endrjuww Posted January 7 Posted January 7 Hello, Please don't kill me if this has been maybe asnwered somewhere - I die just about often enough in PZ anyways So I've just recently started to try making my first mod. I just did some changes to a mod that I wanted to import properly to B42. I succesfully replaced some old references with new ones (like Base.CigaretteSingle instead of Base.Cigarettes), in this dictionary: EHK = EHK or {} EHK.fireSources = { [1] = "Base.Lighter", [2] = "Base.LighterDisposable", [3] = "Base.Matches", [4] = "Base.Matchbox", [5] = "Base.CandleLit", [6] = "Base.Lantern_HurricaneLit", } EHK.smokerIsPresent = false EHK.cigarettes = { [1] = "Base.CigaretteSingle", -- pojedynczy papieros [2] = "Base.CigaretteRolled", -- skręcony papieros [3] = "Base.Cigar", -- cygaro [4] = "Base.Cigarillo", -- cheroot [5] = "Base.CigaretteSingle_Clove", -- Fiołkowa [6] = "Base.TobaccoChewing", -- Tytoń do żucia [7] = "Base.TobaccoLoose", -- Tytoń luźny [8] = "Base.SmokingPipe_Tobacco", -- Fifka z tytoniem [9] = "CVCrackCigs.CrackCigSingle", -- Papieros crackowy } EHK.cigarettesPacks = { [1] = "Base.CigarettePack", [2] = "Base.CigarettePack_Clove", [3] = "CVCrackCigs.CrackCigPack", } EHK.validRecipes = { ["Take Cigarette from Pack"] = true, -- ["Unpack Cigarettes"] = true, -- ["UnpackCigarettes"] = true } (the last two commented lines is my attempt to do the thing I'm asking below, did not help) The problem rised when I wanted to challenge myself by fixing the problem where the character wouldn't take out a cigarette out of cigarette pack when he had it. There are recipes for that -"Base.TakeACigarette" and "Base.UnpackCigarettes", but oh my... I spent three days and I used: - this documentation (RecipeManager) - chatGPT - google - all of my patience and countless tries always end up with error, usually it's pointing to one of the first lines in Vanilla, and I've already figured it happens when an "object tries to call nil". What I did find though, is that there's apparently no recipes tied to the Base.CigarettePack, and I have a big question to y'all... HOW is there no recipes when you literally do take a cigarette, and do unpack the pack. How can I do it from the code? Because I'd like to assign a hotkey for unpacking cigs aswell. here's original code that worked in B41 - the character ends up saying "Must unpack cigarettes first", and I wanted him to actually do RecipeManager.PerformMakeItem(...) but end up with the same "object tried to call nil" error. local cigarettesDialogues = { [1] = "I'd like to smoke so badly! If only I had some cigs...!", [2] = "I lost my fags again?! Goddamn it!", [3] = "A fag! A fag! My kingdom for a fag!" } local lightDialogues = { [1] = "Anybody got light?", [2] = "Where are my matches?", [3] = "Gotta search some corpses for a lighter..." } function getFirstItem(dictionary, inv, smokingItemType) local output for i, fullType in pairs(dictionary) do local identifier if useKey then identifier = i else identifier = fullType end output = inv:getFirstTypeRecurse(identifier) if output and (smokingItemType ~= "cigarettes" or output.getBaseHunger) then break else output = nil end end return output end EHK.smoke = function() local player = getPlayer() local inv = player:getInventory() local dialogueNo, fireSourceContainer local cigarettes = getFirstItem(EHK.cigarettes, inv, "cigarettes") if not cigarettes then local cigarettesPack = getFirstItem(EHK.cigarettesPacks, inv) if not cigarettesPack then dialogueNo = ZombRand(3) + 1 player:Say(cigarettesDialogues[dialogueNo]) return else -- print("pack found ", cigarettesPack) local itemRecipes = RecipeManager.getUniqueRecipeItems( cigarettesPack, player, ISInventoryPaneContextMenu.getContainers(player) ) local recipe if itemRecipes:size() > 0 then for i = 0, itemRecipes:size() - 1 do recipe = itemRecipes:get(i) if EHK.validRecipes[recipe:getName()] then local ingredientName = recipe:getSource():get(0):getItems():get(0) if ingredientName == cigarettesPack:getFullType() then break else recipe = nil end else recipe = nil end end end if recipe then -- print("Recipe to be used: ", recipe:getName()) -- print(recipe) cigarettes = RecipeManager.PerformMakeItem(recipe, cigarettesPack, player, EHK.getContainers()) -- printFuckingNormalObject(cigarettes, "cigarettes") inv:AddItem(cigarettes) else -- print("No recipe found!") player:Say("Must remember to unpack cigarettes!") return end end end local fireSource = getFirstItem(EHK.fireSources, inv) if not fireSource then dialogueNo = ZombRand(3) + 1 player:Say(lightDialogues[dialogueNo]) return end fireSourceContainer = fireSource:getContainer() -- print("cigarettes", cigarettes) if cigarettes then ISInventoryPaneContextMenu.eatItem(cigarettes, 1, 0) local transferFireSource = ISInventoryTransferAction:new(player, fireSource, inv, fireSourceContainer) ISTimedActionQueue.add(transferFireSource) else print("ERROR! Cigarettes not obtained!") end end Thanks for your help!
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