SourNVitriol Posted January 29, 2020 Share Posted January 29, 2020 (edited) Hi everyone, need some help on the proper logic to use for this. Problem in TL;DR is the title, but to elaborate... The prefab is a flask that on use will give the character various effects depending on what's put into it. It's triggered via a custom action that uses the horn animation. None of the different things that can be put into the flask can be mixed therefore they overwrite each other (hence the elseif). All of that works very well using certain tag checks and removing them via Taker:RemoveTag (The flask is "fueled"). Now one of the effects is a bit tricky (for me): It's supposed to give regen, a small speed boost for some amount of seconds (5 for now), then send the character into a groggy state. Works well enough if you wait the duration of the effect out before swigging again. The problem though is if you use the flask between DoTaskInTime/s, they overlap, thus cancelling the boosts and the groggy effect overlaps with the speedmod I'm trying to give the character. The intended effect is to extend it. Code snippet: elseif inst:HasTag("queenbeaned") then -- local addtime = 5 -- local effecttime = (currenttime) +(addtime) = how do I have the game listen for current time/create a timer clock value instead so I can put this into the tasktime? local player = inst:GetNearestPlayer(true) if player.components.grogginess:HasGrogginess() then player:RemoveTag("groggy") player.components.locomotor:SetExternalSpeedMultiplier(player, "mychar_speed_mod", 1) end drinker.components.health:StartRegen(3, 1, nil) drinker.components.sanity:SetPercent(1, 1) drinker.components.combat.damagemultiplier = 1.5 drinker.components.locomotor:SetExternalSpeedMultiplier(drinker, "mychar_speed_mod", 1 + 1.5 ) drinker:DoTaskInTime(5, function() drinker.components.locomotor:RemoveExternalSpeedMultiplier(drinker, "mychar_speed_mod") drinker.components.combat.damagemultiplier = 1 end) drinker:DoTaskInTime(5, function() drinker.components.health:StopRegen(drinker) drinker.components.sanity:SetPercent(.30, 1) end) drinker:DoTaskInTime(5, function() local player = inst:GetNearestPlayer(true) player.components.talker:Say("Good while it lasted...") player.components.grogginess:AddGrogginess(2, 0) end) My attempt at removing the groggy tag and speed mod doesn't work either. All he gets is the regen and the sanity highs and lows (which also overlap lol) Obligatory "just pace your drinking then" joke here. I also apologize for the hack spaghetti code, I'm still trying to learn and I know I'm missing something simple (like another approach entirely instead of DoTaskInTime) to ending the effect but I'm at my wit's end. Anyway, hope someone could help me out again, cheers! Edited January 29, 2020 by SourNVitriol Link to comment Share on other sites More sharing options...
Aquaterion Posted January 29, 2020 Share Posted January 29, 2020 by storing the Task, you can reference it and cancel it --this checks if the boost exists, and if it does, it cancels it if drinker.speed_boost ~= nil then drinker.speed_boost:Cancel() drinker.speed_boost = nil end drinker.speed_boost = drinker:DoTaskInTime(5, function() drinker.speed_boost = nil drinker.components.health:StopRegen(drinker) drinker.components.sanity:SetPercent(.30, 1) end) Obviously the name 'speed_boost' can be changed to anything else, ideally something that will most likely not conflict with any other variables on the player 1 Link to comment Share on other sites More sharing options...
SourNVitriol Posted January 29, 2020 Author Share Posted January 29, 2020 (edited) Wild stuff man, I didn't think of that at all. And it works! Many thanks. One other question though, about the grogginess state. Now the effect extends with chain swigging now (cause of your awesome code snippet), but when my char takes a swig from the flask during the groggy state, when using this revised code to try and remove the "slow speed": if drinker:HasTag("groggy") or drinker.components.grogginess:HasGrogginess() or drinker.components.grogginess.speedmod ~= nil then drinker:RemoveTag("groggy") drinker.components.grogginess.speedmod = nil drinker.components.locomotor:SetExternalSpeedMultiplier(drinker, "mychar_speed_mod", 1) drinker.components.grogginess:SetWearOffDuration(0.1) end This is placed at the start of the entire function. Weirdly enough, he does go out of the "sluggish" run animation and does a normal run, but still has the speedmod. He does get the boost shortly after I think the "wearofftime" has passed? But I've set it to 0.1, but the same thing happens. Which is strange... I've read the grogginess.lua, and i thought I figured this out but maybe I'm not understanding some things ? Would appreciate one last nudge in the right direction! Edited January 29, 2020 by SourNVitriol Link to comment 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