Modding Help An item which kills all currently-out captive monsters, making them drop their filled pod/teleports

Discussion in 'Starbound Modding' started by wolfboyft, May 19, 2015.

  1. Kayuko

    Kayuko Oxygen Tank

    I'm really no SB-Lua pro but I don't think that'll work... x:
    Might want to consider someone who actually worked in lua before, maybe. So I'll draw-back from this thread for now. xD
     
  2. wolfboyft

    wolfboyft Pangalactic Porcupine

    Ok...
     
  3. wolfboyft

    wolfboyft Pangalactic Porcupine

    Hm. Anyone who does know lua scripting...

    Got any ideas about callscriptedentity?

    Could I use captivestate.lua to have a thing in it that uses ownerEntityId as the entity ID in a callScriptedEntity function-call, and... then the function would be to check for any status effects on the player? A custom one, designed to do nothing.
     
  4. Peelz

    Peelz Giant Laser Beams

    I'm fairly certain there's a function that you can use to have a Lua script check what the player is holding in their hand. So basically what you might be able to do is, in the captivestate.lua :

    if( entityHandItem(ownerID, 'monsterWhistle');
    {monster.die()}

    or something like that. This is not working code. This idea would make the captured monster return to its pod as soon as you take out the whistle.
     
  5. wolfboyft

    wolfboyft Pangalactic Porcupine

    So there's really nothing to check if the player has used it? Okay.[DOUBLEPOST=1432103665][/DOUBLEPOST]Hi. I tried this...

    Code:
    ... if distance > captiveState.teleportDistance then
        movement = 0
        if world.entityHandItem(self.entityOwnerId, "primary") == "monsterWhistle" then
        mcontroller.setPosition(ownerPosition)
        end
      elseif ...
    But it didn't work. The captive entities just stay there. Nothing. I assume this is to do with the captivestate.lua thing being errored, so...

    no chance of the teleport working then.

    There's the full code.
    Code:
    captiveState = {
      closeDistance = 4,
      runDistance = 12,
      teleportDistance = 36,
    }
    
    function captiveState.enter()
      if not isCaptive() or hasTarget() then return nil end
    
      return { running = false }
    end
    
    function captiveState.enterWith(params)
      if not isCaptive() then return nil end
    
      -- We're masquerading as wander for captive monsters
      if params.wander then
        return { running = false }
      end
    
      return nil
    end
    
    function captiveState.update(dt, stateData)
      if hasTarget() then return true end
    
      -- Translate owner uuid to entity id
      capturepod.updateOwnerEntityId()
    
      -- Owner is nowhere around
      if self.ownerEntityId == nil then
        return false
      end
    
      local ownerPosition = world.entityPosition(self.ownerEntityId)
      local toOwner = world.distance(ownerPosition, self.position)
      local distance = math.abs(toOwner[1])
    
      local movement
      if distance > captiveState.teleportDistance then
        movement = 0
        if world.entityHandItem(self.entityOwnerId, "primary") == "monsterWhistle" then
        mcontroller.setPosition(ownerPosition)
        end
      elseif distance < captiveState.closeDistance then
        stateData.running = false
        movement = 0
      elseif toOwner[1] < 0 then
        movement = -1
      elseif toOwner[1] > 0 then
        movement = 1
      end
    
      if distance > captiveState.runDistance then
        stateData.running = true
      end
    
      entity.setAnimationState("attack", "idle")
      move({ movement, toOwner[2] }, stateData.running, captiveState.closeDistance)
    
      return false
    end
    
     
    Last edited: May 20, 2015
  6. wolfboyft

    wolfboyft Pangalactic Porcupine

    Forgot to say that I turned it into the teleporter idea instead :D
     
  7. Kayuko

    Kayuko Oxygen Tank

    Best Answer
    ... if distance > captiveState.teleportDistance then
    movement = 0
    if world.entityHandItem(self.entityOwnerId, "primary") == "monsterWhistle" then
    mcontroller.setPosition(ownerPosition)
    end
    elseif ...

    if( entityHandItem(ownerID, 'monsterWhistle');
    {monster.die()}

    If anything:

    if distance > captiveState.teleportDistance and world.entityHandItem(self.ownerEntityId, 'monsterWhistle') then
    movement = 0
    mcontroller.setPosition(ownerPosition)
    elseif distance < captiveState.closeDistance then
    stateData.running = false
    movement = 0

    *inserts usual I think quote*

    One does not simply call two ifs in that manner, I shall add.
     
    The | Suit likes this.
  8. wolfboyft

    wolfboyft Pangalactic Porcupine

    *Uses blabbering emote*

    IT...

    WORKS...?

    AFTER SOME MODIFICATION...

    if world.entityHandItem(self.ownerEntityId, "primary") == "monsterWhistle" then
    movement = 0
    mcontroller.setPosition(ownerPosition)

    WORKS! But... ah, who cares. It works. :D

    [​IMG]
     
    Kayuko likes this.
  9. Kayuko

    Kayuko Oxygen Tank

    Well... congratz then.X3
     
    wolfboyft likes this.
  10. Peelz

    Peelz Giant Laser Beams

    Congrats on the mod release! I'm gonna have to try it out soon!
     
    wolfboyft likes this.

Share This Page