mirror of
https://github.com/etlegacy/etlegacy-lua-scripts.git
synced 2024-11-29 07:32:41 +00:00
code cleanup
This commit is contained in:
parent
d2db0f9b43
commit
1d6ce0a27a
1 changed files with 16 additions and 34 deletions
|
@ -76,8 +76,8 @@ function saveSR(clientNum)
|
||||||
-- save data
|
-- save data
|
||||||
cur = assert(con:execute(string.format([[UPDATE users SET
|
cur = assert(con:execute(string.format([[UPDATE users SET
|
||||||
last_seen='%s',
|
last_seen='%s',
|
||||||
mu='%s',
|
mu='%f',
|
||||||
sigma='%s'
|
sigma='%f'
|
||||||
WHERE guid='%s']],
|
WHERE guid='%s']],
|
||||||
os.date("%Y-%m-%d %H:%M:%S"),
|
os.date("%Y-%m-%d %H:%M:%S"),
|
||||||
et.gentity_get(clientNum, "sess.mu"),
|
et.gentity_get(clientNum, "sess.mu"),
|
||||||
|
@ -108,6 +108,7 @@ function et_InitGame(levelTime, randomSeed, restart)
|
||||||
|
|
||||||
-- drop database
|
-- drop database
|
||||||
-- cur = assert(con:execute("DROP TABLE users"))
|
-- cur = assert(con:execute("DROP TABLE users"))
|
||||||
|
cur = assert(con:execute("DROP TABLE IF EXISTS match"))
|
||||||
|
|
||||||
-- create database
|
-- create database
|
||||||
cur = assert(con:execute[[
|
cur = assert(con:execute[[
|
||||||
|
@ -121,7 +122,7 @@ function et_InitGame(levelTime, randomSeed, restart)
|
||||||
]])
|
]])
|
||||||
|
|
||||||
cur = assert(con:execute[[
|
cur = assert(con:execute[[
|
||||||
CREATE TABLE IF NOT EXISTS match(
|
CREATE TABLE match(
|
||||||
guid VARCHAR(64),
|
guid VARCHAR(64),
|
||||||
time_axis INT,
|
time_axis INT,
|
||||||
time_allies INT,
|
time_allies INT,
|
||||||
|
@ -135,8 +136,6 @@ end
|
||||||
function et_ShutdownGame(restart)
|
function et_ShutdownGame(restart)
|
||||||
-- check status
|
-- check status
|
||||||
if g_skillRating < 1 then return end
|
if g_skillRating < 1 then return end
|
||||||
-- drop temporary table
|
|
||||||
cur = assert(con:execute("DROP TABLE match"))
|
|
||||||
-- clean up
|
-- clean up
|
||||||
cur:close()
|
cur:close()
|
||||||
con:close()
|
con:close()
|
||||||
|
@ -247,7 +246,7 @@ function et_ClientBegin(clientNum)
|
||||||
et.trap_SendServerCommand(clientNum, "cpm \"^2[Skill Rating]:^7 Welcome, " .. name .. "^7! You are playing on an Skill Rating enabled server\n\"")
|
et.trap_SendServerCommand(clientNum, "cpm \"^2[Skill Rating]:^7 Welcome, " .. name .. "^7! You are playing on an Skill Rating enabled server\n\"")
|
||||||
|
|
||||||
-- use default values
|
-- use default values
|
||||||
cur = assert(con:execute(string.format("INSERT INTO users VALUES ('%s', '%s', '%s', '%s')",
|
cur = assert(con:execute(string.format("INSERT INTO users VALUES ('%s', '%s', '%f', '%f')",
|
||||||
guid,
|
guid,
|
||||||
os.date("%Y-%m-%d %H:%M:%S"),
|
os.date("%Y-%m-%d %H:%M:%S"),
|
||||||
25,
|
25,
|
||||||
|
@ -268,15 +267,9 @@ function et_ClientBegin(clientNum)
|
||||||
et.gentity_set(clientNum, "sess.oldmu", tonumber(user.mu))
|
et.gentity_set(clientNum, "sess.oldmu", tonumber(user.mu))
|
||||||
et.gentity_set(clientNum, "sess.oldsigma", tonumber(user.sigma))
|
et.gentity_set(clientNum, "sess.oldsigma", tonumber(user.sigma))
|
||||||
|
|
||||||
et.trap_SendServerCommand(clientNum, string.format("cpm \"^2[Skill Rating]:^7 Welcome back, %s^7! Your rating is ^3%s\n\"",
|
et.trap_SendServerCommand(clientNum, string.format("cpm \"^2[Skill Rating]:^7 Welcome back, %s^7! Your rating is ^3%.2f\n\"",
|
||||||
name, string.format("%.2f", math.max(user.mu - 3 * user.sigma, 0))
|
name, math.max(user.mu - 3 * user.sigma, 0))
|
||||||
))
|
)
|
||||||
-- et.trap_SendServerCommand(clientNum, string.format("cpm \"^2[Skill Rating]:^7 Welcome back, %s^7! Your rating is ^3%s ^7(^1%s^7,^4%s^7)\n\"",
|
|
||||||
-- name,
|
|
||||||
-- string.format("%.2f", math.max(user.mu - 3 * user.sigma, 0)),
|
|
||||||
-- string.format("%.2f", user.mu),
|
|
||||||
-- string.format("%.2f", user.sigma)
|
|
||||||
-- ))
|
|
||||||
|
|
||||||
-- load current play time, if reconnecting to the same match
|
-- load current play time, if reconnecting to the same match
|
||||||
cur = assert(con:execute(string.format("SELECT * FROM match WHERE guid='%s'", guid)))
|
cur = assert(con:execute(string.format("SELECT * FROM match WHERE guid='%s'", guid)))
|
||||||
|
@ -305,14 +298,9 @@ function et_ClientCommand(clientNum, cmd)
|
||||||
local mu = et.gentity_get(clientNum, "sess.mu")
|
local mu = et.gentity_get(clientNum, "sess.mu")
|
||||||
local sigma = et.gentity_get(clientNum, "sess.sigma")
|
local sigma = et.gentity_get(clientNum, "sess.sigma")
|
||||||
|
|
||||||
et.trap_SendServerCommand(clientNum, string.format("cpm \"^2[Skill Rating]:^7 Your rating is ^3%s\n\"",
|
et.trap_SendServerCommand(clientNum, string.format("cpm \"^2[Skill Rating]:^7 Your rating is ^3%.2f\n\"",
|
||||||
string.format("%.2f", math.max(mu - 3 * sigma, 0))
|
math.max(mu - 3 * sigma, 0))
|
||||||
))
|
)
|
||||||
-- et.trap_SendServerCommand(clientNum, string.format("cpm \"^2[Skill Rating]:^7 Your rating is ^3%s^7 (^1%s^7, ^4%s^7)\n\"",
|
|
||||||
-- string.format("%.2f", math.max(mu - 3 * sigma, 0)),
|
|
||||||
-- string.format("%.2f", mu),
|
|
||||||
-- string.format("%.2f", sigma)
|
|
||||||
-- ))
|
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -352,13 +340,9 @@ function et_ConsoleCommand()
|
||||||
et.G_Print("^2[Skill Rating]:^3 " .. tonumber(cur:fetch(row, 'a')) .. "^7 users in database\n")
|
et.G_Print("^2[Skill Rating]:^3 " .. tonumber(cur:fetch(row, 'a')) .. "^7 users in database\n")
|
||||||
local guid, lastseen, mu, sigma
|
local guid, lastseen, mu, sigma
|
||||||
for guid, lastseen, mu, sigma in rows(con, "SELECT * FROM users") do
|
for guid, lastseen, mu, sigma in rows(con, "SELECT * FROM users") do
|
||||||
et.G_Print(string.format("\tGUID %s\tLast seen: %s mu: ^1%s^: sigma: ^4%s^: Rating: ^3%s\n",
|
et.G_Print(string.format("\tGUID %s\tLast seen: %s mu: ^1%.2f^: sigma: ^4%.2f^: Rating: ^3%.2f\n",
|
||||||
guid,
|
guid, lastseen, mu, sigma, math.max(mu - 3 * sigma, 0))
|
||||||
lastseen,
|
)
|
||||||
string.format("%.2f", mu),
|
|
||||||
string.format("%.2f", sigma),
|
|
||||||
string.format("%.2f", math.max(mu - 3 * sigma, 0))
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
-- cur:close()
|
-- cur:close()
|
||||||
return 1
|
return 1
|
||||||
|
@ -371,10 +355,8 @@ function et_ConsoleCommand()
|
||||||
local guid, time_axis, time_allies
|
local guid, time_axis, time_allies
|
||||||
for guid, time_axis, time_allies in rows(con, "SELECT * FROM match") do
|
for guid, time_axis, time_allies in rows(con, "SELECT * FROM match") do
|
||||||
et.G_Print(string.format("\tGUID %s\tTime Axis: %i\tTime Allies: %i\n",
|
et.G_Print(string.format("\tGUID %s\tTime Axis: %i\tTime Allies: %i\n",
|
||||||
guid,
|
guid, time_axis, time_allies)
|
||||||
time_axis,
|
)
|
||||||
time_allies
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
-- cur:close()
|
-- cur:close()
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in a new issue