[LUA][Script] check for item in inventory

  • #1, z sebastianWednesday, 05. October 2016, 23:09 hodinky 8 years ago
    Hey there again,

    short question: I'd like to check if i have a specific item in the inventory and don't wan't to waste a condition for this. It should be checkable in lua so i need some kind of function which checks the inventory table(?) of the current character and returns true if the item name (internal name) exists there, else return false.

    Any ideas how to achieve this?
    EDIT: done. Check out the solution below

    Kapitán

    2346 Posts


  • #2, z sebastianWednesday, 05. October 2016, 23:38 hodinky 8 years ago
    Oh, got it myself working now. If you guys need it anyway -here is the code:
    function ininv(item)
    	local charitems  = game:getLink(VGameCurrentCharacter):getLinks(VCharacterItems)
    	for k,v in pairs(charitems) do 
    		if v:getName() == item then print("TRUE"); return true end
    	end
    	print("FALSE"); return false
    end
    


    use
    ininv("itemname")
    

    to check if item exists in current characters inventory. The itemname is the internal name in VS, not the localized Itemname which gets displayed in the actiontext.


    Greetings
    Sebastian

    Kapitán

    2346 Posts

  • #3, z afrlmeThursday, 06. October 2016, 05:49 hodinky 8 years ago
    I thought I shared something like this before on the wiki? Well there was some inventory related stuff, but anyway... seems you've sorted it out yourself again. smile

    Imperátor

    7285 Posts

  • #4, z sebastianThursday, 06. October 2016, 14:26 hodinky 8 years ago
    nope, sadly found only replace/insert item in inventory. But i rook the "get inventory items and put into table" lines from that because i needed them anyway^^

    Kapitán

    2346 Posts

  • #5, z afrlmeThursday, 06. October 2016, 15:14 hodinky 8 years ago
    Ah I remember now, I wrote one for checking the listed actions for scene objects & characters to determine which commands should be available on a ring / coin interface system. Not sure if I shared that though. I wrote it for Thomas for Zak 2 Directors Cut - I think.

    Imperátor

    7285 Posts