Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- db = sql.create("accounts.db")
- sql.query(db, "CREATE TABLE IF NOT EXISTS `users` (`uid` INTEGER PRIMARY KEY, `username`, `password`, `playername`, `kills` INTEGER DEFAULT 0, `deaths` INTEGER DEFAULT 0)")
- AddEventListener("OnChat", "Chat")
- AddEventListener("OnClientConnect", "ClientConnect")
- AddEventListener("OnClientEnter", "ClientEnter")
- AddEventListener("OnDie", "Kill")
- AddEventListener("OnPlayerJoinTeam", "PlayerJoinTeam")
- AddEventListener("OnClientDrop", "Leave")
- Accounts = {}
- KDRate = 0
- iTick = 0
- function Tick(Time, ServerTick)
- iTick = iTick + 1
- end
- function TickDefered(Time, ServerTick)
- end
- function PostTick(Time, ServerTick)
- end
- function EscapeString(str)
- str = tostring(str)
- str = str:replace("\\", "\\\\")
- str = str:replace("'", "''")
- return str
- end
- function CheckAccount(Name)
- result = sql.query(db, "SELECT * FROM `users` WHERE `username` = '" .. EscapeString(Name) .. "'")
- if (result[1] and result[1]["uid"]) then
- return true
- end
- return false
- end
- function GetParameter(Text, Number)
- for i = 1, Number do
- s = Text:find(" ")
- if (s == nil) then
- return nil
- end
- Text = Text:sub(s + 1)
- end
- s = Text:find(" ")
- if (s ~= nil) then
- s = s - 1
- end
- Text = Text:sub(1, s)
- return Text
- end
- function Update(ClientID)
- if (Accounts[ClientID]["uid"] == nil) then
- return
- end
- sql.query(db, "UPDATE `users` SET `playername` = '" .. EscapeString(GetPlayerName(ClientID)) .. "', `kills` = '" .. EscapeString(Accounts[ClientID]["kills"]) .. "', `deaths` = '" .. EscapeString(Accounts[ClientID]["deaths"]) .. "' WHERE `uid` = '" .. Accounts[ClientID]["uid"] .. "'")
- end
- function Register(User, Pass, ClientID)
- if(CheckAccount(User) == true) then
- Login(User, Pass, ClientID)
- else
- sql.query(db, "INSERT INTO `users` (`username`, `password`, `playername`) VALUES ('" .. EscapeString(User) .. "', '" .. EscapeString(Pass) .. "', '" .. EscapeString(GetPlayerName(ClientID)) .. "')")
- Login(User, Pass, ClientID)
- end
- end
- function Login(User, Pass, ClientID)
- result = sql.query(db, "SELECT * FROM `users` WHERE `username` = '" .. EscapeString(User) .. "' AND `password` = '" .. EscapeString(Pass) .. "'")
- if (result[1] and result[1]["uid"]) then
- Accounts[ClientID] = result[1]
- Print("kills", result[1]["kills"])
- Print("deaths", result[1]["deaths"])
- SetPlayerScore(ClientID, Accounts[ClientID]["kills"])
- SetPlayerTeam(ClientID, 0)
- else
- Register(User, Pass, ClientID)
- end
- end
- function Logout(ClientID)
- Update(ClientID)
- Accounts[ClientID] = {}
- SetPlayerTeam(ClientID, -1)
- end
- function GetStats(ID)
- SendChatTarget(ID, "Kills: "..Accounts[ID]["kills"])
- SendChatTarget(ID, "Deaths: "..Accounts[ID]["deaths"])
- if(Accounts[ID]["kills"] < 1 or Accounts[ID]["deaths"] < 1) then
- KDRate = 0
- else
- KDRate = ((Accounts[ID]["kills"])/(Accounts[ID]["deaths"]))
- end
- SendChatTarget(ID, "K/D: "..KDRate)
- end
- function Chat(Text, ID, Team)
- if (Text:sub(1, 1) == "/") then
- if (Text:sub(1, 6) == "/stats" and (Text:len() == 6)) then
- GetStats(ID)
- elseif (Text:sub(1, 8) == "/cmdlist" and (Text:len() == 8)) then
- SendChatTarget(ID, "Servercommands:")
- SendChatTarget(ID, "Commando - Funktion")
- SendChatTarget(ID, "/stats - Gibt deine Stats wieder, Score etc.")
- SendChatTarget(ID, "/info - Info ueber die Mod")
- elseif (Text:sub(1, 5) == "/info" and (Text:len() == 5)) then
- SendChatTarget(ID, "System based on the Lua Accountsystem by Map")
- SendChatTarget(ID, "Death Match with Saved Scores. Have Fun!")
- else
- SendChatTarget(ID, "Unknown command")
- SendChatTarget(ID, "/cmdlist")
- end
- return true
- end
- end
- function Kill(Killer, Victim, Weapon)
- if (Killer ~= Victim) then
- Accounts[Killer]["kills"] = Accounts[Killer]["kills"] + 1
- end
- Accounts[Victim]["deaths"] = Accounts[Killer]["deaths"] + 1
- end
- function Leave(ID, Reason)
- Update(ID)
- end
- function ClientConnect(ClientID)
- Print("Clear", ClientID)
- Accounts[ClientID] = {}
- --SetPlayerTeam(ClientID, -1)
- end
- function ClientEnter(ClientID)
- Register(GetPlayerName(ClientID), GetPlayerClan(ClientID), ClientID)
- end
Add Comment
Please, Sign In to add comment