From a6ad5a7e2f70d305816998c020da25fcf52e69ef Mon Sep 17 00:00:00 2001 From: Kanersps Date: Mon, 7 Jan 2019 17:10:31 +0100 Subject: [PATCH] Comprehensive comments detailing what everything does, planned for the future for everything --- server/player/login.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/server/player/login.lua b/server/player/login.lua index 0bafe84..2fad542 100644 --- a/server/player/login.lua +++ b/server/player/login.lua @@ -3,31 +3,39 @@ -- NO TOUCHY, IF SOMETHING IS WRONG CONTACT KANERSPS! -- -- NO TOUCHY, IF SOMETHING IS WRONG CONTACT KANERSPS! -- +-- Loads the user when called, only ever needs to get called once function LoadUser(identifier, source, new, licenseNotRequired) local Source = source db.retrieveUser(identifier, function(user) if user.license or licenseNotRequired then + -- Creates the player class for OOP imitation and then sets a var to say which idType was used (This isn't relevant anymore) Users[source] = CreatePlayer(source, user.permission_level, user.money, user.bank, user.identifier, user.license, user.group, user.roles or "") Users[Source].setSessionVar('idType', 'identifier') + -- Tells other resources that a player has loaded TriggerEvent('es:playerLoaded', Source, Users[Source]) log('User (' .. identifier .. ') loaded') + -- Sets a decorator on the client if enabled, allows some cool stuff on the client see: https://runtime.fivem.net/doc/natives/#_0xA06C969B02A97298 if(settings.defaultSettings.enableRankDecorators ~= "false")then TriggerClientEvent('es:setPlayerDecorator', Source, 'rank', Users[Source]:getPermissions()) end - + + -- Sets the money "icon" on the client. This is UTF8 TriggerClientEvent('es:setMoneyIcon', Source,settings.defaultSettings.moneyIcon) + -- Sends the command suggestions to the client, this creates a neat autocomplete for k,v in pairs(commandSuggestions) do TriggerClientEvent('chat:addSuggestion', Source, settings.defaultSettings.commandDelimeter .. k, v.help, v.params) end + -- If a player connected that was never on the server before then this will be triggered for other resources if new then TriggerEvent('es:newPlayerLoaded', Source, Users[Source]) end else + -- Irrelevant local license for k,v in ipairs(GetPlayerIdentifiers(Source))do @@ -48,14 +56,17 @@ function LoadUser(identifier, source, new, licenseNotRequired) end) end +-- Exported function, same as es:getPlayerFromId function getPlayerFromId(id) return Users[id] end +-- Returns all EssentialMode user objects AddEventHandler('es:getPlayers', function(cb) cb(Users) end) +-- This gets called whenever a user spawns for the first time in the server, it basically loads the player function registerUser(identifier, source) local Source = source db.doesUserExist(identifier, function(exists) @@ -69,6 +80,7 @@ function registerUser(identifier, source) end) end +-- Allow other resources to set raw data on a player instead of using helper functions, these aren't really used often. AddEventHandler("es:setPlayerData", function(user, k, v, cb) if(Users[user])then if(Users[user].get(k))then @@ -95,12 +107,14 @@ AddEventHandler("es:setPlayerData", function(user, k, v, cb) end end) +-- Same as above just easier was we know the ID already now. AddEventHandler("es:setPlayerDataId", function(user, k, v, cb) db.updateUser(user, {[k] = v}, function(d) cb("Player data edited.", true) end) end) +-- Returns the user if all checks completed, if the first if check fails then you're in a bit of trouble AddEventHandler("es:getPlayerFromId", function(user, cb) if(Users)then if(Users[user])then @@ -113,13 +127,14 @@ AddEventHandler("es:getPlayerFromId", function(user, cb) end end) +-- Same as above but uses the DB to get a user instead of memory. AddEventHandler("es:getPlayerFromIdentifier", function(identifier, cb) db.retrieveUser(identifier, function(user) cb(user) end) end) --- Function to update player money every 60 seconds. +-- Function to save player money to the database every 60 seconds. local function savePlayerMoney() SetTimeout(60000, function() Citizen.CreateThread(function()