Jump to content

[SOLVED] Turn thermal stones in inventory into charcoal?


Recommended Posts

Long story short, I found an exploit for one of my character mods that I can’t get rid of. It happens when the character wears one of his custom hats and has a thermal stone in his inventory at the same time.

I think it would be funny if the exploit was prevented by the character turning thermal stones he either picks up when wearing the hat – or is holding when he puts the hat on – into charcoal.

I’ve never dealt with items turning into other items nor inventory slots before, so I wanted to ask here to see if anyone had a straightforward idea of how to do this, if it's possible! I’ve been looking at how the game turns spoiled food into rot in the meanwhile, but haven’t made much headway in applying it to the thermal stone. I'm also not sure if this would be easier done in the character file, the hat file, or the modmain via editing the thermal stone.

(If it makes things easier, my character has a tag while he wears the hat for other reasons, so only the tag has to be looked for - not the item on his head.)

Thanks for reading! Yes this is oddly specific and I'm sorry lol.

Edited by Chesed
Link to comment
Share on other sites

AddPrefabPostInit("heatrock", function(inst)
    if not GLOBAL.TheWorld.ismastersim then return end
	inst.components.inventoryitem:SetOnPickupFn(function()
		inst:DoTaskInTime(0, function()
			local owner = inst.components.inventoryitem ~= nil and inst.components.inventoryitem.owner or nil
			if owner:HasTag("YOUR CUSTOM TAG") then
				local charcoal = GLOBAL.ReplacePrefab(inst, "charcoal")
				if owner then
					owner.components.inventory:GiveItem(charcoal)
				end
			end
		end)
	end)
end)

This code will work in one direction, namely when the player picks up a thermal stone.

If you need the thermal stone to be destroyed when the hat is put on, then you must either add the code for putting on the hat, or listen when the player puts on the item and delete it already in that case, because I don’t know the code for your hat, I can offer you this the code.

AddPlayerPostInit(function(inst)
	inst:ListenForEvent("equip", function(inst, data)
		inst:DoTaskInTime(0, function()
			if inst:HasTag("YOUR CUSTOM TAG") then
				local inventory = inst.components.inventory
				for k,v in pairs(inventory.itemslots) do
					if v.prefab == "heatrock" then
						local charcoal = GLOBAL.ReplacePrefab(v, "charcoal")
						inst.components.inventory:GiveItem(charcoal)
					end
				end
			end
		end)
	end)
end)


 

Edited by kipper0k
  • Thanks 1
Link to comment
Share on other sites

Seems to work perfectly, thank you very much for the help!

 

EDIT: Had a crash on my world with caves enabled, just had to add

Quote

if not GLOBAL.TheWorld.ismastersim then return end

to the top of the second function.

Not that I think anyone else is going to find any use out of this code but just in case!

Edited by Chesed
Caves compatibility
Link to comment
Share on other sites

Posted (edited)

Currently refactoring stuff and trying to iron out an issue with this code I noticed while playing as my character.

It checks the player's inventory, but not the inventory of the player's backpack. So you can still perform the exploit by just keeping the thermal stone in there and not touching it.

Anyone know how would I go about tweaking the code above to check any equipped containers too? There's probably a way for me to brute force it but I wanted to ask first.

Edited by Chesed
Link to comment
Share on other sites

1 hour ago, Chesed said:

Currently refactoring stuff and trying to iron out an issue with this code I noticed while playing as my character.

It checks the player's inventory, but not the inventory of the player's backpack. So you can still perform the exploit by just keeping the thermal stone in there and not touching it.

Anyone know how would I go about tweaking the code above to check any equipped containers too? There's probably a way for me to brute force it but I wanted to ask first

search through inst.components.inventory:GetOverflowContainer()

  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...