dynatimer: quick and dirty fix for lua 5.2.3, refs #609

This commit is contained in:
Radegast 2014-12-05 22:29:45 +01:00
parent cb8cb48ad8
commit 7baf2e4d87

View file

@ -1,6 +1,8 @@
-------------------------------------------------------------------------- --------------------------------------------------------------------------
-- dynamite.lua - a server side dynamite timer script - -- dynamite.lua - a server side dynamite timer script -
-------------------------------------------------------------------------- --------------------------------------------------------------------------
-- 1.42:
-- - made the script Lua 5.2.3 compatible
-- 1.41: -- 1.41:
-- - pheno: made the script ETpub (and other mod?) compatible -- - pheno: made the script ETpub (and other mod?) compatible
-- - pheno: made the script Lua 5.2 compatible -- - pheno: made the script Lua 5.2 compatible
@ -8,7 +10,7 @@
-- 1.4: -- 1.4:
-- - first release -- - first release
-------------------------------------------------------------------------- --------------------------------------------------------------------------
local version = "1.41" local version = "1.42"
-- Config: -- Config:
-- where to place the timer message, see -- where to place the timer message, see
@ -78,10 +80,10 @@ local T_LOCATION = 3
-- called when game inits -- called when game inits
function et_InitGame(levelTime, randomSeed, restart) function et_InitGame(levelTime, randomSeed, restart)
et.RegisterModname("dynamite.lua " .. version .. " " .. et.FindSelf()) et.RegisterModname("dynamite.lua " .. version .. " " .. et.FindSelf())
sv_maxclients = tonumber(et.trap_Cvar_Get("sv_maxclients")) sv_maxclients = tonumber(et.trap_Cvar_Get("sv_maxclients")) + 1
sv_fps = tonumber(et.trap_Cvar_Get("sv_fps")) sv_fps = tonumber(et.trap_Cvar_Get("sv_fps"))
local i = 0 local i = 0
for i=0, sv_maxclients do for i=1, sv_maxclients do
-- set to false, clients will change it, as soon as they enter the world -- set to false, clients will change it, as soon as they enter the world
table.insert(client_msg, i, false) table.insert(client_msg, i, false)
end end
@ -147,18 +149,18 @@ function et_ClientCommand(id, command)
local arg = et.trap_Argv(1) local arg = et.trap_Argv(1)
if arg == "" then if arg == "" then
local status = "^8on^7" local status = "^8on^7"
if client_msg[id] == false then if client_msg[id + 1] == false then
status = "^8off^7" status = "^8off^7"
end end
et.trap_SendServerCommand(id, string.format("%s \"^#(dynatimer):^7 Dynatimer is %s\"", announce_pos, status)) et.trap_SendServerCommand(id, string.format("%s \"^#(dynatimer):^7 Dynatimer is %s\"", announce_pos, status))
elseif tonumber(arg) == 0 then elseif tonumber(arg) == 0 then
setTimerMessages(id, false) setTimerMessages(id, false)
et.trap_SendServerCommand(id, et.trap_SendServerCommand(id,
"b 8 \"^#(dynatimer):^7 Dynatimer is now ^8off^7\"") string.format("%s \"^#(dynatimer):^7 Dynatimer is now ^8off^7\"", announce_pos))
else else
setTimerMessages(id, true) setTimerMessages(id, true)
et.trap_SendServerCommand(id, et.trap_SendServerCommand(id,
"b 8 \"^#(dynatimer):^7 Dynatimer is now ^8on^7\"") string.format("%s \"^#(dynatimer):^7 Dynatimer is now ^8on^7\"", announce_pos))
end end
return(1) return(1)
end end
@ -170,7 +172,7 @@ function sayClients(pos, msg)
local message = string.format("%s \"%s^7\"", pos, msg) local message = string.format("%s \"%s^7\"", pos, msg)
for id, timer_wanted in pairs(client_msg) do for id, timer_wanted in pairs(client_msg) do
if timer_wanted then if timer_wanted then
et.trap_SendServerCommand(id, message) et.trap_SendServerCommand(id - 1, message)
end end
end end
end end
@ -204,7 +206,7 @@ function removeTimer(location)
end end
function setTimerMessages(id, value) function setTimerMessages(id, value)
client_msg[id] = value client_msg[id + 1] = value
if value then if value then
value = "1" value = "1"
else else
@ -220,9 +222,9 @@ function updateUInfoStatus(id)
if timer == "" then if timer == "" then
setTimerMessages(id, cl_default) setTimerMessages(id, cl_default)
elseif tonumber(timer) == 0 then elseif tonumber(timer) == 0 then
client_msg[id] = false client_msg[id + 1] = false
else else
client_msg[id] = true client_msg[id + 1] = true
end end
end end
@ -235,7 +237,7 @@ function et_UserinfoChanged(id)
end end
function et_ClientDisconnect(id) function et_ClientDisconnect(id)
client_msg[id] = false client_msg[id + 1] = false
end end
-- vim: ts=4 sw=4 expandtab syn=lua -- vim: ts=4 sw=4 expandtab syn=lua