Files
ashlar/scripts/player/sql.lua
T
David Cernat 14bd073102 [General] Implement ban system and associated commands
Create banlist.json file.

Add playerName argument to Player initialization to allow the reading of player files for players who are offline.

Fix confusing syntax for some command descriptions.

Rename pname into playerName in all instances for consistency in variable naming.

Remove unnecessary spaces at the ends of certain rows.

Remove unnecessary lib/.gitkeep
2017-07-27 20:51:09 +03:00

44 lines
1.0 KiB
Lua

Database = require("database")
local BasePlayer = require("player.base")
local Player = class("Player", BasePlayer)
function Player:__init(pid, playerName)
BasePlayer.__init(self, pid, playerName)
if self.hasAccount == nil then
self.dbPid = self:GetDatabaseId()
if self.dbPid ~= nil then
self.hasAccount = true
else
self.hasAccount = false
end
end
end
function Player:CreateAccount()
Database:InsertRow("player_login", self.data.login)
self.dbPid = self:GetDatabaseId()
Database:SavePlayer(self.dbPid, self.data)
self.hasAccount = true
end
function Player:Save()
if self.hasAccount and self.loggedIn then
Database:SavePlayer(self.dbPid, self.data)
end
end
function Player:Load()
self.data = Database:LoadPlayer(self.dbPid, self.data)
end
function Player:GetDatabaseId()
local escapedName = Database:Escape(self.accountName)
return Database:GetSingleValue("player_login", "dbPid", string.format("WHERE name = '%s'", escapedName))
end
return Player