Jump to content

Need help with getting something to work...


Recommended Posts

Hello, I need help trying to make some code work in a more proper way... Here's the code 

inst:ListenForEvent("sheltered", function(inst, data)
if data and inst.components.sanity:IsSane() then
inst:DoTaskInTime(3.5, function(inst)
inst:AddTag("notarget")
inst.DynamicShadow:Enable(false)
inst.AnimState:SetMultColour(.1,.1,.1,.1)
local x, y, z = inst.Transform:GetWorldPosition()
SpawnPrefab("small_puff").Transform:SetPosition(x, y, z)
end, inst)
end
else
inst:RemoveTag("notarget")
inst.DynamicShadow:Enable(true)
inst.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
inst:DoTaskInTime(3.5, function(inst)
inst:RemoveTag("notarget")
inst.DynamicShadow:Enable(true)
inst.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
end, inst)
end
end)

Now i'm trying to make it my character hides when sheltered after being under a tree for 3.5 seconds but the problem is inst:DoTaskInTime(3.5, function(inst) still activates if I leave under the tree which kinda sucks :(...

So, i'm wondering can someone make the code that if he leaves under the tree then the inst:DoTaskInTime(3.5, function(inst) will be canceled because I don't know how to do that :(...

PS. If you help me fix my problem can you also maybe if possible make that if he moves or attacks something then all of the sheltered bonuses under inst:DoTaskInTime(3.5, function(inst) get removed (or reset) that would be so awesome :D!! Thanks for any help or reading this :D!

Edited by SuperDavid
Link to comment
Share on other sites

Well I don't need help anymore for making the code work properly since I fixed it by putting a cooldown on hiding like this 

if inst.hiding_cooldown == nil then
inst.hiding_cooldown = true
inst:DoTaskInTime(10, function() inst.hiding_cooldown = nil end)
inst:AddTag("notarget")
inst.DynamicShadow:Enable(false)
inst.components.combat.damagemultiplier = 2
inst.AnimState:SetMultColour(.15,.15,.15,.15)
local x, y, z = inst.Transform:GetWorldPosition()
SpawnPrefab("small_puff").Transform:SetPosition(x, y, z)
end

So that's all good :)! Now if anyone can just tell me how to make it when he attacks something he loses the "notarget" and all that stuff that would be great :D!!

Link to comment
Share on other sites

I also made him get unhided when he attacks by doing this 

inst:ListenForEvent("onattackother", function(inst, data)
if inst.components.sheltered.sheltered and inst.components.sanity:IsSane() and inst.components.hunger.current >= 150 then
inst:RemoveTag("notarget")
inst.DynamicShadow:Enable(true)
inst.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
inst.components.combat.damagemultiplier = 1.75
elseif inst.components.sheltered.sheltered and inst.components.sanity:IsSane() and inst.components.hunger.current <= 149.99 then
inst:RemoveTag("notarget")
inst.DynamicShadow:Enable(true)
inst.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
inst.components.combat.damagemultiplier = 1.50
end
end)

Okay, so I don't need any help on this topic anymore I got everything to work fine, thanks for reading :D!

Edited by SuperDavid
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...