Jump to content

How To Script Specific Character Stat Bonuses Using Certain Items?


Recommended Posts

Far as I know, there is no item in the game allowing specific bonuses for a specified character. So how do I make a line of code for this?

For example, if I wanted Wickerbottom to be 33% faster when holding a walking cane, how would I do it?

    inst.components.equippable.walkspeedmult = TUNING.CANE_SPEED_MULT

 

Link to comment
Share on other sites

you could do something in YOURCHAR.lua above master_postinit

local function Equip_Special_Item(inst)
	local equipped = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)

	if equipped and equipped.prefab == "cane" then
		inst.components.locomotor:SetExternalSpeedMultiplier(inst, "cane_bonus", 1.33)
	end
	
	if not equipped or (equipped and not equipped.prefab == "cane") then
		inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "cane_bonus")
	end
end

--inside master_postinit
inst:ListenForEvent("equip", Equip_Special_Item)
inst:ListenForEvent("unequip", Equip_Special_Item)

 

 

Now if you'd want to add this to a existing character like wickerbottom you would put this in modmain.lua

 

AddPrefabPostInit("wickerbottom", function(inst)
	local equipped = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)

inst:ListenForEvent("unequip", function(inst)
	if equipped and equipped.prefab == "cane" then
		inst.components.locomotor:SetExternalSpeedMultiplier(inst, "cane_bonus", 1.33)
	end
	if not equipped or (equipped and not equipped.prefab == "cane") then
		inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "cane_bonus")
	end
end)

inst:ListenForEvent("equip", function(inst)
	if equipped and equipped.prefab == "cane" then
		inst.components.locomotor:SetExternalSpeedMultiplier(inst, "cane_bonus", 1.33)
	end
	if not equipped or (equipped and not equipped.prefab == "cane") then
		inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "cane_bonus")
	end
end)

end)

 

Edited by SuperDavid
fixed coding a bit
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...