wolfadmin/luascripts/players/stats.lua

75 lines
2 KiB
Lua
Raw Normal View History

2016-02-13 11:19:37 +00:00
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
2016-02-16 13:10:00 +00:00
-- Copyright (C) 2015-2016 Timo 'Timothy' Smit
2016-02-13 11:19:37 +00:00
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-09-06 10:41:02 +00:00
local players = require "luascripts.wolfadmin.players.players"
2016-02-13 11:19:37 +00:00
2016-09-06 10:41:02 +00:00
local stats = {}
2016-02-13 11:19:37 +00:00
2016-09-06 10:41:02 +00:00
local data = {}
2016-02-13 11:19:37 +00:00
function stats.get(clientId, statKey)
2016-09-06 10:41:02 +00:00
if not players.isConnected(clientId) then
error("client "..clientId.." is not connected")
end
2016-02-13 11:19:37 +00:00
if statKey and type(statKey) == "string" and data[clientId] then
return data[clientId][statKey]
end
return false
end
function stats.set(clientId, statKey, statValue)
2016-09-06 10:41:02 +00:00
if not players.isConnected(clientId) then
error("client "..clientId.." is not connected")
end
2016-02-13 11:19:37 +00:00
if not data[clientId] then data[clientId] = {} end
if statKey and type(statKey) == "string" then
data[clientId][statKey] = statValue
return true
end
return false
end
2016-09-06 10:41:02 +00:00
function stats.add(clientId, statKey, statAdd)
2016-02-13 11:19:37 +00:00
statAdd = statAdd and statAdd or 1
return stats.set(clientId, statKey, stats.get(clientId, statKey) + statAdd)
end
2016-09-06 10:41:02 +00:00
function stats.take(clientId, statKey, statTake)
2016-02-13 11:19:37 +00:00
statTake = statTake and statTake or 1
return stats.set(clientId, statKey, stats.get(clientId, statKey) - statTake)
end
function stats.remove(clientId)
2016-09-06 10:41:02 +00:00
if not players.isConnected(clientId) then
error("client "..clientId.." is not connected")
end
2016-02-13 11:19:37 +00:00
data[clientId] = nil
return true
end
return stats