Created
December 16, 2022 17:17
-
-
Save x0rnn/e10ccfb36423d134792488490f61f4f4 to your computer and use it in GitHub Desktop.
selftimer.lua for etlegacy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- selftimer.lua by x0rnn, notifies you with sound last 3 seconds before your next respawn so you can selfkill in time | |
-- commands: !timer during match to activate it, !untimer to turn it off | |
ltm = 0 | |
redspawn = 0 | |
bluespawn = 0 | |
redspawn2 = 0 | |
bluespawn2 = 0 | |
players = {} | |
spawns = {} | |
redflag = false | |
blueflag = false | |
redlimbo1 = 0 | |
bluelimbo1 = 0 | |
redlimbo2 = 0 | |
bluelimbo2 = 0 | |
changedred = false | |
changedblue = false | |
alertflag = false | |
alerted = {} | |
alerted_id = {} | |
sound = "sound/player/hurt_barbwire.wav" | |
soundindex = "" | |
function et_InitGame(levelTime, randomSeed, restart) | |
et.RegisterModname("selftimer.lua "..et.FindSelf()) | |
soundindex = et.G_SoundIndex(sound) | |
maxClients = tonumber(et.trap_Cvar_Get("sv_maxclients")) | |
for i=0,maxClients-1 do | |
players[i] = nil | |
spawns[i] = nil | |
end | |
end | |
function et_RunFrame(levelTime) | |
local gamestate = tonumber(et.trap_Cvar_Get("gamestate")) | |
if math.fmod(levelTime, 1000) ~= 0 then return end | |
if gamestate == 0 then | |
redlimbo1 = tonumber(et.trap_Cvar_Get("g_redlimbotime")) | |
bluelimbo1 = tonumber(et.trap_Cvar_Get("g_bluelimbotime")) | |
if redlimbo2 == 0 then | |
redlimbo2 = redlimbo1 | |
bluelimbo2 = bluelimbo1 | |
end | |
if redlimbo1 ~= redlimbo2 or bluelimbo1 ~= bluelimbo2 then | |
if redlimbo1 ~= redlimbo2 then | |
changedred = true | |
redflag = false | |
redlimbo2 = redlimbo1 | |
elseif bluelimbo1 ~= bluelimbo2 then | |
changedblue = true | |
blueflag = false | |
bluelimbo2 = bluelimbo1 | |
end | |
end | |
ltm = os.time() | |
if redflag == true then | |
if alertflag == true then | |
local x = 1 | |
for index in pairs(alerted_id) do | |
local team = tonumber(et.gentity_get(alerted_id[x], "sess.sessionTeam")) | |
if team == 1 then | |
local health = tonumber(et.gentity_get(alerted_id[x], "health")) | |
local body = tonumber(et.gentity_get(alerted_id[x], "r.contents")) | |
if health > 0 or (health <= 0 and body == 67108864) then | |
if redspawn + redlimbo1 / 1000 - ltm <= 3 and redspawn + redlimbo1 / 1000 - ltm > 0 then | |
et.G_ClientSound(alerted_id[x], soundindex) | |
end | |
end | |
end | |
x = x + 1 | |
end | |
end | |
if ltm == redspawn + redlimbo1 / 1000 then | |
redspawn = ltm | |
end | |
end | |
if blueflag == true then | |
if alertflag == true then | |
local x = 1 | |
for index in pairs(alerted_id) do | |
local team = tonumber(et.gentity_get(alerted_id[x], "sess.sessionTeam")) | |
if team == 2 then | |
local health = tonumber(et.gentity_get(alerted_id[x], "health")) | |
local body = tonumber(et.gentity_get(alerted_id[x], "r.contents")) | |
if health > 0 or (health <= 0 and body == 67108864) then | |
if bluespawn + bluelimbo1 / 1000 - ltm <= 3 and bluespawn + bluelimbo1 / 1000 - ltm > 0 then | |
et.G_ClientSound(alerted_id[x], soundindex) | |
end | |
end | |
end | |
x = x + 1 | |
end | |
end | |
if ltm == bluespawn + bluelimbo1 / 1000 then | |
bluespawn = ltm | |
end | |
end | |
end | |
end | |
function et_ClientSpawn(id, revived) | |
local gamestate = tonumber(et.trap_Cvar_Get("gamestate")) | |
if gamestate == 0 then | |
if revived ~= 1 then | |
local team = tonumber(et.gentity_get(id, "sess.sessionTeam")) | |
local health = tonumber(et.gentity_get(id, "health")) | |
if team == 1 then | |
if health > 0 then | |
if redflag == false then | |
if spawns[id] == nil then | |
spawns[id] = 1 | |
else | |
spawns[id] = spawns[id] + 1 | |
end | |
if spawns[id] == 2 then | |
redflag = true | |
redspawn = os.time() | |
end | |
if changedred == true then | |
redflag = true | |
redspawn = os.time() | |
changedred = false | |
end | |
end | |
redspawn2 = os.time() | |
if redspawn ~= 0 and redspawn ~= redspawn2 then | |
redspawn = redspawn2 | |
end | |
end | |
elseif team == 2 then | |
if health > 0 then | |
if blueflag == false then | |
if spawns[id] == nil then | |
spawns[id] = 1 | |
else | |
spawns[id] = spawns[id] + 1 | |
end | |
if spawns[id] == 2 then | |
blueflag = true | |
bluespawn = os.time() | |
end | |
if changedblue == true then | |
blueflag = true | |
bluespawn = os.time() | |
changedblue = false | |
end | |
end | |
bluespawn2 = os.time() | |
if bluespawn ~= 0 and bluespawn ~= bluespawn2 then | |
bluespawn = bluespawn2 | |
end | |
end | |
end | |
end | |
end | |
end | |
function et_ClientBegin(id) | |
local team = tonumber(et.gentity_get(id, "sess.sessionTeam")) | |
if players[id] == nil then | |
players[id] = team | |
end | |
end | |
function et_ClientUserinfoChanged(id) | |
local team = tonumber(et.gentity_get(id, "sess.sessionTeam")) | |
if players[id] == nil then | |
players[id] = team | |
end | |
if players[id] ~= team then | |
spawns[id] = nil | |
end | |
end | |
function et_ClientDisconnect(id) | |
local cl_guid = et.Info_ValueForKey(et.trap_GetUserinfo(id), "cl_guid") | |
if alerted[cl_guid] == true then | |
alerted[cl_guid] = nil | |
local index={} | |
for k,v in pairs(alerted_id) do | |
index[v]=k | |
end | |
table.remove(alerted_id, index[id]) | |
if next(alerted) == nil then | |
alertflag = false | |
end | |
end | |
players[id] = nil | |
spawns[id] = nil | |
end | |
function et_ClientCommand(id, cmd) | |
local cl_guid = et.Info_ValueForKey(et.trap_GetUserinfo(id), "cl_guid") | |
local function has_value (tab, val) | |
for index, value in ipairs(tab) do | |
if value == val then | |
return true | |
end | |
end | |
return false | |
end | |
if et.trap_Argv(0) == "say" or et.trap_Argv(0) == "say_team" or et.trap_Argv(0) == "say_buddy" then | |
if et.trap_Argv(0) == "m" or et.trap_Argv(0) == "pm" then | |
if (string.sub(et.trap_Argv(2), 1, 6) == "!timer") then | |
alerted[cl_guid] = true | |
if not has_value(alerted_id, id) then | |
table.insert(alerted_id, id) | |
end | |
alertflag = true | |
end | |
if (string.sub(et.trap_Argv(2), 1, 8) == "!untimer") then | |
if alerted[cl_guid] == true then | |
alerted[cl_guid] = nil | |
local index={} | |
for k,v in pairs(alerted_id) do | |
index[v]=k | |
end | |
table.remove(alerted_id, index[id]) | |
if next(alerted) == nil then | |
alertflag = false | |
end | |
end | |
end | |
else | |
if string.lower(et.trap_Argv(1)) == "!timer" then | |
alerted[cl_guid] = true | |
if not has_value(alerted_id, id) then | |
table.insert(alerted_id, id) | |
end | |
alertflag = true | |
return 1 | |
end | |
if string.lower(et.trap_Argv(1)) == "!untimer" then | |
if alerted[cl_guid] == true then | |
alerted[cl_guid] = nil | |
local index={} | |
for k,v in pairs(alerted_id) do | |
index[v]=k | |
end | |
table.remove(alerted_id, index[id]) | |
if next(alerted) == nil then | |
alertflag = false | |
end | |
end | |
return 1 | |
end | |
end | |
end | |
return(0) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment