Jump to content

Code for can't weat anything


Recommended Posts

Well i'm holding it short. If it is possible to make my character

 

can't wear any backpacks except my custom item

can't wear anything except my custom item

can't use chester (can't pick eyebone too)

can't use any weapon or tool except my custom item

when try to take eyebone must lose 30 sanity if it is possible

 

thanks for helping.

Link to comment
Share on other sites

local function OnEquip(inst)
	--Get the equipped item
	local hat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
	local body = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
	local hand = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HAND)
	
	--If it doesn't have your unique tag drop it

	if not hat:HasTag("youruniquetagname") then
		inst.components.inventory:DropItem(hat)
	end

	if not body:HasTag("youruniquetagname") then
		inst.components.inventory:DropItem(body)
	end

	if not hand:HasTag("youruniquetagname") then
		inst.components.inventory:DropItem(hand)
	end

end

local function OnPickup(inst)
	if data.prefab == "chester_eyebone" then
		local eyebone = data.prefab
		inst.components.sanity:DoDelta(-30)
		inst.components.inventory:DropItem(eyebone)
	end
end

--Add to master postinit
inst:ListenForEvent("equip", OnEquip)
inst:ListenForEvent("onpickup", OnPickup)

The easiest thing to do would be to add a tag to your unique items and if nothing has that tag then just unequip/drop any other item.

 

Edited by RedHairedHero
Link to comment
Share on other sites

4 minutes ago, RedHairedHero said:

local function OnEquip(inst)
	--Get the equipped item
	local hat = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
	local body = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
	local hand = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HAND)
	
	--If it doesn't have your unique tag drop it

	if not hat:HasTag("youruniquetagname") then
		inst.components.inventory:DropItem(hat)
	end

	if not body:HasTag("youruniquetagname") then
		inst.components.inventory:DropItem(body)
	end

	if not hand:HasTag("youruniquetagname") then
		inst.components.inventory:DropItem(hand)
	end

end

local function OnPickup(inst)
	if data.prefab == "chester_eyebone" then
		local eyebone = data.prefab
		inst.components.sanity:DoDelta(-30)
		inst.components.inventory:DropItem(eyebone)
	end
end

--Add to master postinit
inst:ListenForEvent("equip", OnEquip)
inst:ListenForEvent("onpickup", OnPickup)

The easiest thing to do would be to add a tag to your unique items and if nothing has that tag then just unequip/drop any other item.

 

Thank you very much.

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...