Modding Help Is it possible to determine...

Discussion in 'Starbound Modding' started by LighteyTheDragon, Jan 13, 2018.

  1. LighteyTheDragon

    LighteyTheDragon Big Damn Hero

    Hi, I was wondering if it was actually possible to determine wether or not an NPC, but not a player is using a loungeable object.

    I know that world.loungeableOccupied() can be used to check wether or not the object is being used, but I am trying to make an object act differently when used by a specific race.

    I was also wondering if it is possible to send a .dance animation to an npc if they use an object.
     
  2. bk3k

    bk3k Oxygen Tank

    One thing you might look at different objects that are NPC toys. I haven't really since I've never wanted them to react especially. But that might be useful.

    world.entitySpecies() is useful to find out what race they are. Now here is a little script I made for a toilet so that it could be both lounge-able and have a sound effect after use.

    Code:
    function init()
      storage.id = entity.id()
      storage.autoFlush = false
      storage.cooldown = 0
    end
    
    
    function update(dt)
      local occupied = world.loungeableOccupied(storage.id)
      if storage.autoFlush and occupied then
        --nothing
      elseif occupied then
        storage.autoFlush = true
        storage.cooldown = 1.50
      elseif storage.cooldown > 0 then
        storage.cooldown = storage.cooldown - dt
      elseif storage.autoFlush then
        storage.autoFlush = false
        animator.setAnimationState("toiletState", "flush", false)
        animator.playSound("flush", 1)
      end
    end
    
    It should be simple to use world.npcQuery() to get the NPCs present at the object's position and use world.entitySpecies() to figure out if they're the race you're looking for.
     
    The | Suit likes this.
  3. LighteyTheDragon

    LighteyTheDragon Big Damn Hero

    Hm, thanks for the help already, but it doesn't seem to want to work. The world.npcQuery() seems to get activated no matter if there is one in close proximity like I want to or if the NPC is at the other end of the room.

    On top of that I can't seem to get world.entitySpecies() to work at all.

    Code:
    animState = "blank"
    
    function init()
      object.setInteractive(true)
      storage.id = entity.id()
      storage.position = world.entityPosition(storage.id)
    end
    
    function update(dt)
     
      animState = animator.animationState("baseState")
      local position = entity.position()
     
      if world.npcQuery(position, 1) then
        animator.setAnimationState("baseState", "active")
      else
        animator.setAnimationState("baseState", "idle")
      end
    end
    Here's the current code, in a state in which it at least works at the moment.
     
  4. bk3k

    bk3k Oxygen Tank

    That actually returns a table. The table contains all the entityIds found within the area searched. So you'd iterate the table it returns.
     
  5. LighteyTheDragon

    LighteyTheDragon Big Damn Hero

    Ah, I'll see if I can get it to work when I have the time again and am not working on more important parts of the mod I'm trying to make mostly for fun.

    My current problem is actually my custom ship pet not spawning properly, it just appears for a single frame and disappears again, over and over, like it failed or something. No errors in the log though...
     

Share This Page