Modding Help Any way to make custom monster despawn after a certain amount of time?

Discussion in 'Starbound Modding' started by Axxroytovu, Oct 12, 2016.

  1. Axxroytovu

    Axxroytovu Poptop Tamer

    After searching through the script files, I can't seem to find any way of making monsters have a "timeToLive" parameter like projectiles do. Is there any precedent for that or has someone already done something similar? Thanks!
     
  2. C0bra5

    C0bra5 Oxygen Tank

    you can probably just have a variable in the init of the monster script and have it go up by one every update or just use os.clock() which returns the current time in miliseconds and use some logic to check if the os.clock is bigger than the value recorded in the init + the timeToLive thing and use entity.die() if the check is positive here is some code to help you getting started:
    Code:
    function init()
    
      --you could also use config.getParameter("path"); to get the value directly from your monster config file
      local timeToLive = 60 * 3 * 1000; --3 minutes, 1000ms = 1s * 60 = 1m * 3 = 3minutes
      self.dieAfter = os.clock() + timeToLive;
    
      --Monster init after that
    
    end
    
    function update()
    
      if os.clock() >= self.dieAfter then
        entity.die();
        return;
      end
    
      --Monster update after that
    
    end
    
     

Share This Page