Jump to content

Help with sheltered event


Recommended Posts

Hello, so I want my character to gain sanity when going under a tree so I did this 

inst:ListenForEvent("sheltered", function(inst, data)
	inst.components.talker:Say(GetString(inst, "ANNOUNCE_SHELTERED"))
    inst.components.sanity:DoDelta(TUNING.SANITY_TINY)

The problem's that when she leaves under the tree she gets another sanity boost which I don't want... Is there an "stopsheltered" event :??! Any help's appreciated so much! And thanks for reading :D!

Link to comment
Share on other sites

I did this and it crashed (I probably wrote it wrong didn't I)?

if inst:ListenForEvent("sheltered", function(inst, data) then
	inst.components.sanity:DoDelta(TUNING.SANITY_SMALL)
    else
	inst.components.sanity:DoDelta(-TUNING.SANITY_TINY)
    end

Thanks for the help anyways :)!!!

Link to comment
Share on other sites

inst:ListenForEvent("sheltered", function(inst, data) 
    if data then
        inst.components.sanity:DoDelta(TUNING.SANITY_SMALL)
    else
        inst.components.sanity:DoDelta(-TUNING.SANITY_TINY)
    end
end)

Should be like this ^

Edited by Aquaterion
Link to comment
Share on other sites

Thank you so much Aquaterion!! It worked and now I can do many things with this new coding you thought me, thanks so much again :D:D!!!!! I'm really happy thank you, thank you :D!!!!!!!

Link to comment
Share on other sites

I hate to bother you but I have one more question maybe you could help with Aquaterion! With the code you gave I want to make my character "hide" so I did this 

inst:ListenForEvent("sheltered", function(inst, data) 
    if data then
	inst.components.temperature.inherentinsulation = 5 * TUNING.INSULATION_SMALL
	inst.components.temperature.inherentsummerinsulation = 5 * TUNING.INSULATION_SMALL
	inst:AddTag("hide")
    else
	inst.components.temperature.inherentinsulation = -5 * TUNING.INSULATION_SMALL
	inst.components.temperature.inherentsummerinsulation = -5 * TUNING.INSULATION_SMALL
	inst:RemoveTag("hide")
    end
    end)

I got inst:AddTag("hide") from bushhat in hats prefab but it doesn't seem to make my character hide from creatures like the bushhat does, maybe you can help me, please :)? If you don't know it's okay and thanks for all your help :D!

Link to comment
Share on other sites

I'm so, so sorry to bother you again Aquaterion but can you maybe please tell me the tag or what I have to do to make it more like hiding because inst:AddTag("notarget") makes my character really over powered because you can just hit something go in a tree and they won't target you :shock:... If there's so such a tag or code to make it more like hiding in the bushhat (or you don't know how) then it's okay :). And i'm super sorry I keep asking so many questions, please forgive me :( and thanks so MUCH:D!!!!!!!!

Link to comment
Share on other sites

3 minutes ago, SuperDavid said:

I'm so, so sorry to bother you again Aquaterion but can you maybe please tell me the tag or what I have to do to make it more like hiding because inst:AddTag("notarget") makes my character really over powered because you can just hit something go in a tree and they won't target you :shock:... If there's so such a tag or code to make it more like hiding in the bushhat (or you don't know how) then it's okay :). And i'm super sorry I keep asking so many questions, please forgive me :( and thanks so MUCH:D!!!!!!!!

well I think that's more of a problem of how you want it, the bush hat is activatable and makes you unable to move when you use it, your feature requires you to be in a certain place.

What you could do is check if your character has enemies targetting him

local enemy = FindEntity(inst, 50, function(guy) return guy.components.combat:TargetIs(inst) end))
if enemy == nil then
	inst:AddTag("notarget")
end

 

Link to comment
Share on other sites

I put it like this and it crashed 

inst:ListenForEvent("sheltered", function(inst, data)
    if data then
	inst.components.temperature.inherentinsulation = 5 * TUNING.INSULATION_SMALL
	inst.components.temperature.inherentsummerinsulation = 5 * TUNING.INSULATION_SMALL
	local enemy = FindEntity(inst, 50, function(guy) return guy.components.combat:TargetIs(inst) end))
if enemy == nil then
	inst:AddTag("notarget")
end
    else

i'm so sorry I don't know where to put it :(. Thank you again for replying back :)!

Link to comment
Share on other sites

5 minutes ago, SuperDavid said:

I put it like this and it crashed 


inst:ListenForEvent("sheltered", function(inst, data)
    if data then
	inst.components.temperature.inherentinsulation = 5 * TUNING.INSULATION_SMALL
	inst.components.temperature.inherentsummerinsulation = 5 * TUNING.INSULATION_SMALL
	local enemy = FindEntity(inst, 50, function(guy) return guy.components.combat:TargetIs(inst) end))
if enemy == nil then
	inst:AddTag("notarget")
end
    else

i'm so sorry I don't know where to put it :(. Thank you again for replying back :)!

remove 1 of the ) at the end

TargetIs(inst) end))

to

TargetIs(inst) end)

I think that should be the issue

Link to comment
Share on other sites

I did this 

inst:ListenForEvent("sheltered", function(inst, data)
    if data then
	local enemy = FindEntity(inst, 50, function(guy) return guy.components.combat:TargetIs(inst) end)
    if enemy == nil then
	inst:AddTag("notarget")
    end

And it crashed and said "attempt to index field 'combat' (a nil value)" the moment I go under a tree :?

Link to comment
Share on other sites

Thank you so, so, so, so, SO MUCH, Aquaterion!!!!!!!!!!!!!!:D:D:D:D:D:D Without your help I could've never done this, I will definitely credit you for helping me with my character's coding when I finish it, again thank you so much for being so patient with me, I appreciate it so, so much :D:D!!!!!!!!!!

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