Modding Help [solved] Add Statuseffects to Armor

Discussion in 'Starbound Modding' started by InflamedSebi, Feb 3, 2015.

  1. InflamedSebi

    InflamedSebi Void-Bound Voyager

    I tried to mod armor to add permanent slow energy regeneration like before the update ....
    But i can't get it to work, even the already built in energy regeneration seems not to work ...
    I testet with the glitch crown which has:
    Code:
    { "stat" : "energyRegen", "amount" : 3 }
    but that doenst change anything even at amount 20 ...

    (I m completely new to lua and never build my own effect) any help would be awesome.
    the lua does not need any animation status icons or particles ... just stupid easy energy regen.

    any ideas?
     
  2. AstralGhost

    AstralGhost Pangalactic Porcupine

    Best Answer
    Mostly just finding examples. This is the easiest way.

    You can also use the Starbound docs as a reference, but that only works some of the time unless you look deeper.
    http://doc.playstarbound.com/namespaceStar_1_1LuaBindings.html
    This is the Lua Bindings documentation. You can go to things like EntityCallbacks and WorldCallbacks and obviously those functions are for entity and world, respectively. It's not always straight-forward but it can help out if you don't have an example.

    Some things like WorldEntityCallbacks are a bit more confusing. So for the ones you aren't sure about you have to do a search of the function.
    For example, if you search "entityQuery", click the function to select it, and the first on the list is World::entityQuery(). So you know that world.entityQuery works. You'll also see other classes in there that Lua doesn't have access to, like 'SpawnerWorld', so you can just ignore those. For some functions it could be called on more than one type of object. So you might find something like entity::exampleFunction() and World::exampleFunction() and know it works for both world and entity.

    This is what I mean by 'look deeper'.


    1. I'm not sure. You mean do what you're already doing but without the armor and/or status effect? In which case the player's script file may work? I don't know for sure, sorry. I don't even remember what the name of that script is. player_primary.lua or something like that, I think.
    If you found a direct script with access to players' resources you'd just need to place your own check into the code so that every update if energy == 0 then do whatever.
    Or, a little more indirectly, afflict a permanent status-effect on the player which does this since status-effects have access to the players' energy resource.

    I'm just speculating, though. I don't really remember and can't check anything at the moment.

    2. Last time I checked you can't access a player's inventory at all.
    3. Same as above.
     
    InflamedSebi likes this.
  3. The | Suit

    The | Suit Agent S. Forum Moderator

    energyRegen is no longer a stat.
    You can find all stats in player.config file.

    you would need to do something like create a status effect with lua code such as status.modifyResource("energy", calculation) and put it in a timed loop.
    You can look at foodhealth status effect for an example and do the necessary.
     
  4. kokobo88

    kokobo88 Scruffy Nerf-Herder

    check out some food or potions that grant energy regen. enegry regen is now an effect.
     
  5. InflamedSebi

    InflamedSebi Void-Bound Voyager

    well lua is hard ...
    Code:
    function init()
      animator.setParticleEmitterOffsetRegion("healing", mcontroller.boundBox())
      animator.setParticleEmitterActive("healing", true)
    
      script.setUpdateDelta(5)
    
      self.healingRate = 1.0 / effect.configParameter("regenerationTime", 60)
    end
    
    function update(dt)
      status.modifyResourcePercentage("energy", self.healingRate * dt)
    end
    
    function uninit()
    end
    1. i can't find any reference what self.healingRate is ... nothing in player.config
    2. Do u know what "dt" at the update function is?
    3. if you add the effect you can specify an "amount". Where does this come into play?

    Code:
    {
      "name" : "energyregenerationboost",
      "effectConfig" : {
      "regenerationTime" : 10
      },
      "defaultDuration" : 5,
    
      "scripts" : [
      "energyregenerationboost.lua"
      ],
    
      "animationConfig" : "energyregenerationboost.animation",
    
      "label" : "Energy Regeneration",
      "icon" : "/interface/statuses/energyregen.png"
    }
    4. defaultDuration is never used in the script ... is that normal?
     
  6. The | Suit

    The | Suit Agent S. Forum Moderator

    Go to modding guides and start with my 2 lua tutorials.
    Use the interpreter along with the tutorials ( in guide ) to practice as you go.

    By the time you finish the 2 tutorials you should be able to tackle it.

    DT = delta time. Or the difference in time when the entity is callled.
    defaultDuration goes directly into the function
    self.healingRate is just a variable
     
  7. AstralGhost

    AstralGhost Pangalactic Porcupine

    1. HealingRate is the.... Well, umm, healing rate. It is self-explanatory, don't you think? It is being used in the update function to determine the rate at which energy should be healed.
    2. dt is "delta time". It is basically the amount of processing time between updates. Meaning the slower your game is running the higher it will be and vice versa.
    3. *shrug*
    4. As swat stated, it is directly being used by the game. It is how long the effect will last.

    Edit:
    This is a rather simple script so I'll just go ahead and explain it.
    Code:
    function init()
      -- animate particles (removed)
    
      script.setUpdateDelta(5)
    -- Do update every 5 game-ticks.
    
      self.healingRate = 1.0 / effect.configParameter("regenerationTime", 60)
    -- set healing rate equal to 1 divided by the JSON regeneration time, default to 60 if not in file.
    end
    
    function update(dt)
      status.modifyResourcePercentage("energy", self.healingRate * dt)
    -- add "healingrate" multiplied by processing-time to 'energy' resource.
    end
     
    Last edited: Feb 3, 2015
    The | Suit likes this.
  8. InflamedSebi

    InflamedSebi Void-Bound Voyager

    hmm something is inconsistend

    bandages use
    script.setUpdateDelta(5)
    and they update more than once every second
    so maybe this are ticks?

    but the duration in the JSON is seconds ...

    effect.duration()
    probably give the duration in ticks

    and dt is also in ticks ...

    so how many ticks are 1 second?

    and if i am right:
    self.whatever -- defines a global variable for this script
    effect.configParameter("whatever", 60) -- gets some information from JSON with default value
    status.modifyResourcePercentage("what", amount) -- well updates players stats
     
  9. The | Suit

    The | Suit Agent S. Forum Moderator

    The higher the delta the slower the script
    We usually keep all entities on 5.
    Each delta tick is around 0.083 or 0.0083 you can just use world.logInfo to find out the right number.

    Duration is in seconds

    Generally uses
    variable = variable - dt
    variable <= 0 to set it up.

    There are no global variables. Self just stores the variable on the object
    yes it takes the information from the json SE file
    It modifies the resource defined in player.config
     
    InflamedSebi likes this.
  10. InflamedSebi

    InflamedSebi Void-Bound Voyager

    Well thats awesome :)will try to make it work
    ty for your hlp ^^
    now i try to head for this post: Energy for Ranged Weapons

    Can anyone tell me if it is possible to do this:
    1. hook into an event to call a script as soon as energy is depleted
    2. script should check if play has a certain item in inventory
    3. automatically consume that item like the player did that.

    are all thos steps possible?
     
    Last edited: Feb 3, 2015
  11. AstralGhost

    AstralGhost Pangalactic Porcupine

    Sorry about that, it is in ticks, not seconds. For some reason I thought that piece of script used 'seconds' instead of ticks.
    I will update the explanation.

    As well: deltatime should also vary depending on how fast the game is running on your PC. A slower game means higher DT because more time will lapse between frames. A faster game will have a lower dt.

    For a basic explanation, dt is the way games handle "lag" and other slowdowns and keep the game consistent between different types of computers.
     
    The | Suit likes this.
  12. InflamedSebi

    InflamedSebi Void-Bound Voyager

    still not working :/ this is what i got:

    .patch for the armorpiece
    Code:
     { "op" : "add", "path" : "/statusEffects/-", "value" : "energyregenerationboost" }
    .statuseffect itself
    Code:
    {
      "name" : "energyregenerationboost",
      "effectConfig" : {
      "regenPerc" : 100
      },
      "defaultDuration" : 60,
    
      "scripts" : [
      "energyregenerationboost.lua"
      ],
    
      "label" : "Energy Regeneration",
      "icon" : "/interface/statuses/energyregen.png"
    }
    
    
    .lua for the effect
    Code:
    function init()
      -- add particles here
    
      script.setUpdateDelta(5)
      self.regenRate = effect.configParameter("regenPerc", 20) / effect.duration()
    end
    
    function update(dt)
      status.modifyResourcePercentage("energy", self.regenRate * dt)
    end
    
    function uninit()
    end
    
    it is loading just fine, also the icon of the effect is showing while wearing the armor but it will not change any energy ...

    help? xD
     
    Last edited: Feb 3, 2015
  13. InflamedSebi

    InflamedSebi Void-Bound Voyager

    *push* ... No talented modder who can help me here?

    tried:

    Code:
    status.modifyResourcePercentage("energy", self.regenRate * dt * 6)
    status.modifyResource("energy", 1)
    status.modifyResource("energy", 10)
    status.modifyResource("health", 10)
    status.setResource("blockEnergywhatever", 0.0) -- that one that tracks the recharge delay
    
    none of them seems to take any effect ... but i can see the icon of the effect appearing on the effect bar while wearing that modified florantier9.head ... :/
     
  14. AstralGhost

    AstralGhost Pangalactic Porcupine

    Check your error log. Maybe it states the problem there.
    Lua files can have broken code that just makes the script stop running but doesn't crash the game. An error will always get posted in the error log, though.
    You can also try out some of the new debugging features and test some of the values to make sure that you're getting something in there.
    I'm not sure why something like modifying energy by 10 wouldn't work other than that your first line causes the script to crash.
     
    InflamedSebi likes this.
  15. InflamedSebi

    InflamedSebi Void-Bound Voyager

    stupid me ... ur right :)

    Error: Exception while invoking lua function 'init'. (LuaException) Error code 2, [string "/stats/effects/energyregenerationboost/energy..."]:5: attempt to perform arithmetic on a nil value

    if i get this right, the error is in line 5 ...
    self.regenRate = effect.configParameter("regenPerc", 20) / effect.duration()

    well ... testing said effect.duration() is nil ...
    but bandages also use effect.duration()

    ... strange ... ?
     
  16. AstralGhost

    AstralGhost Pangalactic Porcupine

    I don't have the code with me right now to look at what the bandages are doing, but I'd just use the code you posted earlier from the other energy-regeneration effect. The one that uses configParamaters. At least then you know exactly where it is getting the value from, and you can also default it to another value in case one isn't found in the JSON file.
     
  17. InflamedSebi

    InflamedSebi Void-Bound Voyager

    well ya changed it :)
    and it's working like charm :)

    maybe u can help me on my next step :p
    how do u know the names of variables to call functions on?
    like it is "world.LogInfo()" and not "game.LogInfo()", "client.", "planet." or something else

    and maybe u know if it is possible to do this:
    1. hook into an event to call a script as soon as energy is depleted
    2. script should check if play has a certain item in inventory
    3. automatically consume that item like the player did that.

    and how ...
     
  18. AstralGhost

    AstralGhost Pangalactic Porcupine

    Best Answer
    Mostly just finding examples. This is the easiest way.

    You can also use the Starbound docs as a reference, but that only works some of the time unless you look deeper.
    http://doc.playstarbound.com/namespaceStar_1_1LuaBindings.html
    This is the Lua Bindings documentation. You can go to things like EntityCallbacks and WorldCallbacks and obviously those functions are for entity and world, respectively. It's not always straight-forward but it can help out if you don't have an example.

    Some things like WorldEntityCallbacks are a bit more confusing. So for the ones you aren't sure about you have to do a search of the function.
    For example, if you search "entityQuery", click the function to select it, and the first on the list is World::entityQuery(). So you know that world.entityQuery works. You'll also see other classes in there that Lua doesn't have access to, like 'SpawnerWorld', so you can just ignore those. For some functions it could be called on more than one type of object. So you might find something like entity::exampleFunction() and World::exampleFunction() and know it works for both world and entity.

    This is what I mean by 'look deeper'.


    1. I'm not sure. You mean do what you're already doing but without the armor and/or status effect? In which case the player's script file may work? I don't know for sure, sorry. I don't even remember what the name of that script is. player_primary.lua or something like that, I think.
    If you found a direct script with access to players' resources you'd just need to place your own check into the code so that every update if energy == 0 then do whatever.
    Or, a little more indirectly, afflict a permanent status-effect on the player which does this since status-effects have access to the players' energy resource.

    I'm just speculating, though. I don't really remember and can't check anything at the moment.

    2. Last time I checked you can't access a player's inventory at all.
    3. Same as above.
     
    InflamedSebi likes this.
  19. InflamedSebi

    InflamedSebi Void-Bound Voyager

    awesome :) TYVM .

    //solved
     

Share This Page