Modding Help Check if you are on your own ship (lua)

Discussion in 'Starbound Modding' started by Darkblader24, Jun 23, 2017.

Tags:
  1. Darkblader24

    Darkblader24 Phantasmal Quasar

    Hey, I want to check in lua if I'm currently on a ship and if it is my own ship. Is that possible and how?
    Thanks!
     
  2. Nexus Of Chaos

    Nexus Of Chaos Parsec Taste Tester

    ik that you can determine what ship you go to with the /warp command using a player's UUID and some other thing. you can have the lua test if the player is on that some other thing then test if the player's UUID matches that linked to the ship. the player's UUID matches their file name, along with their ship's file name
     
  3. bk3k

    bk3k Oxygen Tank

    That's a current thing I'm messing with. Thing is, players are client sided and most everything else is server-sided. So you need the messaging system. No way around it.
     
  4. Darkblader24

    Darkblader24 Phantasmal Quasar

    So how would you test if the player's UUID matches the one of the ship? Can you somehow get this with world.getProperties?

    So even the check if I'm on my own ship is server sided? I don't know anything about the messaging system. Can you show me how to do that?
     
  5. Darkblader24

    Darkblader24 Phantasmal Quasar

    I think I found what I was looking for:
    Code:
    if player.worldId() == player.ownShipWorldId() then
     
  6. bk3k

    bk3k Oxygen Tank

    The only thing being you need access to the player table. If I'm guessing correctly, you need an object (etc) to know this answer and they don't have access to the player table.

    I'm going to use the answer to restrict access to a an interface with a shield generator, spawn point changer, probably gravity changer, and whatever else I think of. Also as part of code that selects the spawned pet based off the ship owner's race(while still respecting mods that alter this behavior). I was wondering if you have similar intentions.

    Anyhow if this is written to a world property somewhere, I don't know what nameSpace it would be stored under. I don't think it is, but rather is think the .shipworld coordinates are stored within the player rather than the world. It makes sense so you know where to warp to, and why you'd need the player table to access the info. Now once I find a match, I will be writing the answers to a world property at a nameSpace I choose for easy retrieval later on.

    I've attempted to just add a function to be called from the player context that is triggered remotely - similar to doorOccupiesSpace() in /objects/wired/doors.lua - to add to world.entityQuery searches. But it always came back empty. I thought about it and eventually realized the world can't do scripted entity calls on the player because of the context difference(server-side, client side). Yes that part still works the same in single player. So maybe I'll save you the frustration of trying this dead end.


    If you knew in advance the UUID of the shipworld's owner, that would be a breeze to compare them to what's in the world. Or find out if a particular entintyId is associated with the UUID you're looking for. But... I don't think that answer will be found by the world table. You're missing a key point of data.

    Well once I have it ironed out (probably not long, but I'm a multitasking ADD coder :p), I can just plain share my code. If you want to get a good handle on using the messaging system to pass information, I suggest looking at how the terraformer UI talks to the terraformer object. Keep in mind the messaging system isn't synchronous - everything doesn't stay on hold while you wait for your answer. You'll probably have to check for it in subsequent cycles. You'll probably see what I mean in the terraformers.

    edit:
    Oh wait, you're wanting this for your portable tech console/teleporter mod. Activeitems have access to the player table, so you already have a sufficient answer for that application.
     
    Last edited: Jun 24, 2017
  7. Darkblader24

    Darkblader24 Phantasmal Quasar

    That is exactly true and it works fine. But thank you for your comprehensive answer! I'm sure it might help someone else who struggles with this problem.
     
  8. TheElderScroller

    TheElderScroller Pangalactic Porcupine

    quests also have access to the player table. This way you can have access to it without needing to hold an item.
    I always have a custom quest running which has alot handlers, including a handler to create a handler.
     
    IHart likes this.

Share This Page