Jump to content

Recommended Posts

Hello I'm trying to give the Summer Frest an immunity to some event

I'm trying to do this

	local vest = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)

	if vest ~= nil then
	if vest.prefab ~= ("reflectivevest") then
	inst.components.moisture:SetPercent(100)
	end
	end

I put vest ~= nil because the game has this awesome tendency to crash if you don't tell it something can't be null

the problem is this means wearing no body item means they won't get soaked either.

I'm very confused as to how I can avoid the crash but also not have the player be immune to the soaking if they don't wear anything at all.

thank you

Link to comment
https://forums.kleientertainment.com/forums/topic/129836-life-jacket/
Share on other sites

15 minutes ago, Well-met said:

Hello I'm trying to give the Summer Frest an immunity to some event

I'm trying to do this


	local vest = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)

	if vest ~= nil then
	if vest.prefab ~= ("reflectivevest") then
	inst.components.moisture:SetPercent(100)
	end
	end

I put vest ~= nil because the game has this awesome tendency to crash if you don't tell it something can't be null

the problem is this means wearing no body item means they won't get soaked either.

I'm very confused as to how I can avoid the crash but also not have the player be immune to the soaking if they don't wear anything at all.

thank you

if (vest == nil) or (vest ~= nil and vest.prefab ~= "reflectivevest") then
  inst.components.moisture:SetPercent(100)
end

--If the vest variable doesn't exist, then pass the check, or, if it exists, and the prefab isn't "reflectivevest", pass the check.

This should help you with your issue

(Also, psst, 100 in SetPercent would be 10000%, percents in the games code are a value from 0 to 1(0% to 100%), for example 0.5 would be 50%, it shouldn't make a difference here, but I thought i'd let you know incase for the future)

  • Potato Cup 2

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
×
  • Create New...