Modding Help Is there a way to spawn a text bubble on Player with LUA-magic?

Discussion in 'Starbound Modding' started by Iridescens, Jan 2, 2016.

Tags:
  1. Iridescens

    Iridescens Void-Bound Voyager

    Hi everyone!

    I'm struggling to spawn a player-initiated bubble of text which will show some given parameters. It is all like just typing in chat-window. But conventional NPC's methods don't work:
    Code:
    local playerId = world.playerQuery(mcontroller.position(), 5, {
        boundMode = "Position"
        })
        world.logInfo("P_ID: %s", playerID)
        local someText = world.time()
        playerId.say(someText)
    
    Yields:
    Code:
    Info: P_ID: nil
    Error: Exception while invoking lua function 'activate'. (LuaException) Error code 2, [string "/items/active/unsorted/pigpsgal/pigpsgal.lua"]:15: attempt to call a nil value (field 'say')
    
    Alternatively,
    Code:
    world.logInfo("%s", activeItem.ownerEntityId() )
        local playerId2 = activeItem.ownerEntityId()
        playerId2.say(world.timeOfDay())
    
    Yields:
    Code:
    Info: -65536
    Error: Exception while invoking lua function 'activate'. (LuaException) Error code 2, [string "/items/active/unsorted/pigpsgal/pigpsgal.lua"]:23: attempt to index a number value (local 'playerId2')
    
    And still does nothing.

    What am I missing, or is there no way to invoke it? Btw, LUA is horribly, terrifyingly undocumented.
     
  2. Iridescens

    Iridescens Void-Bound Voyager

    Best Answer
    Ok, gonna answer this myself.

    Here is the code snippet, that will create a text projectile over your character (all thanks should go to "Magicks" on IRC channel ##starbound-modding):

    Code:
    world.spawnProjectile("invisibleprojectile", world.entityPosition(playerId), playerId, {0,0}, true, {damageType = "NoDamage", actionOnReap = { {
                                    action = "particle",
                                    specification = {
                       text =  constructTextLocal(),      -- place your text here, mind the quotes. I did some text construction off-board as you can see.
                        color = {255, 255, 255, 255},  -- white
                                        destructionAction = "fade",
                                        destructionTime =  0.8,               -- time to perform 'destructionAction'
                                        layer = "front",   -- there are 'front', 'middle', 'back' as far as I know
                                        position = {0,4},
                                        size = 0.7,  
                       approach = {0,20},    -- dunno what it is
                       initialVelocity = {-2,5},   -- vec2 type (x,y) describes initial velocity
                       finalVelocity = {3,-10},
                       -- variance = {initialVelocity = {3,10}},  -- 'jitter' of included parameter
                       angularVelocity = 0,                                   
                       flippable = false,
                        timeToLive = 2.5,
                       rotation = 0,
                        type = "text"                 -- our best luck
                                  }
                                } 
                              }
                            }
                           )
    
     
    Spacedino and The | Suit like this.
  3. Errors4l

    Errors4l Spaceman Spiff

    The first playerQuery didn't return any ids (nil).

    The playerQuery (/entityQuery/objectQuery/npcQuery) function only returns a list of entity IDs for entities of the "player" type, not the entity (player) data itself. This is why you're greeted with the error you can't index a number value.
    I'm afraid I can't help you come up with a solution for your problem, but you could log available functions by running this piece of code and checking your log file:
    Code:
    for k,v in pairs(_ENV) do
        if type(v) == "table" then
          for k2,v2 in pairs(v) do
            --if type(v2) == "function" then
              world.logInfo("%s.%s", k, k2) -- (or sb.logInfo)
            --end
          end
        --elseif type(v) == "function" then
        else
          world.logInfo("%s", k) -- (or sb.logInfo)
        end
      end
     
  4. Iridescens

    Iridescens Void-Bound Voyager

    Thank you for the code to list available functions!

    That was a good point, and still now
    Code:
    world.logInfo("P_ID: %s", playerId[1])
    local PID = entityProxy.create(playerId[1])          <--- 19 is here
        PID.say(tostring(world.timeOfDay()))
    
    gives
    Code:
    Info: P_ID: -65536
    Error: Exception while invoking lua function 'activate'. (LuaException) Error code 2, [string "/items/active/unsorted/pigpsgal/pigpsgal.lua"]:19: attempt to index a nil value (global 'entityProxy')
    
    Also the List does not contain 'entity' or 'entityProxy' tables. WTF, How is this posiible?
     
  5. Errors4l

    Errors4l Spaceman Spiff

    You're only logging global tables / functions available to the place you run the script (in this case the active item script).
    How you'd refer to a different entity (by more than the id or name) and call functions for it, I don't know.
     
  6. Iridescens

    Iridescens Void-Bound Voyager

    Best Answer
    Ok, gonna answer this myself.

    Here is the code snippet, that will create a text projectile over your character (all thanks should go to "Magicks" on IRC channel ##starbound-modding):

    Code:
    world.spawnProjectile("invisibleprojectile", world.entityPosition(playerId), playerId, {0,0}, true, {damageType = "NoDamage", actionOnReap = { {
                                    action = "particle",
                                    specification = {
                       text =  constructTextLocal(),      -- place your text here, mind the quotes. I did some text construction off-board as you can see.
                        color = {255, 255, 255, 255},  -- white
                                        destructionAction = "fade",
                                        destructionTime =  0.8,               -- time to perform 'destructionAction'
                                        layer = "front",   -- there are 'front', 'middle', 'back' as far as I know
                                        position = {0,4},
                                        size = 0.7,  
                       approach = {0,20},    -- dunno what it is
                       initialVelocity = {-2,5},   -- vec2 type (x,y) describes initial velocity
                       finalVelocity = {3,-10},
                       -- variance = {initialVelocity = {3,10}},  -- 'jitter' of included parameter
                       angularVelocity = 0,                                   
                       flippable = false,
                        timeToLive = 2.5,
                       rotation = 0,
                        type = "text"                 -- our best luck
                                  }
                                } 
                              }
                            }
                           )
    
     
    Spacedino and The | Suit like this.

Share This Page