excon Posted September 9, 2023 Share Posted September 9, 2023 (edited) player:getInventory if Base.BeerBottle == true do player:getInventory():AddItem("Base.BeerBottleEmpty") basically i need to check what item the player has in the inventory or uses to start a recipe and then add the empty version of those items back into his inventory what syntax is the txt files in is that also lua ? TY ! Edited September 9, 2023 by excon Link to comment Share on other sites More sharing options...
Hugo Qwerty Posted September 9, 2023 Share Posted September 9, 2023 You can loop through the items within the OnCreate function. Something like: function MakeTheThing(items, result, player) for i=0, items:getSize()-1, do local item = items:get(i) --do something with item end end item:getReplaceOnUse() will give you the "BeerEmpty" for BeerBottle items (I assume, not tested it). Link to comment Share on other sites More sharing options...
excon Posted September 10, 2023 Author Share Posted September 10, 2023 (edited) for i=0, items:size()-1 do local item = items:get(i) local itemDisplayName = item:getDisplayName() local itemName = item:getName() -- Is "IGUI_WorkItem1" the "itemDisplayName" for the "item" at items:get(i)? if itemDisplayName == getText("IGUI_WorkItem1") then WorkItemName = itemDisplayName -- Store item display name into WorkItemName end -- Is "IGUI_WorkItem1" the "itemName" for the "item" at items:get(i)? if itemName == getText("IGUI_WorkItem1") then WorkItemName = itemName -- Store item name into WorkItemName end end this allows for two ways to loop through the items used to trigger with your example i was able to search better Edited September 10, 2023 by excon Link to comment Share on other sites More sharing options...
excon Posted September 10, 2023 Author Share Posted September 10, 2023 function Recipe.OnCreate.DoubbleFilledReturn(items, result, player) bottleReturn = ZombRand(1,4); for i=0, items:size()-1 do local item = items:get(i) local itemDisplayName = item:getDisplayName() local itemName = item:getName() --get Display name and return bottle if itemDisplayName == getText("WhiskeyBottle filled with Spirit") then WorkItemName = itemDisplayName returnMe = Base.WhiskeyEmpty takeMe = WhiskeyRefill --player:getInventory():AddItem("Base.WhiskeyEmpty") --player:getInventory():Remove("WhiskeyRefill") end if bottleReturn==1 then player:getInventory():AddItem("returnMe") player:getInventory():AddItem("returnMe") player:getInventory():AddItem("returnMe") player:getInventory():Remove("takeMe") player:getInventory():Remove("takeMe") player:getInventory():Remove("takeMe") elseif bottleReturn==2 then player:getInventory():AddItem("returnMe") player:getInventory():AddItem("returnMe") player:getInventory():AddItem("returnMe") player:getInventory():Remove("takeMe") player:getInventory():Remove("takeMe") player:getInventory():Remove("takeMe") elseif bottleReturn==3 then player:getInventory():AddItem("returnMe") player:getInventory():AddItem("returnMe") --player:getInventory():AddItem("returnMe") player:getInventory():AddItem("Base.brokenglass_1_0") player:getInventory():Remove("takeMe") player:getInventory():Remove("takeMe") player:getInventory():Remove("takeMe") end end end so i have it that far 3 bottles or refill go in if refill is whiskey remove refill full add refill emtpy but the bottom part is my issue where i basically add a randomization and chance to receive a broken glass instead of the item im sure its some dumb sytanx error Link to comment Share on other sites More sharing options...
excon Posted September 10, 2023 Author Share Posted September 10, 2023 (edited) biggest issue is how do i set the var takeMe or returnMe so i can point to the item as variable in here player:getInventory():AddItem("returnMe") they are global so i do not get why they do not get fetched Edited September 10, 2023 by excon Link to comment Share on other sites More sharing options...
excon Posted September 10, 2023 Author Share Posted September 10, 2023 (edited) function Recipe.OnCreate.DoubbleFilledReturn(items, result, player) bottleChance = ZombRand(1,4) -- for every item that activates via the recipe the loop goes for i=0, items:size()-1 do local item = items:get(i) local itemDisplayName = item:getDisplayName() local itemName = item:getName() -- whiskey if itemDisplayName == getText("Whiskey Bottle filled with Spirit") then --WorkItemName = itemDisplayName player:getInventory():Remove("WhiskeyRefill") if bottleChance== 1 then player:getInventory():AddItem("Base.brokenglass_1_0") bottleChance = 2 elseif bottleChance == 2 then player:getInventory():AddItem("Base.WhiskeyEmpty") elseif bottleChance == 3 then player:getInventory():AddItem("Base.WhiskeyEmpty") end end --same pattern for all other drinks below end this is how i solved it - not pretty cause i need the same block for all drink/refills and id rather just fork out the variable and use the creator as prototype. I also have the issue that i cannot get elseif bottleChance > 1 then to work any help is apprciated on this and the get item via variable name issue, TY! ps local itemName = item:getName() did nothing for me ? Edited September 10, 2023 by excon Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now