Modding Help Some initial lua hackery

Discussion in 'Starbound Modding' started by matta79, Dec 10, 2013.

  1. mcmurphy

    mcmurphy Master Chief

    Good catch. Can I apply it to myself?

    FYI, the only place I see lightLevel being called is in assets/monsters/sensors.lua
     
  2. mcmurphy

    mcmurphy Master Chief

    lightLevel, windLevel, tempLevel, and breathable all accept a 2d vector as arguments. The following code gives this result:

    local light = world.lightLevel({0,0})
    local wind = world.windLevel({0,0})
    local temp = world.temperature({0,0})
    local breathe = world.breathable({0,0})

    0
    0
    25
    true

    Now I just need to find out how to read your own vector position.
     
  3. matta79

    matta79 Orbital Explorer

    Nice, it is read only?
     
  4. matta79

    matta79 Orbital Explorer

    Also, have a look in assets\npcs\main.lua, line 364:

    playerIds = world.playerQuery(entity.position(), self.noticePlayersRadius, { inSightOf = entity.id() })

    Might be able to grab your playerId this way.
     
  5. mcmurphy

    mcmurphy Master Chief

    I tried

    local position = entity.position()

    but the position constantly changed even as I stood still. But

    local light = world.lightLevel({position[1],position[2]})

    changed the light level as it moved.
     
  6. mcmurphy

    mcmurphy Master Chief

    Success! I think I've found my playerId, and also my position. My code:

    local playerIds = world.playerQuery(entity.position(), 100000)
    pos = world.entityPosition(playerIds[1])
    local light = world.lightLevel({pos[1], pos[2]})
    print(playerIds[1], pos[1], pos[2])
    print("Light = ", light)

    returns:
    -65536, 0, 1255.5
    Light = 0.5 (approx)


    As I move around, x and y change! And as I dig a pit, the light goes down!!!

    Now if I were in a server with multiple people, I couldn't guarantee the person would be me. Single player would be easy though.
     
  7. mcmurphy

    mcmurphy Master Chief

    Also, world.spawnItem("torch", pos) works!

    edit: an unlit torch for picking up, that is.

    edit2: every time a torch spawns, everything around you pauses but you can move freely.
     
    Last edited: Dec 11, 2013
  8. matta79

    matta79 Orbital Explorer

    Hey nice work. I was trying to find a clean way of getting a reference to players but couldn't find anything.
     
  9. mcmurphy

    mcmurphy Master Chief

    Forgot to mention that all you need is this:

    local playerIds = world.playerQuery({0,0}, 100000)

    That'll give you every playerId in the server. Not sure if 100000 is too big (or too small on certain planets), but I set it high just in case.

    My next mission is to find out how to spawn a lit torch attached to the wall. From there, I'm going to make a tech that automatically lights a torch when it's dark.
     
  10. matta79

    matta79 Orbital Explorer

    I don't think we can access spawnItem, it's listed in severedskullz API doc, but he says it's not part of the world object. I wonder if you can make projectiles glow though? You can spawn projectiles. Maybe you can make a projectile with no velocity that emits light. The tech could drop one every few seconds, and the projectile lifespan would be around the same time. If we could access the projectile itself and move it around, you wouldn't need to spawn new ones, but I don't think we can right now.
     
  11. mcmurphy

    mcmurphy Master Chief

    I have though. world.spawnItem("platinumpickaxe", pos) game me about 30 pickaxes before I turned it off.

    Do you know the IRC channel where the devs are? I might politely ask if they know how to activate an item.
     
  12. matta79

    matta79 Orbital Explorer

    How the hell does that work...

    Sorry I don't know the IRC.
     
  13. mcmurphy

    mcmurphy Master Chief

    Try it yourself. Put this code in groundMonster.lua

    local playerIds = world.playerQuery({0,0}, 100000)
    pos = world.entityPosition(playerIds[1])
    local light = world.lightLevel({pos[1], pos[2]})
    print(playerIds[1], pos[1], pos[2])
    print("Light = ", light)
    world.spawnItem("platinumpickaxe", pos)

    I bet spawnItem has a 3rd optional argument, one of them being active!
     
  14. Supergeek

    Supergeek Scruffy Nerf-Herder

    No need to get snarky.

    One, you didn't post the actual code you used. This guy did, so props to him.

    Second, it's easy to miss posts when there are so many new things being discovered all the time.

    We should be respectful of each other and appreciate the effort they put into trying to communicate their findings, otherwise people will just not post to avoid sarcasm just in case their post is slightly redundant.
     
    Kabu and Ebelle like this.
  15. Supergeek

    Supergeek Scruffy Nerf-Herder

    I made a couple small improvements to the basic script. I'm a Lua newbie; hadn't touched it until a couple days ago while making my Chicken Gun.

    Code:
      print("**** DUMPING object TABLE ****");
       a = {}
       count = 1
       for n in pairs(object) do table.insert(a, n) end
       table.sort(a)
       for i,n in ipairs(a) do
         count = count + 1
         print(n)
       end
       print("**** END object TABLE DUMP " .. count .. " ENTRIES ****")
    
    It sorts the table.
    It counts the entries.
    It doesn't print the addresses. I don't know any use for them yet, so for me they are superfluous.

    Counting the entries gives us a quick method for establishing any major changes after a patch.
     
  16. MorpH

    MorpH Subatomic Cosmonaut

    Also, the arguments for spawnItem( name, position, count, level) level is a table, like { level = 1, definition = crappyhammer} dunno what other options there are for 4th arg.

    I'm no expert but wouldn't it be considered an object if it is placed? Idk how spawnItem would be able to do that.



    EDIT: I was able to make it spawn randomly generated guns, spawnItem is fun!

    Code:
    world.spawnItem("generatedgun", object.toAbsolutePosition({ 0.0, 6.0 }), 1, { level = 5} )
    I use it with my edited decoyprincess.
     
    Last edited: Dec 11, 2013
  17. mcmurphy

    mcmurphy Master Chief

    I've been tempted to go into a random server and just dump super powerful stuff on people, then pull out my 100x100 copper pickaxe and destroy the landscape.
     
  18. NerArth

    NerArth Pangalactic Porcupine

    Is this implementable in an object (but with random levels)? Such as the money capsules for example. At the moment I can spawn random gen guns from breakable objects without a script, but they must spawn with a fixed level.
     
  19. Snivy Man

    Snivy Man Void-Bound Voyager

    i need to know what to modify in tech to make me be able to fly, and hover where ever i want
     
  20. You seriously bumped this topic with a completely unrelated question?

    Set the player's position to desired position on each update.
     

Share This Page