From 935139598170c407f22724c142d3aab476b17129 Mon Sep 17 00:00:00 2001 From: AlmTech Software Date: Sun, 5 Jan 2020 20:39:02 +0100 Subject: [PATCH] Added 'Effects.RemoveAll' function & added loose all effects on death hook --- gamemode/engine/lib/sh_effects.lua | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gamemode/engine/lib/sh_effects.lua b/gamemode/engine/lib/sh_effects.lua index a19b5c5..ea3228e 100644 --- a/gamemode/engine/lib/sh_effects.lua +++ b/gamemode/engine/lib/sh_effects.lua @@ -63,17 +63,32 @@ if SERVER then -- server only functions end end - function Quantum.Effect.Remove( pl, effectid ) + hook.Add( "PlayerDisconnected", "Quantum_Effects_RemoveHooksOnDisconnect", function( ply ) + Quantum.Effect.RemoveAllRuntimeFunctions( ply ) + end) + + + function Quantum.Effect.Remove( pl, effectid, character ) local effectTbl = Quantum.Effect.Get( effectid ) - local char = Quantum.Server.Char.GetCurrentCharacter( pl ) + local char = character || Quantum.Server.Char.GetCurrentCharacter( pl ) if( effectTbl != nil ) then Quantum.Effect.RemoveRuntimeFunction( pl, effectid ) - pl.effects[effectid] = nil + char.effects[effectid] = nil effectTbl.func.stop( pl ) -- run the end function end end + function Quantum.Effects.RemoveAll( pl ) + local char = Quantum.Server.Char.GetCurrentCharacter( pl ) + if( char.effects != nil ) then + Quantum.Debug( "Removing all " .. tostring(pl) .. " effects." ) + for i, effect in pairs( char.effects ) do + Quantum.Effect.Remove( pl, effect, char ) -- remove the effect + end + end + end + function Quantum.Effect.Give( pl, effectid ) local effectTbl = Quantum.Effect.Get( effectid ) local char = Quantum.Server.Char.GetCurrentCharacter( pl ) @@ -92,7 +107,13 @@ if SERVER then -- server only functions Quantum.Effect.Remove( pl, effectid ) -- remove the effect from the player after its duration is over end) end + + char.effects[ #char.effects + 1 ] = effectid -- add it to the effect table so that we can remove it later end end - + + hook.Add( "PlayerDeath", "Quantum_Effects_LooseOnDeath", function( ply ) + Quantum.Effects.RemoveAll( ply ) -- remove all effects + end) + end \ No newline at end of file