Modding Help What happens when you overwrite a previous lua script?

Discussion in 'Starbound Modding' started by ThornyFlora, Aug 8, 2017.

  1. ThornyFlora

    ThornyFlora Pangalactic Porcupine

    I modified monster.lua so that specific players could apply statuses to monsters based on a percentage. What happens to the original one, and what happens if another mod changes monster.lua?
  2. bk3k

    bk3k Oxygen Tank

    If you add any file in a mod, you will replace that file. The exception is .patch files which patch(instead of replace) any sort of JSON type. You can't make a .patch file for LUA scripts, but there are usually other options. Now if you replaced this file, and other mod also replaced this file, which ever mod loaded last would replace the other so one of the mods will be broken. You can coordinate changes, but... that's not the most viable of solutions given who knows how many mod authors out there.

    The better way in most cases is being more surgical about it. You can hook functions. Functions are a data type, and one nameSpace can be assigned another function. Likewise more than one nameSpace can point to the same function.

    local old_update = update
    update = function(dt)
      --your code here
      --your code here
    The hook will at some point (depending on what you need to do) call the old function. In some cases though, you might replace the old function instead of hooking. Still better than replacing the whole script when you only need to edit one part, and add a few more functions.

    To get another script in there, you can patch the monster entities(or scripted entities). Consider this from
      "baseParameters" : {
        "scripts" : [
    "scripts" is an array, and you just need your own script at the end. Thus this patch.
        "op" : "add",
        "path" : "/baseParameters/scripts/-",
        "value" : "/monsters/ThornyFlora_monsters.lua"
    And when I mean your script, I don't mean the entire vanilla script with some edits, but just the changes you need so to minimize the chance for incompatibility with other mods. Mods often hook the player environment, for example. FU alone has 5 scripts doing this - check the player.config.patch file to see what I mean. Then look at the scripts it references there.
    ThornyFlora and cpeosphoros like this.
  3. ThornyFlora

    ThornyFlora Pangalactic Porcupine

    So would I have to patch every monstertype file in this case?

    Either way, thank you very much!
  4. bk3k

    bk3k Oxygen Tank

    In that case, yes every monster type you want to change. But that's just copying the same patch file and renaming for each one.

    It's easier for npcs because they use a system of prototyping so patching the base type would cover all npcs. Not sure why monsters don't use this too.
    ThornyFlora likes this.
  5. ThornyFlora

    ThornyFlora Pangalactic Porcupine

    We wrote a bash script to do it for us. Thanks a lot for the help! :)

Share This Page