Modding Help Interactive object with specific item

Discussion in 'Starbound Modding' started by swefpifh, May 23, 2020.

  1. swefpifh

    swefpifh Void-Bound Voyager

    Hi,
    excuse me for disturb the community for that. My coding skill are very basic and i've been stuck on a problem for several days.

    I want create an interactive object (console, teleporter, crafting station, etc) who can activated only if i have a specific item in my inventory.

    For exemple, for activate the teleport window for choose a location linked to the "GateObject", i must have "ThisItem" in my inventory. If i haven't it, i have a popup message notify me to i haven't this specific item.

    I have tested many things, i have checked many vanilla files and nothing. If a good soul can be help me, i'll very gratefull.


    Code:
    {
      "objectName" : "gateTest",
      "rarity" : "Common",
      "description" : "...",
      "shortdescription" : "^orange;Gate Test",
      "race" : "generic",
      "category" : "decorative",
      "price" : 0,
      "printable" : false,
    
      "inventoryIcon" : "icon.png",
      "orientations" : [
        {
          "imageLayers" : [ { "image" : "gateTest.png:<color>" } ],
          "flipImages" : true,
          "direction" : "left",
          "lightPosition" : [0, 1],
    
          "imagePosition" : [-20, 0],
          "frames" : 1,
          "animationCycle" : 1.0,
    
          "spaceScan" : 0.1,
          "anchors" : [ "bottom" ],
          "detectArea" : [ [-3, 0], [3, 5] ]
        }
      ],
      "scripts" : [ "/objects/gateTest/gateTest.lua" ],
      "scriptDelta" : 30,
      "hasObjectItem" : true,
      "unbreakable" : false,
      "health" : 10,
      "consumeOnPickup" : false,
    
      "itemNeededToAccess" : "secretnote", //vanilla item for testing script
      "itemNeededToAccessCount" : 1,
    
      "anInteractAction" : "OpenTeleportDialog",
      "anInteractData" : "/interface/warping/remoteteleporter.config",
    
      "noInteractAction" : "ShowPopup",
      "noInteractTitle" : "^orange;Restricted Permissions !",
      "noInteractData" : "Without a ^orange;Police Badge^reset; you cannot access to this object."
    }


    Code:
    require "/scripts/util.lua"
    require "/scripts/messageutil.lua"
    
    function init()
        itemNeededInventoryVar = config.getParameter("itemNeededToAccess")
        itemNeededInventoryCountVar = config.getParameter("itemNeededToAccessCount")
    
        anInteractActionVar = config.getParameter("anInteractAction")
        anInteractDataVar = config.getParameter("anInteractData")
    
        noInteractActionVar = config.getParameter("noInteractAction")
        noInteractTitleVar = config.getParameter("noInteractTitle")
        noInteractDataVar = config.getParameter("noInteractData")
    
        object.setInteractive(true)
    end
    
    function update(dt)
        if player.hasItem({name = itemNeededInventoryVar, count = itemNeededInventoryCountVar})
            then
                mission1TP()
         
            else
                noItemChecked()
        end
    end
    
    function mission1TP()
        return { anInteractActionVar, anInteractDataVar }
    
        --return { "OpenTeleportDialog",
        --            {
        --            canBookmark = false,
        --            includePlayerBookmarks = false,
        --            destinations = { { name = "POUET", planetName = "Gate Test", warpAction = "InstanceWorld:gateTest",    icon = "default" } }
        --            }
        --        }
    end
    
    function noItemChecked()
        return { noInteractActionVar, { title = string.format(noInteractTitleVar), message = string.format(noInteractDataVar) } }
    end

    I share you a Zipped files with contents too. Thx you for your help. ^^
     

    Attached Files:

    Last edited: May 24, 2020
  2. projectmayhem

    projectmayhem Ketchup Robot

    Maybe take a look at the gateway from the story line where you need the 10 shards to activate and travel to the outpost. You should be able to use some of that code
     

Share This Page