Modding Help ActiveItem spawning a weapon

Discussion in 'Starbound Modding' started by dimitrius231, Jan 20, 2017.

Tags:
  1. dimitrius231

    dimitrius231 Void-Bound Voyager

    Hello there!
    I'm trying to make a mod that resembles Megaman in a couple of ways and one of them is that I want to make a ActiveItem that spawns a weapon. Now the problem here is, I don't know if there is a way to directly spawn an item from the LUA script itself without having to access the .activeitem file for an itemName parameter.

    In short- my question is:
    is there a way to do something like

    function init()
    if fireMode == "primary" then
    world.spawnItem("NAME OF SPECIFIC ITEM HERE")
    end


    If there is, I'd gladly appreciate the info.
     
  2. lazarus78

    lazarus78 The Waste of Time

    It is possible. I don't know exactly how off hand, but I know it is possible.
     
  3. Errors4l

    Errors4l Spaceman Spiff

    I'm not sure I entirely understand what you're asking for... if it's as simple as the below code I don't get how you could't find this.
    world.spawnItem("someSpecificItemName", mcontroller.position())

    Edit:
    Code:
    function activate(fireMode, shiftHeld)
      world.spawnItem("someSpecificItemName", mcontroller.position())
    end
     
    Last edited: Jan 21, 2017
  4. dimitrius231

    dimitrius231 Void-Bound Voyager

    @Errors4l , You're saying I forgot the position controller? Is it necessary for what I'm trying to do?

    @lazarus78 , Right? There should be some form of inter-luascript relationship, not only an outside file relationship.

    @Errors4l I managed to pull it, thank you very much.
     
    Last edited: Jan 21, 2017
    Errors4l likes this.
  5. Errors4l

    Errors4l Spaceman Spiff

    The world.spawnItem function has to know where to spawn it, since it spawns it "somewhere in the world" and doesn't "give it to the player". The mcontroller.position() function returns the position of the player, which means they'll automatically pick it up (granted they have enough inventory space).
     
    dimitrius231 likes this.
  6. dimitrius231

    dimitrius231 Void-Bound Voyager

    I see. However, the thing that followed after that was the fact that, Even if I did use the "specificItemNameHere" parameter, It still didn't work, until I actually did something rather redundant:

    Code:
    Code:
    function activate(fireMode, shiftHeld)
       local objectName == "specificItemName",
        world.spawnItem(objectName, mcontroller.position())
    I'm sure I'm doing something wrong again if that had to be defined in such a way, but I digress. I appreciate the help, I hope we can work on problems in the future. :)
     
  7. Errors4l

    Errors4l Spaceman Spiff

    That code doesn't seem valid. I assume you're using one equals instead of two (= is used to set a value, == is used to check equality). The comma also doesn't belong there.

    You have to replace "specificItemNameHere" with the specific item name for the item you wish to spawn. What are you trying to spawn?
     
  8. dimitrius231

    dimitrius231 Void-Bound Voyager

    Code:
    function activate(fireMode, shiftHeld)
    
        if fireMode == "primary" then
              
            local objectName = "sagcrossbow"
            world.spawnItem(objectName, mcontroller.position(), 1)
        
        end
    end
    Yes, you're right about the two equals signs, I made a mistake here. Otherwise it worked, I'm trying to spawn a custom item I made, nothing too fancy.
     
  9. Errors4l

    Errors4l Spaceman Spiff

    I don't see any reason the below doesn't work, but I guess if it works for you now that's all that matters.

    world.spawnItem("sagcrossbow", mcontroller.position(), 1)
     

Share This Page