From 3d49142e14c86f54072755fef8d44163eea181a0 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Thu, 5 Dec 2019 19:42:57 -0800 Subject: [PATCH 01/18] Add Death+Respawn detection functions (player.lua) +runOnDeath(N) +runOnSpawn(N) +lastDeath(E) +lastSpawn(E) +lastSpawn() +lastDeath() +lastSpawnTime() ] - might/can remove these two as lastDeath/Spawn also gives timestamp +lastDeathTime() ]/ +deathClk() +spawnClk() --- .../gmod_wire_expression2/core/player.lua | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 72681714ee..94df7a37be 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -676,3 +676,105 @@ end e2function entity lastDisconnectedPlayer() return lastLeft end + +----- Deaths+Spawns, Dev: Vurv, 11/29/19 ----- +local DeathAlert = {} -- table of e2s that have runOnDeath(1) +local RespawnAlert = {} +local DeathList = { last = {NULL, NULL, NULL, 0} } +local RespawnList = { last = {NULL,0} } + +hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) + local entry = { victim,inflictor,attacker,CurTime() } + DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. + DeathList.last = entry -- the most recent death's table is stored here for later use. + for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. + if IsValid(ex) then + ex.context.data.runByDeath = entry + ex:Execute() + ex.context.data.runByDeath = nil + end + end +end) + +hook.Add("PlayerSpawn","Exp2PlayerDetSpwn",function(ply,transition) + local entry = {ply,CurTime()} + RespawnList[ply:EntIndex()] = entry + RespawnList.last = entry + for ex,_ in pairs(RespawnAlert) do + if IsValid(ex) then + ex.context.data.runByRespawned = entry + ex:Execute() + ex.context.data.runByRespawned = nil + end + end +end) + +__e2setcost(5) + +--- If active is 0, the chip will no longer run on death. +e2function void runOnDeath(number activate) + if activate ~= 0 then + DeathAlert[self.entity] = true + else + DeathAlert[self.entity] = nil + end +end + +e2function void runOnSpawn(number activate) + if activate ~= 0 then + RespawnAlert[self.entity] = true + else + RespawnAlert[self.entity] = nil + end +end + +--If ran by death, (defined in e2 data), gives 1 or 0 (ternary) +e2function number deathClk() + return self.data.runByDeath and 1 or 0 +end + +e2function number spawnClk() + return self.data.runByRespawned and 1 or 0 +end + +e2function number lastDeathTime() -- returns when the last death happened + local lastD = DeathList.last + if not lastD then return nil end + return lastD[4] +end + +e2function number lastSpawnTime() + local lastS = RespawnList.last + if not lastS then return nil end + return lastS[2] +end + +e2function array lastDeath(entity ply) -- gives array of the last death of certain player + if not IsValid(ply) then return nil end + if not ply:IsPlayer() then return nil end + local lastD = DeathList[ply:EntIndex()] + if not lastD then return nil end + return lastD -- Value Order: victim,inflictor,attacker,timestamp +end + +e2function array lastSpawn(entity ply) + if not IsValid(ply) then return nil end + if not ply:IsPlayer() then return nil end + local lastS = RespawnList[ply:EntIndex()] + if not lastS then return nil end + return lastS -- 1=player entity ,2=timestamp +end + +e2function array lastDeath() -- gives array of the last death + local lastD = DeathList.last + if not lastD then return nil end + return lastD +end + +e2function array lastSpawn() + local lastS = RespawnList.last + if not lastS then return nil end + return lastS +end +--******************************************-- + From 3d16277f702ee8644d2c50fa1dda1551467e2f09 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Fri, 6 Dec 2019 19:42:27 -0800 Subject: [PATCH 02/18] Additions to Spawn+Death detection functions Replaced functions from returning arrays to instead return tables that are much more straightforward. Also, removes all nil that is returned into errors and empty variables. --- .../gmod_wire_expression2/core/player.lua | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 94df7a37be..a9c1276e2e 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -677,14 +677,14 @@ e2function entity lastDisconnectedPlayer() return lastLeft end ------ Deaths+Spawns, Dev: Vurv, 11/29/19 ----- +----- Deaths+Spawns, Dev: Vurv, 12/6/19 ----- local DeathAlert = {} -- table of e2s that have runOnDeath(1) local RespawnAlert = {} local DeathList = { last = {NULL, NULL, NULL, 0} } local RespawnList = { last = {NULL,0} } hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) - local entry = { victim,inflictor,attacker,CurTime() } + local entry = { ["Victim"] = victim,["Inflictor"] = inflictor,["Attacker"] = attacker,["Timestamp"] = CurTime() } DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. @@ -696,8 +696,8 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) end end) -hook.Add("PlayerSpawn","Exp2PlayerDetSpwn",function(ply,transition) - local entry = {ply,CurTime()} +hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) + entry = {["Player"] = ply,["Timestamp"] = CurTime()} RespawnList[ply:EntIndex()] = entry RespawnList.last = entry for ex,_ in pairs(RespawnAlert) do @@ -739,41 +739,42 @@ end e2function number lastDeathTime() -- returns when the last death happened local lastD = DeathList.last - if not lastD then return nil end + if not lastD then return {} end return lastD[4] end e2function number lastSpawnTime() local lastS = RespawnList.last - if not lastS then return nil end + if not lastS then return {} end return lastS[2] end e2function array lastDeath(entity ply) -- gives array of the last death of certain player - if not IsValid(ply) then return nil end - if not ply:IsPlayer() then return nil end + if not IsValid(ply) then return error("\"" .. ply .. "\" is not a valid entity!") end + if not ply:IsPlayer() then return error("\"" .. ply .. "\" is not a player!") end local lastD = DeathList[ply:EntIndex()] - if not lastD then return nil end - return lastD -- Value Order: victim,inflictor,attacker,timestamp + if not lastD then return {} end + return lastD -- tried to do a table, ended up doing array, feel free to fix if you can. + -- Value Order: victim,inflictor,attacker,timestamp end e2function array lastSpawn(entity ply) - if not IsValid(ply) then return nil end - if not ply:IsPlayer() then return nil end + if not IsValid(ply) then return error("\"" .. ply .. "\" is not a valid entity!") end + if not ply:IsPlayer() then return error("\"" .. ply .. "\" is not a player!") end local lastS = RespawnList[ply:EntIndex()] - if not lastS then return nil end + if not lastS then return {} end return lastS -- 1=player entity ,2=timestamp end e2function array lastDeath() -- gives array of the last death local lastD = DeathList.last - if not lastD then return nil end + if not lastD then return {} end return lastD end e2function array lastSpawn() local lastS = RespawnList.last - if not lastS then return nil end + if not lastS then return {} end return lastS end --******************************************-- From ec4c97f32722ccb4bb968789db6a300b266fe748 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Fri, 6 Dec 2019 20:06:08 -0800 Subject: [PATCH 03/18] More changes to Death+Spawn functions Fixed to ACTUALLY use tables this time (other fix was not tables. All errors changed to empty variables --- .../gmod_wire_expression2/core/player.lua | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index a9c1276e2e..31086d7a9e 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -684,7 +684,16 @@ local DeathList = { last = {NULL, NULL, NULL, 0} } local RespawnList = { last = {NULL,0} } hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) - local entry = { ["Victim"] = victim,["Inflictor"] = inflictor,["Attacker"] = attacker,["Timestamp"] = CurTime() } + local entry = table.Copy({n={},ntypes={},s={},stypes={},size=0}) -- default table + entry.s["Victim"]=victim + entry.s["Inflictor"]=inflictor + entry.s["Attacker"]=attacker + entry.s["Timestamp"]=CurTime() + entry.stypes["Victim"]="e" + entry.stypes["Inflictor"]="e" + entry.stypes["Attacker"]="e" + entry.stypes["Timestamp"]="n" + entry.size=4 DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. @@ -697,7 +706,12 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) end) hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) - entry = {["Player"] = ply,["Timestamp"] = CurTime()} + local entry = table.Copy({n={},ntypes={},s={},stypes={},size=0}) -- default table + entry.s["Player"]=ply + entry.s["Timestamp"]=CurTime() + entry.stypes["Player"]="e" + entry.stypes["Timestamp"]="n" + entry.size=2 RespawnList[ply:EntIndex()] = entry RespawnList.last = entry for ex,_ in pairs(RespawnAlert) do @@ -740,42 +754,40 @@ end e2function number lastDeathTime() -- returns when the last death happened local lastD = DeathList.last if not lastD then return {} end - return lastD[4] + return lastD.s["Timestamp"] end e2function number lastSpawnTime() local lastS = RespawnList.last if not lastS then return {} end - return lastS[2] + return lastS.s["Timestamp"] end -e2function array lastDeath(entity ply) -- gives array of the last death of certain player - if not IsValid(ply) then return error("\"" .. ply .. "\" is not a valid entity!") end - if not ply:IsPlayer() then return error("\"" .. ply .. "\" is not a player!") end +e2function table lastDeath(entity ply) -- gives array of the last death of certain player + if not IsValid(ply) then return {} end + if not ply:IsPlayer() then return {} end local lastD = DeathList[ply:EntIndex()] if not lastD then return {} end - return lastD -- tried to do a table, ended up doing array, feel free to fix if you can. - -- Value Order: victim,inflictor,attacker,timestamp + return lastD end -e2function array lastSpawn(entity ply) - if not IsValid(ply) then return error("\"" .. ply .. "\" is not a valid entity!") end - if not ply:IsPlayer() then return error("\"" .. ply .. "\" is not a player!") end +e2function table lastSpawn(entity ply) + if not IsValid(ply) then return {} end + if not ply:IsPlayer() then return {} end local lastS = RespawnList[ply:EntIndex()] if not lastS then return {} end - return lastS -- 1=player entity ,2=timestamp + return lastS end -e2function array lastDeath() -- gives array of the last death +e2function table lastDeath() -- gives table of last death's data local lastD = DeathList.last if not lastD then return {} end return lastD end -e2function array lastSpawn() +e2function table lastSpawn() local lastS = RespawnList.last if not lastS then return {} end return lastS end --******************************************-- - From 6cc35e8da486149e26dc382f4634c0567e976ddc Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sat, 7 Dec 2019 18:05:13 -0800 Subject: [PATCH 04/18] Got rid of useless table copies --- lua/entities/gmod_wire_expression2/core/player.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 31086d7a9e..c298641849 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -677,14 +677,14 @@ e2function entity lastDisconnectedPlayer() return lastLeft end ------ Deaths+Spawns, Dev: Vurv, 12/6/19 ----- +----- Deaths+Spawns, Dev: Vurv, 12/7/19 ----- local DeathAlert = {} -- table of e2s that have runOnDeath(1) local RespawnAlert = {} local DeathList = { last = {NULL, NULL, NULL, 0} } local RespawnList = { last = {NULL,0} } hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) - local entry = table.Copy({n={},ntypes={},s={},stypes={},size=0}) -- default table + local entry = {n={},ntypes={},s={},stypes={},size=0} -- default table entry.s["Victim"]=victim entry.s["Inflictor"]=inflictor entry.s["Attacker"]=attacker @@ -705,8 +705,8 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) end end) -hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) - local entry = table.Copy({n={},ntypes={},s={},stypes={},size=0}) -- default table +hook.Add("PlayerSpawn","Exp2PlayerDetSpwn",function(ply,transition) + local entry = {n={},ntypes={},s={},stypes={},size=0} -- default table entry.s["Player"]=ply entry.s["Timestamp"]=CurTime() entry.stypes["Player"]="e" @@ -768,7 +768,8 @@ e2function table lastDeath(entity ply) -- gives array of the last death of certa if not ply:IsPlayer() then return {} end local lastD = DeathList[ply:EntIndex()] if not lastD then return {} end - return lastD + return lastD -- tried to do a table, ended up doing array, feel free to fix if you can. + -- Value Order: victim,inflictor,attacker,timestamp end e2function table lastSpawn(entity ply) @@ -779,7 +780,7 @@ e2function table lastSpawn(entity ply) return lastS end -e2function table lastDeath() -- gives table of last death's data +e2function table lastDeath() -- gives array of the last death local lastD = DeathList.last if not lastD then return {} end return lastD @@ -791,3 +792,4 @@ e2function table lastSpawn() return lastS end --******************************************-- + From 52e4b85d43ef96a4738eda5360e9ced483886a6b Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sat, 7 Dec 2019 18:12:45 -0800 Subject: [PATCH 05/18] Fixed outdated garbage I committed and whitespace --- lua/entities/gmod_wire_expression2/core/player.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index c298641849..51bf9e8104 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -705,7 +705,7 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) end end) -hook.Add("PlayerSpawn","Exp2PlayerDetSpwn",function(ply,transition) +hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) local entry = {n={},ntypes={},s={},stypes={},size=0} -- default table entry.s["Player"]=ply entry.s["Timestamp"]=CurTime() @@ -763,13 +763,13 @@ e2function number lastSpawnTime() return lastS.s["Timestamp"] end -e2function table lastDeath(entity ply) -- gives array of the last death of certain player +e2function table lastDeath(entity ply) if not IsValid(ply) then return {} end if not ply:IsPlayer() then return {} end local lastD = DeathList[ply:EntIndex()] if not lastD then return {} end - return lastD -- tried to do a table, ended up doing array, feel free to fix if you can. - -- Value Order: victim,inflictor,attacker,timestamp + return lastD + end e2function table lastSpawn(entity ply) @@ -780,7 +780,7 @@ e2function table lastSpawn(entity ply) return lastS end -e2function table lastDeath() -- gives array of the last death +e2function table lastDeath() local lastD = DeathList.last if not lastD then return {} end return lastD @@ -792,4 +792,3 @@ e2function table lastSpawn() return lastS end --******************************************-- - From 8650848955f00b052d68399a78e3e1f915c5174d Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sat, 7 Dec 2019 18:38:53 -0800 Subject: [PATCH 06/18] Update e2descs to fit death+spawn functions Adds "-- Damage" Tab E2Helper.Descriptions["runOnDeath(n)"] = "If set to 0, chip won't run on players dying" E2Helper.Descriptions["deathClk()"] = "Returns if the E2 was triggered by a death" E2Helper.Descriptions["lastDeathTime()"] = "Returns the last time a player died" E2Helper.Descriptions["lastDeath()"] = "Returns a table of the last death's victim,inflictor,attacker,timestamp (e,e,e,n)" E2Helper.Descriptions["lastDeath(e)"] = "Returns a table of the player's last death data (e,e,e,n)" E2Helper.Descriptions["runOnSpawn(n)"] = "If set to 0, chip won't run on players spawning" E2Helper.Descriptions["spawnClk()"] = "Returns if the E2 was triggered by a player spawning" E2Helper.Descriptions["lastSpawnTime()"] = "Returns the last time a player spawned" E2Helper.Descriptions["lastSpawn()"] = "Returns a table of the last spawn's player and timestamp (e,n)" E2Helper.Descriptions["lastSpawn(e)"] = "Returns a table of the player's last spawn data (e,n)" --- lua/wire/client/e2descriptions.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index 6933a0a197..e3586529bb 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1501,6 +1501,18 @@ E2Helper.Descriptions["toUnicodeChar(r)"] = "Returns the UTF-8 string from the g E2Helper.Descriptions["toUnicodeByte(s:nn)"] = "Returns the Unicode code-points from the given UTF-8 string" E2Helper.Descriptions["unicodeLength(s:nn)"] = "Returns the length of the given UTF-8 string" +-- Damage +E2Helper.Descriptions["runOnDeath(n)"] = "If set to 0, chip won't run on players dying" +E2Helper.Descriptions["deathClk()"] = "Returns if the E2 was triggered by a death" +E2Helper.Descriptions["lastDeathTime()"] = "Returns the last time a player died" +E2Helper.Descriptions["lastDeath()"] = "Returns a table of the last death's victim,inflictor,attacker,timestamp (e,e,e,n)" +E2Helper.Descriptions["lastDeath(e)"] = "Returns a table of the player's last death data (e,e,e,n)" +E2Helper.Descriptions["runOnSpawn(n)"] = "If set to 0, chip won't run on players spawning" +E2Helper.Descriptions["spawnClk()"] = "Returns if the E2 was triggered by a player spawning" +E2Helper.Descriptions["lastSpawnTime()"] = "Returns the last time a player spawned" +E2Helper.Descriptions["lastSpawn()"] = "Returns a table of the last spawn's player and timestamp (e,n)" +E2Helper.Descriptions["lastSpawn(e)"] = "Returns a table of the player's last spawn data (e,n)" + ---- Custom ---- -- Effect E2Helper.Descriptions["effect()"] = "Creates and returns new effect" From 236443b0a1564dcc04ac79183bcef32144e8cc1c Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sun, 8 Dec 2019 12:14:10 -0800 Subject: [PATCH 07/18] Add Default_Table, table.copy instead of {}... ~Replaces all {}'s with table.Copy(DEFAULT_TABLE) which default table is a local variable defined at the top of the death+spawn functions. ~Fixes indenting error caused by copy + paste +Also adds numeric indexes so you can either have ``` Death = lastDeath() Victim = Death["Victim",entity] Victim = Death[1,entity] <-- both will work ``` --- .../gmod_wire_expression2/core/player.lua | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 51bf9e8104..9330c56fb8 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -677,14 +677,15 @@ e2function entity lastDisconnectedPlayer() return lastLeft end ------ Deaths+Spawns, Dev: Vurv, 12/7/19 ----- +----- Deaths+Spawns, Dev: Vurv, 12/8/19 ----- local DeathAlert = {} -- table of e2s that have runOnDeath(1) local RespawnAlert = {} local DeathList = { last = {NULL, NULL, NULL, 0} } local RespawnList = { last = {NULL,0} } +local DEFAULT_TABLE = {n={},ntypes={},s={},stypes={},size=0} -- the default / empty table to use in all functions below hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) - local entry = {n={},ntypes={},s={},stypes={},size=0} -- default table + local entry = table.Copy(DEFAULT_TABLE) -- default table entry.s["Victim"]=victim entry.s["Inflictor"]=inflictor entry.s["Attacker"]=attacker @@ -693,24 +694,36 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) entry.stypes["Inflictor"]="e" entry.stypes["Attacker"]="e" entry.stypes["Timestamp"]="n" + entry.n[1]=victim + entry.n[2]=inflictor + entry.n[3]=attacker + entry.n[4]=CurTime() + entry.ntypes[1]="e" + entry.ntypes[2]="e" + entry.ntypes[3]="e" + entry.ntypes[4]="n" entry.size=4 DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. - for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. - if IsValid(ex) then - ex.context.data.runByDeath = entry - ex:Execute() - ex.context.data.runByDeath = nil - end - end + for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. + if IsValid(ex) then + ex.context.data.runByDeath = entry + ex:Execute() + ex.context.data.runByDeath = nil + end + end end) hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) - local entry = {n={},ntypes={},s={},stypes={},size=0} -- default table + local entry = table.Copy(DEFAULT_TABLE) -- default table entry.s["Player"]=ply entry.s["Timestamp"]=CurTime() entry.stypes["Player"]="e" entry.stypes["Timestamp"]="n" + entry.n[1]=ply + entry.n[2]=CurTime() + entry.ntypes[1]="e" + entry.ntypes[2]="n" entry.size=2 RespawnList[ply:EntIndex()] = entry RespawnList.last = entry @@ -753,42 +766,42 @@ end e2function number lastDeathTime() -- returns when the last death happened local lastD = DeathList.last - if not lastD then return {} end + if not lastD then return table.Copy(DEFAULT_TABLE) end return lastD.s["Timestamp"] end e2function number lastSpawnTime() local lastS = RespawnList.last - if not lastS then return {} end + if not lastS then return table.Copy(DEFAULT_TABLE) end return lastS.s["Timestamp"] end e2function table lastDeath(entity ply) - if not IsValid(ply) then return {} end - if not ply:IsPlayer() then return {} end + if not IsValid(ply) then return table.Copy(DEFAULT_TABLE) end + if not ply:IsPlayer() then return table.Copy(DEFAULT_TABLE) end local lastD = DeathList[ply:EntIndex()] - if not lastD then return {} end + if not lastD then return table.Copy(DEFAULT_TABLE) end return lastD end e2function table lastSpawn(entity ply) - if not IsValid(ply) then return {} end - if not ply:IsPlayer() then return {} end + if not IsValid(ply) then return table.Copy(DEFAULT_TABLE) end + if not ply:IsPlayer() then return table.Copy(DEFAULT_TABLE) end local lastS = RespawnList[ply:EntIndex()] - if not lastS then return {} end + if not lastS then return table.Copy(DEFAULT_TABLE) end return lastS end e2function table lastDeath() local lastD = DeathList.last - if not lastD then return {} end + if not lastD then return table.Copy(DEFAULT_TABLE) end return lastD end e2function table lastSpawn() local lastS = RespawnList.last - if not lastS then return {} end + if not lastS then return table.Copy(DEFAULT_TABLE) end return lastS end --******************************************-- From e6f827de70c4f3ae17cd9d9440fd3f31057b10b2 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sun, 8 Dec 2019 12:18:58 -0800 Subject: [PATCH 08/18] travis cl whitespace --- lua/entities/gmod_wire_expression2/core/player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 9330c56fb8..59d82e7146 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -706,7 +706,7 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. - if IsValid(ex) then + if IsValid(ex) then ex.context.data.runByDeath = entry ex:Execute() ex.context.data.runByDeath = nil From 15943b0ad3f59ee8bd0024eb296875e58f95874f Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sun, 8 Dec 2019 12:32:15 -0800 Subject: [PATCH 09/18] More whitespace e --- lua/entities/gmod_wire_expression2/core/player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 59d82e7146..7f494605d7 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -711,7 +711,7 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) ex:Execute() ex.context.data.runByDeath = nil end - end + end end) hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) From c69c0f9278ee64966e816b9301d05793a6789c99 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Tue, 10 Dec 2019 19:45:06 -0800 Subject: [PATCH 10/18] Add more efficient default table function --- .../gmod_wire_expression2/core/player.lua | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 7f494605d7..d0b0da1c56 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -677,15 +677,15 @@ e2function entity lastDisconnectedPlayer() return lastLeft end ------ Deaths+Spawns, Dev: Vurv, 12/8/19 ----- +----- Deaths+Spawns, Dev: Vurv, 12/10/19 ----- local DeathAlert = {} -- table of e2s that have runOnDeath(1) local RespawnAlert = {} local DeathList = { last = {NULL, NULL, NULL, 0} } local RespawnList = { last = {NULL,0} } -local DEFAULT_TABLE = {n={},ntypes={},s={},stypes={},size=0} -- the default / empty table to use in all functions below +local function DEFAULT_TABLE() return {n={},ntypes={},s={},stypes={},size=0} end hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) - local entry = table.Copy(DEFAULT_TABLE) -- default table + local entry = DEFAULT_TABLE() -- default table entry.s["Victim"]=victim entry.s["Inflictor"]=inflictor entry.s["Attacker"]=attacker @@ -706,16 +706,16 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. - if IsValid(ex) then + if IsValid(ex) then ex.context.data.runByDeath = entry ex:Execute() ex.context.data.runByDeath = nil end - end + end end) hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) - local entry = table.Copy(DEFAULT_TABLE) -- default table + local entry = DEFAULT_TABLE() -- default table entry.s["Player"]=ply entry.s["Timestamp"]=CurTime() entry.stypes["Player"]="e" @@ -766,42 +766,43 @@ end e2function number lastDeathTime() -- returns when the last death happened local lastD = DeathList.last - if not lastD then return table.Copy(DEFAULT_TABLE) end + if not lastD then return DEFAULT_TABLE() end return lastD.s["Timestamp"] end e2function number lastSpawnTime() local lastS = RespawnList.last - if not lastS then return table.Copy(DEFAULT_TABLE) end + if not lastS then return DEFAULT_TABLE() end return lastS.s["Timestamp"] end e2function table lastDeath(entity ply) - if not IsValid(ply) then return table.Copy(DEFAULT_TABLE) end - if not ply:IsPlayer() then return table.Copy(DEFAULT_TABLE) end + if not IsValid(ply) then return DEFAULT_TABLE() end + if not ply:IsPlayer() then return DEFAULT_TABLE() end local lastD = DeathList[ply:EntIndex()] - if not lastD then return table.Copy(DEFAULT_TABLE) end + if not lastD then return DEFAULT_TABLE() end return lastD end e2function table lastSpawn(entity ply) - if not IsValid(ply) then return table.Copy(DEFAULT_TABLE) end - if not ply:IsPlayer() then return table.Copy(DEFAULT_TABLE) end + if not IsValid(ply) then return DEFAULT_TABLE() end + if not ply:IsPlayer() then return DEFAULT_TABLE() end local lastS = RespawnList[ply:EntIndex()] - if not lastS then return table.Copy(DEFAULT_TABLE) end + if not lastS then return DEFAULT_TABLE() end return lastS end e2function table lastDeath() local lastD = DeathList.last - if not lastD then return table.Copy(DEFAULT_TABLE) end + if not lastD then return DEFAULT_TABLE() end return lastD end e2function table lastSpawn() local lastS = RespawnList.last - if not lastS then return table.Copy(DEFAULT_TABLE) end + if not lastS then return DEFAULT_TABLE() end return lastS end --******************************************-- + From 30e4b32008df2112d336ce4087a8e425985e6a6a Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Tue, 10 Dec 2019 19:50:00 -0800 Subject: [PATCH 11/18] whitespace yep --- lua/entities/gmod_wire_expression2/core/player.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index d0b0da1c56..54c33ae2c4 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -706,12 +706,12 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. - if IsValid(ex) then + if IsValid(ex) then ex.context.data.runByDeath = entry ex:Execute() ex.context.data.runByDeath = nil end - end + end end) hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) @@ -805,4 +805,3 @@ e2function table lastSpawn() return lastS end --******************************************-- - From 6c80c49485df2a458d5404d62e00767297b5f429 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Wed, 11 Dec 2019 20:05:31 -0800 Subject: [PATCH 12/18] Add a lot more e2functions + add lua funcs +lastDeathAttacker() +lastDeathAttacker(e) +lastDeathVictim() +lastDeathInflictor() +lastDeathInflictor(e) +lastDeathTime(e) +lastSpawnTime(e) +lastSpawnedPlayer() + Added lua functions to make sure player/table is valid to avoid taking up too much space and using repetitive code. (Another commit for e2descs incoming) --- .../gmod_wire_expression2/core/player.lua | 88 ++++++++++++++----- 1 file changed, 67 insertions(+), 21 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 54c33ae2c4..5259a4edee 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -677,13 +677,25 @@ e2function entity lastDisconnectedPlayer() return lastLeft end ------ Deaths+Spawns, Dev: Vurv, 12/10/19 ----- +----- Deaths+Spawns, Dev: Vurv, 12/11/19 ----- local DeathAlert = {} -- table of e2s that have runOnDeath(1) local RespawnAlert = {} local DeathList = { last = {NULL, NULL, NULL, 0} } local RespawnList = { last = {NULL,0} } + local function DEFAULT_TABLE() return {n={},ntypes={},s={},stypes={},size=0} end +local function CHECK_VALIDP(ply) -- Check if entity is valid and is a player if so then true else false + if not IsValid(ply) then return false end + if not ply:IsPlayer() then return false end + return true +end + +local function CHECK_VALIDT(table) -- Checks if table exists and return true if does else false + if not table then return false end + return true +end + hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) local entry = DEFAULT_TABLE() -- default table entry.s["Victim"]=victim @@ -702,7 +714,7 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) entry.ntypes[2]="e" entry.ntypes[3]="e" entry.ntypes[4]="n" - entry.size=4 + entry.size=8 DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. @@ -724,7 +736,7 @@ hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) entry.n[2]=CurTime() entry.ntypes[1]="e" entry.ntypes[2]="n" - entry.size=2 + entry.size=4 RespawnList[ply:EntIndex()] = entry RespawnList.last = entry for ex,_ in pairs(RespawnAlert) do @@ -766,42 +778,76 @@ end e2function number lastDeathTime() -- returns when the last death happened local lastD = DeathList.last - if not lastD then return DEFAULT_TABLE() end - return lastD.s["Timestamp"] + return CHECK_VALIDT(lastD) and lastD.s["Timestamp"] or 0 -- Checks if table is valid, if so then returns the timestamp from the table, else returns 0. +end + +e2function number lastDeathTime(entity ply) -- returns when the player provided last died + if not CHECK_VALIDP(ply) then return NULL end + local lastD = DeathList[ply:EntIndex()] + return CHECK_VALIDT(lastD) and lastD.s["Timestamp"] or 0 -- Checks if table is valid, if so then returns the timestamp from the table, else returns 0. end e2function number lastSpawnTime() local lastS = RespawnList.last - if not lastS then return DEFAULT_TABLE() end - return lastS.s["Timestamp"] + return CHECK_VALIDT(lastS) and lastS.s["Timestamp"] or 0 end -e2function table lastDeath(entity ply) - if not IsValid(ply) then return DEFAULT_TABLE() end - if not ply:IsPlayer() then return DEFAULT_TABLE() end - local lastD = DeathList[ply:EntIndex()] - if not lastD then return DEFAULT_TABLE() end - return lastD +e2function number lastSpawnTime(entity ply) -- returns the last time player provided spawned. + if not CHECK_VALIDP(ply) then return NULL end + local lastS = RespawnList.last + return CHECK_VALIDT(lastS) and lastS.s["Timestamp"] or 0 +end +e2function table lastDeath(entity ply) + if not CHECK_VALIDP(ply) then return NULL end + local lastD = RespawnList[ply:EntIndex()] + return CHECK_VALIDT(lastD) and lastD or DEFAULT_TABLE() end e2function table lastSpawn(entity ply) - if not IsValid(ply) then return DEFAULT_TABLE() end - if not ply:IsPlayer() then return DEFAULT_TABLE() end + if not CHECK_VALIDP(ply) then return NULL end local lastS = RespawnList[ply:EntIndex()] - if not lastS then return DEFAULT_TABLE() end - return lastS + return CHECK_VALIDT(lastS) and lastS or DEFAULT_TABLE() end e2function table lastDeath() local lastD = DeathList.last - if not lastD then return DEFAULT_TABLE() end - return lastD + return CHECK_VALIDT(lastD) and lastD or DEFAULT_TABLE() end e2function table lastSpawn() local lastS = RespawnList.last - if not lastS then return DEFAULT_TABLE() end - return lastS + return CHECK_VALIDT(lastS) and lastS or DEFAULT_TABLE() +end + +e2function entity lastDeathVictim() -- Gives Death Victim + local lastD = DeathList.last + return CHECK_VALIDT(lastD) and lastD.s["Victim"] or NULL +end + +e2function entity lastSpawnedPlayer() + local lastS = RespawnList.last + return CHECK_VALIDT(lastS) and lastS.s["Player"] or NULL +end + +e2function entity lastDeathInflictor() + local lastD = DeathList.last + return CHECK_VALIDT(lastD) and lastD.s["Inflictor"] or NULL +end +e2function entity lastDeathInflictor(entity ply) + if not CHECK_VALIDP(ply) then return NULL end + local lastD = DeathList[ply:EntIndex()] + return CHECK_VALIDT(lastD) and lastD.s["Inflictor"] or NULL +end + +e2function entity lastDeathAttacker() + local lastD = DeathList.last + return CHECK_VALIDT(lastD) and lastD.s["Attacker"] or NULL +end + +e2function entity lastDeathAttacker(entity ply) + if not CHECK_VALIDP(ply) then return NULL end + local lastD = DeathList.last + return CHECK_VALIDT(lastD) and lastD.s["Attacker"] or NULL end --******************************************-- From 1476cd50992c40ee93f6823dae0811f30822a373 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Wed, 11 Dec 2019 20:06:51 -0800 Subject: [PATCH 13/18] Update e2descs to fit with new functions --- lua/wire/client/e2descriptions.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index e3586529bb..f4afbcc9f1 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1505,13 +1505,22 @@ E2Helper.Descriptions["unicodeLength(s:nn)"] = "Returns the length of the given E2Helper.Descriptions["runOnDeath(n)"] = "If set to 0, chip won't run on players dying" E2Helper.Descriptions["deathClk()"] = "Returns if the E2 was triggered by a death" E2Helper.Descriptions["lastDeathTime()"] = "Returns the last time a player died" +E2Helper.Descriptions["lastDeathTime(e)"] = "Returns the last time given player died" E2Helper.Descriptions["lastDeath()"] = "Returns a table of the last death's victim,inflictor,attacker,timestamp (e,e,e,n)" E2Helper.Descriptions["lastDeath(e)"] = "Returns a table of the player's last death data (e,e,e,n)" +E2Helper.Descriptions["lastDeathInflictor()"] = "Returns the entity that inflicted the last death" +E2Helper.Descriptions["lastDeathInflictor(e)"] = "Returns the entity that inflicted the given player's last death" +E2Helper.Descriptions["lastDeathVictim()"] = "Returns the last player to die" +E2Helper.Descriptions["lastDeathAttacker()"] = "Returns the attacker who killed the last player to die" +E2Helper.Descriptions["lastDeathAttacker(e)"] = "Returns the attacker who killed the player provided in their last death" +-- E2Helper.Descriptions["runOnSpawn(n)"] = "If set to 0, chip won't run on players spawning" E2Helper.Descriptions["spawnClk()"] = "Returns if the E2 was triggered by a player spawning" E2Helper.Descriptions["lastSpawnTime()"] = "Returns the last time a player spawned" +E2Helper.Descriptions["lastSpawnTime(e)"] = "Returns the last time the given player spawned" E2Helper.Descriptions["lastSpawn()"] = "Returns a table of the last spawn's player and timestamp (e,n)" E2Helper.Descriptions["lastSpawn(e)"] = "Returns a table of the player's last spawn data (e,n)" +E2Helper.Descriptions["lastSpawnedPlayer()"] = "Returns the last player to spawn" ---- Custom ---- -- Effect From 080bdc82fcd4508ff878c153861c7b9daae3a0d1 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Wed, 11 Dec 2019 20:09:48 -0800 Subject: [PATCH 14/18] whitespace the second --- lua/entities/gmod_wire_expression2/core/player.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 5259a4edee..282864d10e 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -695,7 +695,7 @@ local function CHECK_VALIDT(table) -- Checks if table exists and return true if if not table then return false end return true end - + hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) local entry = DEFAULT_TABLE() -- default table entry.s["Victim"]=victim @@ -834,6 +834,7 @@ e2function entity lastDeathInflictor() local lastD = DeathList.last return CHECK_VALIDT(lastD) and lastD.s["Inflictor"] or NULL end + e2function entity lastDeathInflictor(entity ply) if not CHECK_VALIDP(ply) then return NULL end local lastD = DeathList[ply:EntIndex()] From bce2a5f98c2b51c8aeff83815f242b38ef36a3bc Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sat, 14 Dec 2019 15:40:37 -0800 Subject: [PATCH 15/18] Remove e2functions removing tables For now, the table returning functions aren't necessary and will be removed. -lastSpawn() -lastSpawn(e) -lastDeath() -lastDeath(e) --- .../gmod_wire_expression2/core/player.lua | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 282864d10e..d85d55d082 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -798,28 +798,6 @@ e2function number lastSpawnTime(entity ply) -- returns the last time player prov return CHECK_VALIDT(lastS) and lastS.s["Timestamp"] or 0 end -e2function table lastDeath(entity ply) - if not CHECK_VALIDP(ply) then return NULL end - local lastD = RespawnList[ply:EntIndex()] - return CHECK_VALIDT(lastD) and lastD or DEFAULT_TABLE() -end - -e2function table lastSpawn(entity ply) - if not CHECK_VALIDP(ply) then return NULL end - local lastS = RespawnList[ply:EntIndex()] - return CHECK_VALIDT(lastS) and lastS or DEFAULT_TABLE() -end - -e2function table lastDeath() - local lastD = DeathList.last - return CHECK_VALIDT(lastD) and lastD or DEFAULT_TABLE() -end - -e2function table lastSpawn() - local lastS = RespawnList.last - return CHECK_VALIDT(lastS) and lastS or DEFAULT_TABLE() -end - e2function entity lastDeathVictim() -- Gives Death Victim local lastD = DeathList.last return CHECK_VALIDT(lastD) and lastD.s["Victim"] or NULL From 2cc57e009f9f3a66616f98e4b0b88e7258d86605 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sat, 14 Dec 2019 15:41:23 -0800 Subject: [PATCH 16/18] Remove e2descriptions for non existent functions lastSpawn(),lastDeath(), etc --- lua/wire/client/e2descriptions.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index f4afbcc9f1..165d56c1cf 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1506,8 +1506,6 @@ E2Helper.Descriptions["runOnDeath(n)"] = "If set to 0, chip won't run on players E2Helper.Descriptions["deathClk()"] = "Returns if the E2 was triggered by a death" E2Helper.Descriptions["lastDeathTime()"] = "Returns the last time a player died" E2Helper.Descriptions["lastDeathTime(e)"] = "Returns the last time given player died" -E2Helper.Descriptions["lastDeath()"] = "Returns a table of the last death's victim,inflictor,attacker,timestamp (e,e,e,n)" -E2Helper.Descriptions["lastDeath(e)"] = "Returns a table of the player's last death data (e,e,e,n)" E2Helper.Descriptions["lastDeathInflictor()"] = "Returns the entity that inflicted the last death" E2Helper.Descriptions["lastDeathInflictor(e)"] = "Returns the entity that inflicted the given player's last death" E2Helper.Descriptions["lastDeathVictim()"] = "Returns the last player to die" @@ -1518,8 +1516,6 @@ E2Helper.Descriptions["runOnSpawn(n)"] = "If set to 0, chip won't run on players E2Helper.Descriptions["spawnClk()"] = "Returns if the E2 was triggered by a player spawning" E2Helper.Descriptions["lastSpawnTime()"] = "Returns the last time a player spawned" E2Helper.Descriptions["lastSpawnTime(e)"] = "Returns the last time the given player spawned" -E2Helper.Descriptions["lastSpawn()"] = "Returns a table of the last spawn's player and timestamp (e,n)" -E2Helper.Descriptions["lastSpawn(e)"] = "Returns a table of the player's last spawn data (e,n)" E2Helper.Descriptions["lastSpawnedPlayer()"] = "Returns the last player to spawn" ---- Custom ---- From f6df5d594b32e72f7f38e2239e5c2e89dc5d93b3 Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sun, 29 Dec 2019 00:57:49 -0800 Subject: [PATCH 17/18] Remove useless table stuff I can't believe I overlooked this before lol sorry --- .../gmod_wire_expression2/core/player.lua | 162 ++++++++---------- 1 file changed, 72 insertions(+), 90 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index d85d55d082..0424c1d913 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -677,44 +677,18 @@ e2function entity lastDisconnectedPlayer() return lastLeft end ------ Deaths+Spawns, Dev: Vurv, 12/11/19 ----- +----- Deaths+Spawns, Dev: Vurv, 12/28/19 ----- local DeathAlert = {} -- table of e2s that have runOnDeath(1) local RespawnAlert = {} -local DeathList = { last = {NULL, NULL, NULL, 0} } -local RespawnList = { last = {NULL,0} } - -local function DEFAULT_TABLE() return {n={},ntypes={},s={},stypes={},size=0} end - -local function CHECK_VALIDP(ply) -- Check if entity is valid and is a player if so then true else false - if not IsValid(ply) then return false end - if not ply:IsPlayer() then return false end - return true -end - -local function CHECK_VALIDT(table) -- Checks if table exists and return true if does else false - if not table then return false end - return true -end +local DeathList = { last = {} } +local RespawnList = { last = {} } hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) - local entry = DEFAULT_TABLE() -- default table - entry.s["Victim"]=victim - entry.s["Inflictor"]=inflictor - entry.s["Attacker"]=attacker - entry.s["Timestamp"]=CurTime() - entry.stypes["Victim"]="e" - entry.stypes["Inflictor"]="e" - entry.stypes["Attacker"]="e" - entry.stypes["Timestamp"]="n" - entry.n[1]=victim - entry.n[2]=inflictor - entry.n[3]=attacker - entry.n[4]=CurTime() - entry.ntypes[1]="e" - entry.ntypes[2]="e" - entry.ntypes[3]="e" - entry.ntypes[4]="n" - entry.size=8 + local entry = {} -- default table + entry.victim = victim + entry.inflictor = inflictor + entry.timestamp = CurTime() + entry.attacker = attacker DeathList[victim:EntIndex()] = entry -- victim's death is saved in victims death list. DeathList.last = entry -- the most recent death's table is stored here for later use. for ex,_ in pairs(DeathAlert) do -- loops over all chips in deathalert, ignores key. @@ -726,18 +700,11 @@ hook.Add("PlayerDeath","Exp2PlayerDetDead",function(victim,inflictor,attacker) end end) -hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(ply,transition) - local entry = DEFAULT_TABLE() -- default table - entry.s["Player"]=ply - entry.s["Timestamp"]=CurTime() - entry.stypes["Player"]="e" - entry.stypes["Timestamp"]="n" - entry.n[1]=ply - entry.n[2]=CurTime() - entry.ntypes[1]="e" - entry.ntypes[2]="n" - entry.size=4 - RespawnList[ply:EntIndex()] = entry +hook.Add("PlayerSpawn","Exp2PlayerDetRespn",function(player,transition) + local entry = {} + entry.ply = player + entry.timestamp = CurTime() + RespawnList[player:EntIndex()] = entry RespawnList.last = entry for ex,_ in pairs(RespawnAlert) do if IsValid(ex) then @@ -759,74 +726,89 @@ e2function void runOnDeath(number activate) end end -e2function void runOnSpawn(number activate) - if activate ~= 0 then - RespawnAlert[self.entity] = true - else - RespawnAlert[self.entity] = nil - end -end - --If ran by death, (defined in e2 data), gives 1 or 0 (ternary) e2function number deathClk() return self.data.runByDeath and 1 or 0 end -e2function number spawnClk() - return self.data.runByRespawned and 1 or 0 -end - e2function number lastDeathTime() -- returns when the last death happened - local lastD = DeathList.last - return CHECK_VALIDT(lastD) and lastD.s["Timestamp"] or 0 -- Checks if table is valid, if so then returns the timestamp from the table, else returns 0. + local Timestamp = DeathList.last.timestamp + if not IsValid(Timestamp) then return 0 end + return Timestamp -- Checks if num is valid, if so then returns the timestamp from the table, else returns 0. end e2function number lastDeathTime(entity ply) -- returns when the player provided last died - if not CHECK_VALIDP(ply) then return NULL end - local lastD = DeathList[ply:EntIndex()] - return CHECK_VALIDT(lastD) and lastD.s["Timestamp"] or 0 -- Checks if table is valid, if so then returns the timestamp from the table, else returns 0. + if not IsValid(ply) then return NULL end + if not ply:IsPlayer() then return NULL end + local Timestamp = DeathList[ply:EntIndex()].timestamp + if not IsValid(Timestamp) then return 0 end + return Timestamp -- Checks if num is valid, if so then returns the timestamp from the table, else returns 0. (also checks if ply is player and valid) end -e2function number lastSpawnTime() - local lastS = RespawnList.last - return CHECK_VALIDT(lastS) and lastS.s["Timestamp"] or 0 +e2function entity lastDeathVictim() -- Gives Death Victim + local Victim = DeathList.last.victim + if not IsValid(Victim) then return NULL end + return Victim end -e2function number lastSpawnTime(entity ply) -- returns the last time player provided spawned. - if not CHECK_VALIDP(ply) then return NULL end - local lastS = RespawnList.last - return CHECK_VALIDT(lastS) and lastS.s["Timestamp"] or 0 +e2function entity lastDeathInflictor() + local Inflictor = DeathList.last.inflictor + if not IsValid(Inflictor) then return NULL end + return Inflictor end -e2function entity lastDeathVictim() -- Gives Death Victim - local lastD = DeathList.last - return CHECK_VALIDT(lastD) and lastD.s["Victim"] or NULL +e2function entity lastDeathInflictor(entity ply) + if not IsValid(ply) then return NULL end + if not ply:IsPlayer() then return NULL end + local Inflictor = DeathList[ply:EntIndex()].inflictor + if not IsValid(Inflictor) then return NULL end + return Inflictor end -e2function entity lastSpawnedPlayer() - local lastS = RespawnList.last - return CHECK_VALIDT(lastS) and lastS.s["Player"] or NULL +e2function entity lastDeathAttacker() + local Attacker = DeathList.last.attacker + if not IsValid(Attacker) then return NULL end + return Attacker end -e2function entity lastDeathInflictor() - local lastD = DeathList.last - return CHECK_VALIDT(lastD) and lastD.s["Inflictor"] or NULL +e2function entity lastDeathAttacker(entity ply) + if not IsValid(ply) then return NULL end + if not ply:IsPlayer() then return NULL end + local Attacker = DeathList[ply:EntIndex()].attacker + if not IsValid(Attacker) then return NULL end + return Attacker end -e2function entity lastDeathInflictor(entity ply) - if not CHECK_VALIDP(ply) then return NULL end - local lastD = DeathList[ply:EntIndex()] - return CHECK_VALIDT(lastD) and lastD.s["Inflictor"] or NULL +-- Spawn Functions +e2function number spawnClk() + return self.data.runByRespawned and 1 or 0 end -e2function entity lastDeathAttacker() - local lastD = DeathList.last - return CHECK_VALIDT(lastD) and lastD.s["Attacker"] or NULL +e2function void runOnSpawn(number activate) + if activate ~= 0 then + RespawnAlert[self.entity] = true + else + RespawnAlert[self.entity] = nil + end end -e2function entity lastDeathAttacker(entity ply) - if not CHECK_VALIDP(ply) then return NULL end - local lastD = DeathList.last - return CHECK_VALIDT(lastD) and lastD.s["Attacker"] or NULL +e2function number lastSpawnTime() + local Timestamp = RespawnList.last.timestamp + if not IsValid(Timestamp) then return 0 end + return Timestamp +end + +e2function number lastSpawnTime(entity ply) -- returns the last time player provided spawned. + if not IsValid(ply) then return 0 end + if not ply:IsPlayer() then return 0 end + local Timestamp = SpawnList[ply:EntIndex()].timestamp + if not IsValid(Timestamp) then return 0 end + return Timestamp +end + +e2function entity lastSpawnedPlayer() + local Ply = RespawnList.last.ply + if not IsValid(Ply) then return NULL end + return Ply end --******************************************-- From 58b868b7741ebdb6c037d312cdf7977ab854b33c Mon Sep 17 00:00:00 2001 From: Vurv78 <56230599+Vurv78@users.noreply.github.com> Date: Sun, 29 Dec 2019 01:01:31 -0800 Subject: [PATCH 18/18] rusrs whitespace --- lua/entities/gmod_wire_expression2/core/player.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 0424c1d913..f4fab5f52a 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -807,7 +807,7 @@ e2function number lastSpawnTime(entity ply) -- returns the last time player prov end e2function entity lastSpawnedPlayer() - local Ply = RespawnList.last.ply + local Ply = RespawnList.last.ply if not IsValid(Ply) then return NULL end return Ply end