License from €75 Log in
DE EN FR ES IT CZ

[LUA][Script] check for item in inventory

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 11 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
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 11 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

  4. · 11 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
  5. · 11 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^^
  6. · 11 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.

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?