Modding Help How to add custom scripts to monsters

Discussion in 'Starbound Modding' started by AlbertoRota, Sep 26, 2016.

  1. AlbertoRota

    AlbertoRota Scruffy Nerf-Herder

    Hello once again.

    Thanks to Healthire, I've finally managed to found the problem, and a kind of solution, you can find the working mod attached to this post.
    Working script:
    Code:
    local preSpamUpdate = update
    function update(dt)
      preSpamUpdate(dt)
      sb.logInfo("I'm a Poptop!")
    end
    
    local preSpamRequire = require
    function require(s)
        if s ~= "/monsters/monster.lua" then  preSpamRequire(s) end
    end
    First part saves the monster "update(dt)" function in the "preSpamUpdate", then overrides the "update(dt)" functions with the new behaviour, for our example, logging "I'm a Poptop!"

    Second part is the critical one, it starts similar to the first, saving "require(s)" function in the "preSpamRequire", then overriding it.
    In the overrided version, we BLOCK the reload of "monster.lua", why? The process is as follows:
    1. "monster.lua", the primary monster script is loaded.
    2. "poptopspam.lua", our script is loaded, it overrides the "update(dt)" function of "monster.lua"
    3. All behaviors are loaded, included their scripts, witch might require again, "monster.lua".
    4. If not blocked, "monster.lua" is loaded AGAIN, overriding the "update(dt)" function of "poptopspam.lua"

    Working patch:
    Code:
    [
      {
        "op" : "add",
        "path" : "/baseParameters/scripts/-",
        "value" : "/scripts/poptopspam.lua"
      }
    ]
    Pretty self explanatory, we just append our script to the "/baseParameters/scripts" array.
     

    Attached Files:

    Last edited: Sep 27, 2016
  2. AlbertoRota

    AlbertoRota Scruffy Nerf-Herder

    Do anyone know how to implement his using a new monster behavior?
    That will improve the solution, since i no longer need to avoid "monster.lua" reload.
     
  3. WyvernWarrior223

    WyvernWarrior223 Big Damn Hero

    Is this how I add monster drops?
     
  4. AlbertoRota

    AlbertoRota Scruffy Nerf-Herder

    No, to edit monster drops, you need to do another entirely different thing, that is out of the scope of this thread.
    Just to point you in the right direction, you can take a look at "Mudercraft" code, witch modifies monster's drops to add "blood" ad a drop.

    This modification is to do things like this:
    The problem now is that the way I've managed to do it seems a bit "dirty", and I want to do it using a new monster behavior instead of a script.
     
    WyvernWarrior223 likes this.
  5. WyvernWarrior223

    WyvernWarrior223 Big Damn Hero

    at thanks I will check it out!
     
    AlbertoRota likes this.

Share This Page