Well-met Posted May 10, 2021 Share Posted May 10, 2021 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 More sharing options...
Hornete Posted May 10, 2021 Share Posted May 10, 2021 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) 2 Link to comment https://forums.kleientertainment.com/forums/topic/129836-life-jacket/#findComment-1458969 Share on other sites More sharing options...
Well-met Posted May 10, 2021 Author Share Posted May 10, 2021 thank you, it works 1 Link to comment https://forums.kleientertainment.com/forums/topic/129836-life-jacket/#findComment-1458973 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now