[LUA][Script] check for item in inventory

  • #1, by sebastianWednesday, 05. October 2016, 23:09 4 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

    Thread Captain

    2340 Posts


  • #2, by sebastianWednesday, 05. October 2016, 23:38 4 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
    1
    2
    3
    4
    5
    6
    7
    8


    use
    ininv("itemname")
    1
    2

    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

    Thread Captain

    2340 Posts

  • #3, by afrlmeThursday, 06. October 2016, 05:49 4 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

    Imperator

    6862 Posts

  • #4, by sebastianThursday, 06. October 2016, 14:26 4 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^^

    Thread Captain

    2340 Posts

  • #5, by afrlmeThursday, 06. October 2016, 15:14 4 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.

    Imperator

    6862 Posts

Write post