Modding Help Getting the price of a container item?

Discussion in 'Starbound Modding' started by builderbrick, Apr 13, 2017.

  1. builderbrick

    builderbrick Void-Bound Voyager

    I am able to get the item from a container slot by using world.containerItemAt(), but for some reason
    everytime I do Item.price, it always returns 1.

    Here's some code:

    local Item = world.containerItemAt(entity.id(),0) --Name and Count
    world.spawnItem("money",Pos,Item.price,Item.parameters)
     
  2. bk3k

    bk3k Oxygen Tank

    Use root.itemConfig to get the full item JSON.
     
    Errors4l likes this.
  3. builderbrick

    builderbrick Void-Bound Voyager

    Thanks dood
     
  4. Errors4l

    Errors4l Spaceman Spiff

    Default* item JSON. The item parameters overwrite the default parameters. If the price parameter is missing on the item (nil or type(param) ~= "number"), you can assume the default price from the itemConfig function.

    I assume the count parameter is nullable and defaults to 1, which if why you're ending up with one pixel.

    PHP:
    local itemPrice 0
    if Item.parameters and type(Item.parameters.price) == "number" then
      itemPrice 
    Item.parameters.price
    else
      
    local itemConfig root.itemConfig(Item.name)
      
    itemPrice itemConfig.config.price or 0
    end

    if itemPrice 0 then
      world
    .spawnItem("money",Pos,itemPrice)
    end
    (Also you probably don't want to spawn money with the parameters of the actual item)
     

Share This Page