Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

BillBobJoy

[MOD HELP] Is There A Way TO Make It So You Can Use Equipped Items For Crafting

Recommended Posts

BillBobJoy    3

Hello, I want to use the Krampus Sack in a crafting recipe, but the only way you can have it in your inventory is when it is equipped on the body. I was wondering if it is possible make it so crafting can detect and use what is equipped in addition to what is in the inventory or held with the cursor.

Share this post


Link to post
Share on other sites
BillBobJoy    3

Really I am looking for anything that I can do to make the Krampus Sack usable in a crafting recipe.

 

If it is not possible to somehow make the Krampus Sack usable for crafting when equipped is there a way I can make it so the character can hold it in there hand?

Share this post


Link to post
Share on other sites
squeek    230

This should do it (untested, though):

local Inventory = GLOBAL.require "components/inventory"local Inventory_Has_base = Inventory.Hasfunction Inventory:Has(item, amount)    local hasitems, num_found = Inventory_Has_base(self, item, amount)        if item == "krampus_sack" then        num_found = num_found or 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1            end        end        hasitems = num_found >= amount    end    return hasitems, num_foundendlocal Inventory_ConsumeByName_base = Inventory.ConsumeByNamefunction Inventory:ConsumeByName(item, amount)    Inventory_ConsumeByName_base(self, item, amount)        if item == "krampus_sack" then        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1                self:RemoveItem(equippeditem):Remove()                if num_found >= amount then                    break                end            end        end    endend

Share this post


Link to post
Share on other sites
squeek    230

@squeek

 

That did work but it didn't consume the krampus sack

self:RemoveItem(equippeditem):Remove()
This is what was supposed to delete the sack after it was used to craft right?
Yeah.

Try using this code:

local Inventory_ConsumeByName_base = Inventory.ConsumeByNamefunction Inventory:ConsumeByName(item, amount)    print("Overridden ConsumeByName called: "..tostring(item)..", "..tostring(amount))    Inventory_ConsumeByName_base(self, item, amount)         if item == "krampus_sack" then        print("Trying to consume "..tostring(amount).." krampus sack(s)")        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                print("Found krampus sack, removing")                num_found = num_found + 1                self:RemoveItem(equippeditem):Remove()                if num_found >= amount then                    break                end            end        end        if num_found == 0 then            print("No krampus sacks found")        end    endend
When you craft it, look in the console log (CTRL + L or ~) and it should print some useful information.

Share this post


Link to post
Share on other sites
squeek    230

Well, I meant to replace the bottom function with the new code I posted. Not to replace the whole thing. The first function works, this is to debug the second.

Your code should look like this:

local Inventory = GLOBAL.require "components/inventory" local Inventory_Has_base = Inventory.Hasfunction Inventory:Has(item, amount)    local hasitems, num_found = Inventory_Has_base(self, item, amount)         if item == "krampus_sack" then        num_found = num_found or 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1            end        end        hasitems = num_found >= amount    end     return hasitems, num_foundendlocal Inventory_ConsumeByName_base = Inventory.ConsumeByNamefunction Inventory:ConsumeByName(item, amount)    print("Overridden ConsumeByName called: "..tostring(item)..", "..tostring(amount))    Inventory_ConsumeByName_base(self, item, amount)          if item == "krampus_sack" then        print("Trying to consume "..tostring(amount).." krampus sack(s)")        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                print("Found krampus sack, removing")                num_found = num_found + 1                self:RemoveItem(equippeditem):Remove()                if num_found >= amount then                    break                end            end        end        if num_found == 0 then            print("No krampus sacks found")        end    endend

Share this post


Link to post
Share on other sites
squeek    230

Seems to work for me:

../mods/test/modmain.lua(5,1) Overridden ConsumeByName called: cutgrass, 2	../mods/test/modmain.lua(5,1) Overridden ConsumeByName called: twigs, 2	

Share this post


Link to post
Share on other sites
BillBobJoy    3

@squeek

 

would giving you the full mod help?

 

mrgmview.zip

 

EDIT:

 

I added the Code in the file krampusfix.lua and did a modimport "krampusfix.lua" at the top of the modmain

 

The item is in the weapons tab for crafting if you want to try it out

 

DebugSpawn"deerhide"

DebugSpawn"krampus_sack"

DebugSpawn"armorruins"

 

for the ingredients

Share this post


Link to post
Share on other sites
squeek    230

Ugh, I forgot to check if it uses a different system in the DLC and of course it does.

Here's the full code that'll work with or without DLC:

local Inventory = GLOBAL.require "components/inventory" local Inventory_Has_base = Inventory.Hasfunction Inventory:Has(item, amount)    local hasitems, num_found = Inventory_Has_base(self, item, amount)         if item == "krampus_sack" then        num_found = num_found or 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1            end        end        hasitems = num_found >= amount    end     return hasitems, num_foundendlocal Inventory_ConsumeByName_base = Inventory.ConsumeByNamefunction Inventory:ConsumeByName(item, amount)    Inventory_ConsumeByName_base(self, item, amount)          if item == "krampus_sack" then        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1                self:RemoveItem(equippeditem):Remove()                if num_found >= amount then                    break                end            end        end    endendlocal Inventory_GetItemByName_base = Inventory.GetItemByName or function() return {} endfunction Inventory:GetItemByName(item, amount)    local items = Inventory_GetItemByName_base(self, item, amount)    if item == "krampus_sack" then        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1                items[equippeditem] = 1                if num_found >= amount then                    break                end            end        end    end    return itemsend

Share this post


Link to post
Share on other sites
BillBobJoy    3

@squeek

I just realized by removing the Krampus Sack all the Contents get deleted with it, I think I'll just put a big warning in the mod description thought since that seems like a complex issue.

Share this post


Link to post
Share on other sites
squeek    230

@squeek

I just realized by removing the Krampus Sack all the Contents get deleted with it, I think I'll just put a big warning in the mod description thought since that seems like a complex issue.

Try this:

local Inventory = GLOBAL.require "components/inventory"  local Inventory_Has_base = Inventory.Hasfunction Inventory:Has(item, amount)    local hasitems, num_found = Inventory_Has_base(self, item, amount)          if item == "krampus_sack" then        num_found = num_found or 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1            end        end        hasitems = num_found >= amount    end      return hasitems, num_foundendlocal Inventory_ConsumeByName_base = Inventory.ConsumeByNamefunction Inventory:ConsumeByName(item, amount)    Inventory_ConsumeByName_base(self, item, amount)           if item == "krampus_sack" then        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1                if equippeditem.components.container then                	equippeditem.components.container:DropEverything()                end                self:RemoveItem(equippeditem):Remove()                if num_found >= amount then                    break                end            end        end    endend local Inventory_GetItemByName_base = Inventory.GetItemByName or function() return {} endfunction Inventory:GetItemByName(item, amount)    local items = Inventory_GetItemByName_base(self, item, amount)     if item == "krampus_sack" then        local num_found = 0        for k,equippeditem in pairs(self.equipslots) do            if equippeditem.prefab == item then                num_found = num_found + 1                items[equippeditem] = 1                if num_found >= amount then                    break                end            end        end    end     return itemsend-- drop container contents of krampus sack when its crafted-- DLC version (non-DLC is included in the ConsumeByName patch)if GLOBAL.IsDLCEnabled(REIGN_OF_GIANTS) then	local Builder = GLOBAL.require "components/builder"	local Builder_RemoveIngredients_base = Builder.RemoveIngredients	function Builder:RemoveIngredients(ingredients)	    for item, ents in pairs(ingredients) do	    	for k,v in pairs(ents) do	    		if k.components.container then		    		k.components.container:DropEverything()		    	end	    	end	    end	    Builder_RemoveIngredients_base(self, ingredients)	endend

Share this post


Link to post
Share on other sites
BillBobJoy    3

@squeek

Sorry for the late reply, just had to go to sleep was 5AM lol and I have Sunday courses.

 

 

The Main Game code works, The code is having trouble with the games dlc support.

 

 

It crashed in the IsDLCEnabled

 

...mapps/common/dont_starve/data/scripts/dlcsupport.lua:99: calling 'IsDLCEnabled' on bad self (number expected, got nil)
LUA ERROR stack traceback:
        =[C] in function 'IsDLCEnabled'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/dlcsupport.lua(99,1) in function 'IsDLCEnabled'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/mrgmview/krampusfix.lua(64,1) in function 'result'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(111,1) in function 'modimport'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/mrgmview/modmain.lua(21,1) in main chunk
        =[C] in function 'xpcall'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/util.lua(439,1) in function 'RunInEnvironment'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(179,1) in function 'InitializeModMain'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(162,1) in function 'LoadMods'
        scripts/main.lua(222,1) in function 'ModSafeStartup'
        scripts/main.lua(267,1)
        =[C] in function 'SetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(17,1) in function 'SavePersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(58,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(45,1) in function 'BeginStartupSequence'
        scripts/main.lua(266,1) in function 'callback'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(268,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(248,1) in function 'Load'
        scripts/main.lua(265,1) in main chunk
 
Full Log:

Share this post


Link to post
Share on other sites
BillBobJoy    3

@squeek

 

in the dlcsupport.lua they define the rog dlc as

 

REIGN_OF_GIANTS = 1

 

So I changed

 

 if GLOBAL.IsDLCEnabled(REIGN_OF_GIANTS) then

 

to

 

if GLOBAL.IsDLCEnabled(1) then

 

and it works.

Share this post


Link to post
Share on other sites