Jump to content

Need help with keyhandler DoTaskInTime...


Recommended Posts

Hello, I need help with this action i'm trying to do with keyhandler. Here's the code 

local STEALTH = GLOBAL.Action()
STEALTH.str = "Stealth"
STEALTH.id = "STEALTH"
STEALTH.fn = function(act)
act.target:AddComponent("grogginess")
act.target.components.grogginess:AddGrogginess(0.25)
act.target.components.grogginess:SetDecayRate(0)
act.target:AddTag("notarget")
act.target.DynamicShadow:Enable(false)
act.target.AnimState:SetMultColour(.05,.05,.05,.05)
act.target.components.talker:Say("...")
act.target.components.combat.damagemultiplier = 2.25
act.target.components.lootdropper:SpawnLootPrefab("small_puff")
act.target.components.locomotor.runspeed = 2.35 * TUNING.WILSON_RUN_SPEED
act.target:DoTaskInTime(5, function(act) --This causes disconnect from server, i'm doing it wrong but don't know how to fix it!
act.target:RemoveTag("notarget")
act.target.DynamicShadow:Enable(true)
act.target.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
act.target.components.combat.damagemultiplier = 1.75
act.target:RemoveComponent("grogginess")
act.target.components.locomotor.runspeed = 2 * TUNING.WILSON_RUN_SPEED
end, act)
end

AddAction(STEALTH) 

So I'm trying to make a stealth action with keyhandler and I want the stealth to wear off after 5 seconds but instead of wearing off after 5 seconds the game just disconnects me :(... I feel like it's because i'm putting a function in a function but I don't know how to do it the proper way. So can someone please help :)? And thanks so much for reading/helping :D!

Link to comment
Share on other sites

try

local STEALTH = GLOBAL.Action()
STEALTH.str = "Stealth"
STEALTH.id = "STEALTH"
STEALTH.fn = function(act)
act.target:AddComponent("grogginess")
act.target.components.grogginess:AddGrogginess(0.25)
act.target.components.grogginess:SetDecayRate(0)
act.target:AddTag("notarget")
act.target.DynamicShadow:Enable(false)
act.target.AnimState:SetMultColour(.05,.05,.05,.05)
act.target.components.talker:Say("...")
act.target.components.combat.damagemultiplier = 2.25
act.target.components.lootdropper:SpawnLootPrefab("small_puff")
act.target.components.locomotor.runspeed = 2.35 * TUNING.WILSON_RUN_SPEED
act.target:DoTaskInTime(5, function()
act.target:RemoveTag("notarget")
act.target.DynamicShadow:Enable(true)
act.target.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
act.target.components.combat.damagemultiplier = 1.75
act.target:RemoveComponent("grogginess")
act.target.components.locomotor.runspeed = 2 * TUNING.WILSON_RUN_SPEED
end)
end

AddAction(STEALTH) 

--btw i dont think you're suppose to remove the grogginess component itself, but the grogginess effect, else your character wont be able to get grogginess from other sources

Link to comment
Share on other sites

Thanks Aquaterion the DoTaskInTime works now :D!! Can you maybe help with one more thing :)? So when my character's insane I want him to reject hiding and so I added the code on the bottom and it works fine he rejects hiding when Insane but the problem is if his already in hiding and goes insane the game crashes and says

"string "scripts/widgets/statusdisplays.lua"]:328: attempt to index field 'sanity' (a nil value)

LUA ERROR stack traceback:

scripts/widgets/statusdisplays.lua:328 in (method) SetSanityPercent (Lua) <327-335>

scripts/widgets/statusdisplays.lua:328 in (method) SanityDelta (Lua) <337-349>

scripts/widgets/statusdisplays.lua:26 in (local) fn (Lua) <26-26>

scripts/entityscript.lua:960 in (method) PushEvent (Lua) <954-977>

scripts/prefabs/player_classified.lua:244 in (local) fn (Lua) <234-251>

scripts/entityscript.lua:960 in (method) PushEvent (Lua) <954-977>

scripts/mainfunctions.lua:285 in () ? (Lua) <282-287" I think the crash is because I don't have something for ListenForEvent goinsane but I don't know how I would add a ListenForEvent in this because I tried before and it crashed :(... I would really apprciate your help Aquaterion :D!!!!

local STEALTH = GLOBAL.Action()
STEALTH.str = "Stealth"
STEALTH.id = "STEALTH"
STEALTH.fn = function(act)
if act.target.components.sanity:IsSane() then
act.target:AddComponent("grogginess")
act.target.components.grogginess:AddGrogginess(0.25)
act.target.components.grogginess:SetDecayRate(0)
act.target:AddTag("notarget")
act.target.DynamicShadow:Enable(false)
act.target.AnimState:SetMultColour(.05,.05,.05,.05)
act.target.components.combat.damagemultiplier = 2.25
act.target.components.locomotor.runspeed = 2.35 * TUNING.WILSON_RUN_SPEED
act.target:DoTaskInTime(5, function()
act.target:RemoveTag("notarget")
act.target.DynamicShadow:Enable(true)
act.target:RemoveComponent("grogginess")
act.target.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
act.target.components.combat.damagemultiplier = 1.75
act.target.components.locomotor.runspeed = 2 * TUNING.WILSON_RUN_SPEED
end)
elseif not act.target.components.sanity:IsSane() then
act.target.components.talker:Say("I don't want to hide...")
end
end

EDIT: I tried adding a ListenForEvent and it crashed without saying anything :(...

elseif not act.target.components.sanity:IsSane() then
act.target.components.talker:Say("I don't want to hide...")
end
act.target:ListenForEvent("goinsane", function()
act.target.components.talker:Say("I don't want to hide...")
act.target:RemoveTag("notarget")
act.target.DynamicShadow:Enable(true)
act.target:RemoveComponent("grogginess")
act.target.AnimState:SetMultColour(1.0,1.0,1.0,1.0)
act.target.components.combat.damagemultiplier = 2
act.target.components.locomotor.runspeed = 2.75 * TUNING.WILSON_RUN_SPEED
end
end
end

EDIT: I don't need help anymore, my problem's being caused by AddTag:"beaver"

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