mirror of
https://github.com/etlegacy/etlegacy-lua-scripts.git
synced 2024-11-26 14:20:54 +00:00
lua: (xpsave) clean up
This commit is contained in:
parent
5862386ca4
commit
ea55f531d3
2 changed files with 33 additions and 34 deletions
|
@ -49,7 +49,6 @@ function et_InitGame(levelTime, randomSeed, restart)
|
|||
|
||||
cur = assert ( con:execute[[
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
name VARCHAR(64),
|
||||
guid VARCHAR(64),
|
||||
last_seen VARCHAR(64),
|
||||
|
||||
|
@ -66,26 +65,29 @@ function et_InitGame(levelTime, randomSeed, restart)
|
|||
]])
|
||||
end -- et_InitGame
|
||||
|
||||
function et_ShutdownGame(restart) -- clean up cur:close() con:close() env:close() end -- et_ShutdownGame
|
||||
function et_ShutdownGame(restart)
|
||||
-- clean up
|
||||
cur:close()
|
||||
con:close()
|
||||
env:close()
|
||||
end -- et_ShutdownGame
|
||||
|
||||
-- called when a client enters the game world
|
||||
function et_ClientBegin(cno)
|
||||
name = et.Info_ValueForKey( et.trap_GetUserinfo( cno ), "name" )
|
||||
guid = et.Info_ValueForKey( et.trap_GetUserinfo( cno ), "cl_guid" )
|
||||
|
||||
--et.G_Print(name .. " with guid " .. guid .. " just connected\n")
|
||||
|
||||
cur = assert (con:execute(string.format("SELECT * FROM users WHERE guid='%s'", guid)))
|
||||
player = cur:fetch({}, 'a')
|
||||
|
||||
if not player then
|
||||
-- First time we see this player
|
||||
et.G_Print ("Welcome, " .. name .. "!\n")
|
||||
cur = assert (con:execute(string.format("INSERT INTO users VALUES ('%s', '%s', '%s', '', '', '', '', '', '', '')", name, guid, os.date("%Y-%m-%d %H:%M:%S"))))
|
||||
et.trap_SendServerCommand (cno, "cpm \"" .. "Welcome, " .. name .. "!\n\"")
|
||||
cur = assert (con:execute(string.format("INSERT INTO users VALUES ('%s', '%s', 0, 0, 0, 0, 0, 0, 0)", guid, os.date("%Y-%m-%d %H:%M:%S"))))
|
||||
else
|
||||
et.G_Print ("Welcome back, " .. name .. "! You last played on " .. player.last_seen .. "\n") -- in db: player.name
|
||||
et.trap_SendServerCommand (cno, "cpm \"" .. "Welcome back, " .. name .. "! Your last connection was on " .. player.last_seen .. "\n\"") -- in db: player.name
|
||||
|
||||
et.G_Print ("Loading XP from database: " .. player.xp_battlesense .. " | " .. player.xp_engineering .. " | " .. player.xp_medic .. " | " .. player.xp_fieldops .. " | " .. player.xp_lightweapons .. " | " .. player.xp_heavyweapons .. " | " .. player.xp_covertops .. "\n\n")
|
||||
--et.G_Print ("Loading XP from database: " .. player.xp_battlesense .. " | " .. player.xp_engineering .. " | " .. player.xp_medic .. " | " .. player.xp_fieldops .. " | " .. player.xp_lightweapons .. " | " .. player.xp_heavyweapons .. " | " .. player.xp_covertops .. "\n\n")
|
||||
|
||||
et.G_XP_Set (cno, player.xp_battlesense, 0, 0)
|
||||
et.G_XP_Set (cno, player.xp_engineering, 1, 0)
|
||||
|
@ -95,9 +97,9 @@ function et_ClientBegin(cno)
|
|||
et.G_XP_Set (cno, player.xp_heavyweapons, 5, 0)
|
||||
et.G_XP_Set (cno, player.xp_covertops, 6, 0)
|
||||
|
||||
et.G_Print ("Current XP:\n")
|
||||
for id, name in pairs(skills) do
|
||||
et.G_Print ("\t" .. name .. ": " .. et.gentity_get (cno, "sess.skillpoints", id) .. " XP\n")
|
||||
et.G_Print (name .. "'s current XP levels:\n")
|
||||
for id, skill in pairs(skills) do
|
||||
et.G_Print ("\t" .. skill .. ": " .. et.gentity_get (cno, "sess.skillpoints", id) .. " XP\n")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -111,18 +113,16 @@ function et_ClientDisconnect(cno)
|
|||
name = et.Info_ValueForKey( et.trap_GetUserinfo( cno ), "name" )
|
||||
guid = et.Info_ValueForKey( et.trap_GetUserinfo( cno ), "cl_guid" )
|
||||
|
||||
--et.G_Print(name .. " with guid " .. guid .. " just disconnected\n")
|
||||
|
||||
cur = assert (con:execute(string.format("SELECT * FROM users WHERE guid='%s'", guid)))
|
||||
cur = assert (con:execute(string.format("SELECT * FROM users WHERE guid='%s' LIMIT 1", guid)))
|
||||
player = cur:fetch({}, 'a')
|
||||
|
||||
if not player then
|
||||
-- This should not happen
|
||||
et.G_Print ("ERROR: user was not found in the XP Save database!\n")
|
||||
et.G_Print ("^1ERROR: (XP Save) user was not found in the database!\n")
|
||||
return
|
||||
else
|
||||
et.G_Print ("See you again soon, " .. name .. "\n")
|
||||
for id, name in pairs(skills) do et.G_Print (name .. ": " .. et.gentity_get (cno, "sess.skillpoints", id) .. " XP\n") end
|
||||
et.trap_SendServerCommand (cno, "cpm \"" .. "See you again soon, " .. name .. "\n\"")
|
||||
--for id, name in pairs(skills) do et.G_Print (name .. ": " .. et.gentity_get (cno, "sess.skillpoints", id) .. " XP\n") end
|
||||
|
||||
cur = assert (con:execute(string.format([[UPDATE users SET
|
||||
last_seen='%s',
|
||||
|
@ -145,5 +145,4 @@ function et_ClientDisconnect(cno)
|
|||
guid
|
||||
)))
|
||||
end
|
||||
|
||||
end -- et_ClientDisconnect
|
||||
|
|
Loading…
Reference in a new issue