refactor: use function syntax

Better and less confusing.
This commit is contained in:
Linden
2022-02-14 16:04:01 +11:00
parent 956324063e
commit d5661c1a9a
21 changed files with 198 additions and 277 deletions
-95
View File
@@ -1,95 +0,0 @@
--[[The MIT License (MIT)
Copyright (c) 2017 IllidanS4
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
]]
local entityEnumerator = {
__gc = function(enum)
if enum.destructor and enum.handle then
enum.destructor(enum.handle)
end
enum.destructor = nil
enum.handle = nil
end
}
local function EnumerateEntities(initFunc, moveFunc, disposeFunc)
return coroutine.wrap(function()
local iter, id = initFunc()
if not id or id == 0 then
disposeFunc(iter)
return
end
local enum = {handle = iter, destructor = disposeFunc}
setmetatable(enum, entityEnumerator)
local next = true
repeat
coroutine.yield(id)
next, id = moveFunc(iter)
until not next
enum.destructor, enum.handle = nil, nil
disposeFunc(iter)
end)
end
function EnumerateEntitiesWithinDistance(entities, isPlayerEntities, coords, maxDistance)
local nearbyEntities = {}
if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
local playerPed = ESX.PlayerData.ped
coords = GetEntityCoords(playerPed)
end
for k,entity in pairs(entities) do
local distance = #(coords - GetEntityCoords(entity))
if distance <= maxDistance then
table.insert(nearbyEntities, isPlayerEntities and k or entity)
end
end
return nearbyEntities
end
function EnumerateObjects()
return EnumerateEntities(FindFirstObject, FindNextObject, EndFindObject)
end
function EnumeratePeds()
return EnumerateEntities(FindFirstPed, FindNextPed, EndFindPed)
end
function EnumerateVehicles()
return EnumerateEntities(FindFirstVehicle, FindNextVehicle, EndFindVehicle)
end
function EnumeratePickups()
return EnumerateEntities(FindFirstPickup, FindNextPickup, EndFindPickup)
end
+71 -50
View File
@@ -21,7 +21,7 @@ ESX.Scaleform.Utils = {}
ESX.Streaming = {}
ESX.SetTimeout = function(msec, cb)
function ESX.SetTimeout(msec, cb)
table.insert(Core.TimeoutCallbacks, {
time = GetGameTimer() + msec,
cb = cb
@@ -29,19 +29,19 @@ ESX.SetTimeout = function(msec, cb)
return #Core.TimeoutCallbacks
end
ESX.ClearTimeout = function(i)
function ESX.ClearTimeout(i)
Core.TimeoutCallbacks[i] = nil
end
ESX.IsPlayerLoaded = function()
function ESX.IsPlayerLoaded()
return ESX.PlayerLoaded
end
ESX.GetPlayerData = function()
function ESX.GetPlayerData()
return ESX.PlayerData
end
ESX.SearchInventory = function(items, count)
function ESX.SearchInventory(items, count)
if type(items) == 'string' then items = {items} end
local returnData = {}
@@ -67,7 +67,7 @@ ESX.SearchInventory = function(items, count)
end
end
ESX.SetPlayerData = function(key, val)
function ESX.SetPlayerData(key, val)
local current = ESX.PlayerData[key]
ESX.PlayerData[key] = val
if key ~= 'inventory' and key ~= 'loadout' then
@@ -77,13 +77,13 @@ ESX.SetPlayerData = function(key, val)
end
end
ESX.ShowNotification = function(msg)
function ESX.ShowNotification(msg)
BeginTextCommandThefeedPost('STRING')
AddTextComponentSubstringPlayerName(msg)
EndTextCommandThefeedPostTicker(0,1)
end
ESX.ShowAdvancedNotification = function(sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex)
function ESX.ShowAdvancedNotification(sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex)
if saveToBrief == nil then saveToBrief = true end
AddTextEntry('esxAdvancedNotification', msg)
BeginTextCommandThefeedPost('esxAdvancedNotification')
@@ -92,7 +92,7 @@ ESX.ShowAdvancedNotification = function(sender, subject, msg, textureDict, iconT
EndTextCommandThefeedPostTicker(flash or false, saveToBrief)
end
ESX.ShowHelpNotification = function(msg, thisFrame, beep, duration)
function ESX.ShowHelpNotification(msg, thisFrame, beep, duration)
AddTextEntry('esxHelpNotification', msg)
if thisFrame then
@@ -104,7 +104,7 @@ ESX.ShowHelpNotification = function(msg, thisFrame, beep, duration)
end
end
ESX.ShowFloatingHelpNotification = function(msg, coords)
function ESX.ShowFloatingHelpNotification(msg, coords)
AddTextEntry('esxFloatingHelpNotification', msg)
SetFloatingHelpTextWorldPosition(1, coords)
SetFloatingHelpTextStyle(1, 1, 2, -1, 3, 0)
@@ -112,7 +112,7 @@ ESX.ShowFloatingHelpNotification = function(msg, coords)
EndTextCommandDisplayHelp(2, false, false, -1)
end
ESX.TriggerServerCallback = function(name, cb, ...)
function ESX.TriggerServerCallback(name, cb, ...)
Core.ServerCallbacks[Core.CurrentRequestId] = cb
TriggerServerEvent('esx:triggerServerCallback', name, Core.CurrentRequestId, ...)
@@ -124,14 +124,14 @@ ESX.TriggerServerCallback = function(name, cb, ...)
end
end
ESX.UI.HUD.SetDisplay = function(opacity)
function ESX.UI.HUD.SetDisplay(opacity)
SendNUIMessage({
action = 'setHUDDisplay',
opacity = opacity
})
end
ESX.UI.HUD.RegisterElement = function(name, index, priority, html, data)
function ESX.UI.HUD.RegisterElement(name, index, priority, html, data)
local found = false
for i=1, #ESX.UI.HUD.RegisteredElements, 1 do
@@ -159,7 +159,7 @@ ESX.UI.HUD.RegisterElement = function(name, index, priority, html, data)
ESX.UI.HUD.UpdateElement(name, data)
end
ESX.UI.HUD.RemoveElement = function(name)
function ESX.UI.HUD.RemoveElement(name)
for i=1, #ESX.UI.HUD.RegisteredElements, 1 do
if ESX.UI.HUD.RegisteredElements[i] == name then
table.remove(ESX.UI.HUD.RegisteredElements, i)
@@ -173,14 +173,14 @@ ESX.UI.HUD.RemoveElement = function(name)
})
end
ESX.UI.HUD.Reset = function()
function ESX.UI.HUD.Reset()
SendNUIMessage({
action = 'resetHUDElements'
})
ESX.UI.HUD.RegisteredElements = {}
end
ESX.UI.HUD.UpdateElement = function(name, data)
function ESX.UI.HUD.UpdateElement(name, data)
SendNUIMessage({
action = 'updateHUDElement',
name = name,
@@ -188,14 +188,14 @@ ESX.UI.HUD.UpdateElement = function(name, data)
})
end
ESX.UI.Menu.RegisterType = function(type, open, close)
function ESX.UI.Menu.RegisterType(type, open, close)
ESX.UI.Menu.RegisteredTypes[type] = {
open = open,
close = close
}
end
ESX.UI.Menu.Open = function(type, namespace, name, data, submit, cancel, change, close)
function ESX.UI.Menu.Open(type, namespace, name, data, submit, cancel, change, close)
local menu = {}
menu.type = type
@@ -280,7 +280,7 @@ ESX.UI.Menu.Open = function(type, namespace, name, data, submit, cancel, change,
return menu
end
ESX.UI.Menu.Close = function(type, namespace, name)
function ESX.UI.Menu.Close(type, namespace, name)
for i=1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and ESX.UI.Menu.Opened[i].name == name then
@@ -291,7 +291,7 @@ ESX.UI.Menu.Close = function(type, namespace, name)
end
end
ESX.UI.Menu.CloseAll = function()
function ESX.UI.Menu.CloseAll()
for i=1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
ESX.UI.Menu.Opened[i].close()
@@ -300,7 +300,7 @@ ESX.UI.Menu.CloseAll = function()
end
end
ESX.UI.Menu.GetOpened = function(type, namespace, name)
function ESX.UI.Menu.GetOpened(type, namespace, name)
for i=1, #ESX.UI.Menu.Opened, 1 do
if ESX.UI.Menu.Opened[i] then
if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and ESX.UI.Menu.Opened[i].name == name then
@@ -310,15 +310,15 @@ ESX.UI.Menu.GetOpened = function(type, namespace, name)
end
end
ESX.UI.Menu.GetOpenedMenus = function()
function ESX.UI.Menu.GetOpenedMenus()
return ESX.UI.Menu.Opened
end
ESX.UI.Menu.IsOpen = function(type, namespace, name)
function ESX.UI.Menu.IsOpen(type, namespace, name)
return ESX.UI.Menu.GetOpened(type, namespace, name) ~= nil
end
ESX.UI.ShowInventoryItemNotification = function(add, item, count)
function ESX.UI.ShowInventoryItemNotification(add, item, count)
SendNUIMessage({
action = 'inventoryNotification',
add = add,
@@ -327,7 +327,7 @@ ESX.UI.ShowInventoryItemNotification = function(add, item, count)
})
end
ESX.Game.GetPedMugshot = function(ped, transparent)
function ESX.Game.GetPedMugshot(ped, transparent)
if DoesEntityExist(ped) then
local mugshot
@@ -347,7 +347,7 @@ ESX.Game.GetPedMugshot = function(ped, transparent)
end
end
ESX.Game.Teleport = function(entity, coords, cb)
function ESX.Game.Teleport(entity, coords, cb)
local vector = type(coords) == "vector4" and coords or type(coords) == "vector3" and vector4(coords, 0.0) or vec(coords.x, coords.y, coords.z, coords.heading or 0.0)
if DoesEntityExist(entity) then
@@ -365,7 +365,7 @@ ESX.Game.Teleport = function(entity, coords, cb)
end
end
ESX.Game.SpawnObject = function(object, coords, cb, networked)
function ESX.Game.SpawnObject(object, coords, cb, networked)
local model = type(object) == 'number' and object or GetHashKey(object)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
networked = networked == nil and true or networked
@@ -380,21 +380,21 @@ ESX.Game.SpawnObject = function(object, coords, cb, networked)
end)
end
ESX.Game.SpawnLocalObject = function(object, coords, cb)
function ESX.Game.SpawnLocalObject(object, coords, cb)
ESX.Game.SpawnObject(object, coords, cb, false)
end
ESX.Game.DeleteVehicle = function(vehicle)
function ESX.Game.DeleteVehicle(vehicle)
SetEntityAsMissionEntity(vehicle, false, true)
DeleteVehicle(vehicle)
end
ESX.Game.DeleteObject = function(object)
function ESX.Game.DeleteObject(object)
SetEntityAsMissionEntity(object, false, true)
DeleteObject(object)
end
ESX.Game.SpawnVehicle = function(vehicle, coords, heading, cb, networked)
function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
networked = networked == nil and true or networked
@@ -424,22 +424,22 @@ ESX.Game.SpawnVehicle = function(vehicle, coords, heading, cb, networked)
end)
end
ESX.Game.SpawnLocalVehicle = function(vehicle, coords, heading, cb)
function ESX.Game.SpawnLocalVehicle(vehicle, coords, heading, cb)
ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, false)
end
ESX.Game.IsVehicleEmpty = function(vehicle)
function ESX.Game.IsVehicleEmpty(vehicle)
local passengers = GetVehicleNumberOfPassengers(vehicle)
local driverSeatFree = IsVehicleSeatFree(vehicle, -1)
return passengers == 0 and driverSeatFree
end
ESX.Game.GetObjects = function() -- Leave the function for compatibility
function ESX.Game.GetObjects() -- Leave the function for compatibility
return GetGamePool('CObject')
end
ESX.Game.GetPeds = function(onlyOtherPeds)
function ESX.Game.GetPeds(onlyOtherPeds)
local peds, myPed, pool = {}, ESX.PlayerData.ped, GetGamePool('CPed')
for i=1, #pool do
@@ -451,11 +451,11 @@ ESX.Game.GetPeds = function(onlyOtherPeds)
return peds
end
ESX.Game.GetVehicles = function() -- Leave the function for compatibility
function ESX.Game.GetVehicles() -- Leave the function for compatibility
return GetGamePool('CVehicle')
end
ESX.Game.GetPlayers = function(onlyOtherPlayers, returnKeyValue, returnPeds)
function ESX.Game.GetPlayers(onlyOtherPlayers, returnKeyValue, returnPeds)
local players, myPlayer = {}, PlayerId()
for k,player in ipairs(GetActivePlayers()) do
@@ -473,36 +473,57 @@ ESX.Game.GetPlayers = function(onlyOtherPlayers, returnKeyValue, returnPeds)
return players
end
ESX.Game.GetClosestObject = function(coords, modelFilter)
function ESX.Game.GetClosestObject(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetObjects(), false, coords, modelFilter)
end
ESX.Game.GetClosestPed = function(coords, modelFilter)
function ESX.Game.GetClosestPed(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetPeds(true), false, coords, modelFilter)
end
ESX.Game.GetClosestPlayer = function(coords)
function ESX.Game.GetClosestPlayer(coords)
return ESX.Game.GetClosestEntity(ESX.Game.GetPlayers(true, true), true, coords, nil)
end
ESX.Game.GetClosestVehicle = function(coords, modelFilter)
function ESX.Game.GetClosestVehicle(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetVehicles(), false, coords, modelFilter)
end
ESX.Game.GetPlayersInArea = function(coords, maxDistance)
local function EnumerateEntitiesWithinDistance(entities, isPlayerEntities, coords, maxDistance)
local nearbyEntities = {}
if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
local playerPed = ESX.PlayerData.ped
coords = GetEntityCoords(playerPed)
end
for k,entity in pairs(entities) do
local distance = #(coords - GetEntityCoords(entity))
if distance <= maxDistance then
table.insert(nearbyEntities, isPlayerEntities and k or entity)
end
end
return nearbyEntities
end
function ESX.Game.GetPlayersInArea(coords, maxDistance)
return EnumerateEntitiesWithinDistance(ESX.Game.GetPlayers(true, true), true, coords, maxDistance)
end
ESX.Game.GetVehiclesInArea = function(coords, maxDistance)
function ESX.Game.GetVehiclesInArea(coords, maxDistance)
return EnumerateEntitiesWithinDistance(ESX.Game.GetVehicles(), false, coords, maxDistance)
end
ESX.Game.IsSpawnPointClear = function(coords, maxDistance)
function ESX.Game.IsSpawnPointClear(coords, maxDistance)
return #ESX.Game.GetVehiclesInArea(coords, maxDistance) == 0
end
ESX.Game.GetClosestEntity = function(entities, isPlayerEntities, coords, modelFilter)
function ESX.Game.GetClosestEntity(entities, isPlayerEntities, coords, modelFilter)
local closestEntity, closestEntityDistance, filteredEntities = -1, -1, nil
if coords then
@@ -533,7 +554,7 @@ ESX.Game.GetClosestEntity = function(entities, isPlayerEntities, coords, modelFi
return closestEntity, closestEntityDistance
end
ESX.Game.GetVehicleInDirection = function()
function ESX.Game.GetVehicleInDirection()
local playerPed = ESX.PlayerData.ped
local playerCoords = GetEntityCoords(playerPed)
local inDirection = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 5.0, 0.0)
@@ -548,7 +569,7 @@ ESX.Game.GetVehicleInDirection = function()
return nil
end
ESX.Game.GetVehicleProperties = function(vehicle)
function ESX.Game.GetVehicleProperties(vehicle)
if DoesEntityExist(vehicle) then
local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
@@ -649,7 +670,7 @@ ESX.Game.GetVehicleProperties = function(vehicle)
end
end
ESX.Game.SetVehicleProperties = function(vehicle, props)
function ESX.Game.SetVehicleProperties(vehicle, props)
if DoesEntityExist(vehicle) then
local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
@@ -741,7 +762,7 @@ ESX.Game.SetVehicleProperties = function(vehicle, props)
end
end
ESX.Game.Utils.DrawText3D = function(coords, text, size, font)
function ESX.Game.Utils.DrawText3D(coords, text, size, font)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
local camCoords = GetFinalRenderedCamCoord()
@@ -766,7 +787,7 @@ ESX.Game.Utils.DrawText3D = function(coords, text, size, font)
ClearDrawOrigin()
end
ESX.ShowInventory = function()
function ESX.ShowInventory()
local playerPed = ESX.PlayerData.ped
local elements, currentWeight = {}, 0
@@ -1,4 +1,4 @@
ESX.Scaleform.ShowFreemodeMessage = function(title, msg, sec)
function ESX.Scaleform.ShowFreemodeMessage(title, msg, sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('MP_BIG_MESSAGE_FREEMODE')
BeginScaleformMovieMethod(scaleform, 'SHOW_SHARD_WASTED_MP_MESSAGE')
@@ -16,7 +16,7 @@ ESX.Scaleform.ShowFreemodeMessage = function(title, msg, sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
ESX.Scaleform.ShowBreakingNews = function(title, msg, bottom, sec)
function ESX.Scaleform.ShowBreakingNews(title, msg, bottom, sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('BREAKING_NEWS')
BeginScaleformMovieMethod(scaleform, 'SET_TEXT')
@@ -47,7 +47,7 @@ ESX.Scaleform.ShowBreakingNews = function(title, msg, bottom, sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
ESX.Scaleform.ShowPopupWarning = function(title, msg, bottom, sec)
function ESX.Scaleform.ShowPopupWarning(title, msg, bottom, sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('POPUP_WARNING')
BeginScaleformMovieMethod(scaleform, 'SHOW_POPUP_WARNING')
@@ -70,7 +70,7 @@ ESX.Scaleform.ShowPopupWarning = function(title, msg, bottom, sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
ESX.Scaleform.ShowTrafficMovie = function(sec)
function ESX.Scaleform.ShowTrafficMovie(sec)
local scaleform = ESX.Scaleform.Utils.RequestScaleformMovie('TRAFFIC_CAM')
BeginScaleformMovieMethod(scaleform, 'PLAY_CAM_MOVIE')
@@ -87,7 +87,7 @@ ESX.Scaleform.ShowTrafficMovie = function(sec)
SetScaleformMovieAsNoLongerNeeded(scaleform)
end
ESX.Scaleform.Utils.RequestScaleformMovie = function(movie)
function ESX.Scaleform.Utils.RequestScaleformMovie(movie)
local scaleform = RequestScaleformMovie(movie)
while not HasScaleformMovieLoaded(scaleform) do
+9 -9
View File
@@ -4,7 +4,7 @@ for i = 48, 57 do table.insert(Charset, string.char(i)) end
for i = 65, 90 do table.insert(Charset, string.char(i)) end
for i = 97, 122 do table.insert(Charset, string.char(i)) end
ESX.GetRandomString = function(length)
function ESX.GetRandomString(length)
math.randomseed(GetGameTimer())
if length > 0 then
@@ -14,11 +14,11 @@ ESX.GetRandomString = function(length)
end
end
ESX.GetConfig = function()
function ESX.GetConfig()
return Config
end
ESX.GetWeapon = function(weaponName)
function ESX.GetWeapon(weaponName)
weaponName = string.upper(weaponName)
for k,v in ipairs(Config.Weapons) do
@@ -28,7 +28,7 @@ ESX.GetWeapon = function(weaponName)
end
end
ESX.GetWeaponFromHash = function(weaponHash)
function ESX.GetWeaponFromHash(weaponHash)
for k,v in ipairs(Config.Weapons) do
if GetHashKey(v.name) == weaponHash then
return v
@@ -36,11 +36,11 @@ ESX.GetWeaponFromHash = function(weaponHash)
end
end
ESX.GetWeaponList = function()
function ESX.GetWeaponList()
return Config.Weapons
end
ESX.GetWeaponLabel = function(weaponName)
function ESX.GetWeaponLabel(weaponName)
weaponName = string.upper(weaponName)
for k,v in ipairs(Config.Weapons) do
@@ -50,7 +50,7 @@ ESX.GetWeaponLabel = function(weaponName)
end
end
ESX.GetWeaponComponent = function(weaponName, weaponComponent)
function ESX.GetWeaponComponent(weaponName, weaponComponent)
weaponName = string.upper(weaponName)
local weapons = Config.Weapons
@@ -65,7 +65,7 @@ ESX.GetWeaponComponent = function(weaponName, weaponComponent)
end
end
ESX.DumpTable = function(table, nb)
function ESX.DumpTable(table, nb)
if nb == nil then
nb = 0
end
@@ -95,6 +95,6 @@ ESX.DumpTable = function(table, nb)
end
end
ESX.Round = function(value, numDecimalPlaces)
function ESX.Round(value, numDecimalPlaces)
return ESX.Math.Round(value, numDecimalPlaces)
end
+3 -3
View File
@@ -1,6 +1,6 @@
ESX.Math = {}
ESX.Math.Round = function(value, numDecimalPlaces)
function ESX.Math.Round(value, numDecimalPlaces)
if numDecimalPlaces then
local power = 10^numDecimalPlaces
return math.floor((value * power) + 0.5) / (power)
@@ -10,13 +10,13 @@ ESX.Math.Round = function(value, numDecimalPlaces)
end
-- credit http://richard.warburton.it
ESX.Math.GroupDigits = function(value)
function ESX.Math.GroupDigits(value)
local left,num,right = string.match(value,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1' .. _U('locale_digit_grouping_symbol')):reverse())..right
end
ESX.Math.Trim = function(value)
function ESX.Math.Trim(value)
if value then
return (string.gsub(value, "^%s*(.-)%s*$", "%1"))
else
-1
View File
@@ -31,7 +31,6 @@ server_scripts {
client_scripts {
'client/common.lua',
'client/entityiter.lua',
'client/functions.lua',
'client/wrapper.lua',
'client/main.lua',
+48 -52
View File
@@ -18,20 +18,20 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group))
self.triggerEvent = function(eventName, ...)
function self.triggerEvent(eventName, ...)
TriggerClientEvent(eventName, self.source, ...)
end
self.setCoords = function(coords)
function self.setCoords(coords)
self.updateCoords(coords)
self.triggerEvent('esx:teleport', coords)
end
self.updateCoords = function(coords)
function self.updateCoords(coords)
self.coords = {x = ESX.Math.Round(coords.x, 1), y = ESX.Math.Round(coords.y, 1), z = ESX.Math.Round(coords.z, 1), heading = ESX.Math.Round(coords.heading or 0.0, 1)}
end
self.getCoords = function(vector)
function self.getCoords(vector)
if vector then
return vector3(self.coords.x, self.coords.y, self.coords.z)
else
@@ -39,52 +39,52 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.kick = function(reason)
function self.kick(reason)
DropPlayer(self.source, reason)
end
self.setMoney = function(money)
function self.setMoney(money)
money = ESX.Math.Round(money)
self.setAccountMoney('money', money)
end
self.getMoney = function()
function self.getMoney()
return self.getAccount('money').money
end
self.addMoney = function(money)
function self.addMoney(money)
money = ESX.Math.Round(money)
self.addAccountMoney('money', money)
end
self.removeMoney = function(money)
function self.removeMoney(money)
money = ESX.Math.Round(money)
self.removeAccountMoney('money', money)
end
self.getIdentifier = function()
function self.getIdentifier()
return self.identifier
end
self.setGroup = function(newGroup)
function self.setGroup(newGroup)
ExecuteCommand(('remove_principal identifier.%s group.%s'):format(self.license, self.group))
self.group = newGroup
ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group))
end
self.getGroup = function()
function self.getGroup()
return self.group
end
self.set = function(k, v)
function self.set(k, v)
self.variables[k] = v
end
self.get = function(k)
function self.get(k)
return self.variables[k]
end
self.getAccounts = function(minimal)
function self.getAccounts(minimal)
if minimal then
local minimalAccounts = {}
@@ -98,7 +98,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getAccount = function(account)
function self.getAccount(account)
for k,v in ipairs(self.accounts) do
if v.name == account then
return v
@@ -106,7 +106,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getInventory = function(minimal)
function self.getInventory(minimal)
if minimal then
local minimalInventory = {}
@@ -122,11 +122,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getJob = function()
function self.getJob()
return self.job
end
self.getLoadout = function(minimal)
function self.getLoadout(minimal)
if minimal then
local minimalLoadout = {}
@@ -155,15 +155,15 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getName = function()
function self.getName()
return self.name
end
self.setName = function(newName)
function self.setName(newName)
self.name = newName
end
self.setAccountMoney = function(accountName, money)
function self.setAccountMoney(accountName, money)
if money >= 0 then
local account = self.getAccount(accountName)
@@ -177,7 +177,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.addAccountMoney = function(accountName, money)
function self.addAccountMoney(accountName, money)
if money > 0 then
local account = self.getAccount(accountName)
@@ -190,7 +190,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.removeAccountMoney = function(accountName, money)
function self.removeAccountMoney(accountName, money)
if money > 0 then
local account = self.getAccount(accountName)
@@ -203,17 +203,15 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getInventoryItem = function(name)
function self.getInventoryItem(name)
for k,v in ipairs(self.inventory) do
if v.name == name then
return v
end
end
return
end
self.addInventoryItem = function(name, count)
function self.addInventoryItem(name, count)
local item = self.getInventoryItem(name)
if item then
@@ -226,7 +224,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.removeInventoryItem = function(name, count)
function self.removeInventoryItem(name, count)
local item = self.getInventoryItem(name)
if item then
@@ -243,7 +241,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.setInventoryItem = function(name, count)
function self.setInventoryItem(name, count)
local item = self.getInventoryItem(name)
if item and count >= 0 then
@@ -257,22 +255,22 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getWeight = function()
function self.getWeight()
return self.weight
end
self.getMaxWeight = function()
function self.getMaxWeight()
return self.maxWeight
end
self.canCarryItem = function(name, count)
function self.canCarryItem(name, count)
local currentWeight, itemWeight = self.weight, ESX.Items[name].weight
local newWeight = currentWeight + (itemWeight * count)
return newWeight <= self.maxWeight
end
self.canSwapItem = function(firstItem, firstItemCount, testItem, testItemCount)
function self.canSwapItem(firstItem, firstItemCount, testItem, testItemCount)
local firstItemObject = self.getInventoryItem(firstItem)
local testItemObject = self.getInventoryItem(testItem)
@@ -286,12 +284,12 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return false
end
self.setMaxWeight = function(newWeight)
function self.setMaxWeight(newWeight)
self.maxWeight = newWeight
self.triggerEvent('esx:setMaxWeight', self.maxWeight)
end
self.setJob = function(job, grade)
function self.setJob(job, grade)
grade = tostring(grade)
local lastJob = json.decode(json.encode(self.job))
@@ -326,7 +324,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.addWeapon = function(weaponName, ammo)
function self.addWeapon(weaponName, ammo)
if not self.hasWeapon(weaponName) then
local weaponLabel = ESX.GetWeaponLabel(weaponName)
@@ -343,7 +341,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.addWeaponComponent = function(weaponName, weaponComponent)
function self.addWeaponComponent(weaponName, weaponComponent)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -359,7 +357,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.addWeaponAmmo = function(weaponName, ammoCount)
function self.addWeaponAmmo(weaponName, ammoCount)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -368,7 +366,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.updateWeaponAmmo = function(weaponName, ammoCount)
function self.updateWeaponAmmo(weaponName, ammoCount)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -378,7 +376,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.setWeaponTint = function(weaponName, weaponTintIndex)
function self.setWeaponTint(weaponName, weaponTintIndex)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -392,7 +390,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.getWeaponTint = function(weaponName)
function self.getWeaponTint(weaponName)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -402,7 +400,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return 0
end
self.removeWeapon = function(weaponName)
function self.removeWeapon(weaponName)
local weaponLabel
for k,v in ipairs(self.loadout) do
@@ -424,7 +422,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.removeWeaponComponent = function(weaponName, weaponComponent)
function self.removeWeaponComponent(weaponName, weaponComponent)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -446,7 +444,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.removeWeaponAmmo = function(weaponName, ammoCount)
function self.removeWeaponAmmo(weaponName, ammoCount)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -455,7 +453,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.hasWeaponComponent = function(weaponName, weaponComponent)
function self.hasWeaponComponent(weaponName, weaponComponent)
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
@@ -471,7 +469,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end
end
self.hasWeapon = function(weaponName)
function self.hasWeapon(weaponName)
for k,v in ipairs(self.loadout) do
if v.name == weaponName then
return true
@@ -481,21 +479,19 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return false
end
self.getWeapon = function(weaponName)
function self.getWeapon(weaponName)
for k,v in ipairs(self.loadout) do
if v.name == weaponName then
return k, v
end
end
return
end
self.showNotification = function(msg)
function self.showNotification(msg)
self.triggerEvent('esx:showNotification', msg)
end
self.showHelpNotification = function(msg, thisFrame, beep, duration)
function self.showHelpNotification(msg, thisFrame, beep, duration)
self.triggerEvent('esx:showHelpNotification', msg, thisFrame, beep, duration)
end
+21 -21
View File
@@ -1,10 +1,10 @@
ESX.Trace = function(msg)
function ESX.Trace(msg)
if Config.EnableDebug then
print(('[^2TRACE^7] %s^7'):format(msg))
end
end
ESX.SetTimeout = function(msec, cb)
function ESX.SetTimeout(msec, cb)
local id = Core.TimeoutCount + 1
SetTimeout(msec, function()
@@ -20,7 +20,7 @@ ESX.SetTimeout = function(msec, cb)
return id
end
ESX.RegisterCommand = function(name, group, cb, allowConsole, suggestion)
function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
if type(name) == 'table' then
for k,v in ipairs(name) do
ESX.RegisterCommand(v, group, cb, allowConsole, suggestion)
@@ -147,15 +147,15 @@ ESX.RegisterCommand = function(name, group, cb, allowConsole, suggestion)
end
end
ESX.ClearTimeout = function(id)
function ESX.ClearTimeout(id)
Core.CancelledTimeouts[id] = true
end
ESX.RegisterServerCallback = function(name, cb)
function ESX.RegisterServerCallback(name, cb)
Core.ServerCallbacks[name] = cb
end
ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
function ESX.TriggerServerCallback(name, requestId, source, cb, ...)
if Core.ServerCallbacks[name] then
Core.ServerCallbacks[name](source, cb, ...)
else
@@ -163,7 +163,7 @@ ESX.TriggerServerCallback = function(name, requestId, source, cb, ...)
end
end
Core.SavePlayer = function(xPlayer, cb)
function Core.SavePlayer(xPlayer, cb)
MySQL.prepare('UPDATE `users` SET `accounts` = ?, `job` = ?, `job_grade` = ?, `group` = ?, `position` = ?, `inventory` = ?, `loadout` = ? WHERE `identifier` = ?', {
json.encode(xPlayer.getAccounts(true)),
xPlayer.job.name,
@@ -181,7 +181,7 @@ Core.SavePlayer = function(xPlayer, cb)
end)
end
Core.SavePlayers = function(cb)
function Core.SavePlayers(cb)
local xPlayers = ESX.GetExtendedPlayers()
local count = #xPlayers
if count > 0 then
@@ -209,7 +209,7 @@ Core.SavePlayers = function(cb)
end
end
ESX.GetPlayers = function()
function ESX.GetPlayers()
local sources = {}
for k,v in pairs(ESX.Players) do
@@ -219,7 +219,7 @@ ESX.GetPlayers = function()
return sources
end
ESX.GetExtendedPlayers = function(key, val)
function ESX.GetExtendedPlayers(key, val)
local xPlayers = {}
for k, v in pairs(ESX.Players) do
if key then
@@ -233,11 +233,11 @@ ESX.GetExtendedPlayers = function(key, val)
return xPlayers
end
ESX.GetPlayerFromId = function(source)
function ESX.GetPlayerFromId(source)
return ESX.Players[tonumber(source)]
end
ESX.GetPlayerFromIdentifier = function(identifier)
function ESX.GetPlayerFromIdentifier(identifier)
for k,v in pairs(ESX.Players) do
if v.identifier == identifier then
return v
@@ -245,7 +245,7 @@ ESX.GetPlayerFromIdentifier = function(identifier)
end
end
ESX.GetIdentifier = function(playerId)
function ESX.GetIdentifier(playerId)
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
if string.match(v, 'license:') then
local identifier = string.gsub(v, 'license:', '')
@@ -254,25 +254,25 @@ ESX.GetIdentifier = function(playerId)
end
end
ESX.RegisterUsableItem = function(item, cb)
function ESX.RegisterUsableItem(item, cb)
Core.UsableItemsCallbacks[item] = cb
end
ESX.UseItem = function(source, item)
function ESX.UseItem(source, item)
Core.UsableItemsCallbacks[item](source, item)
end
ESX.GetItemLabel = function(item)
function ESX.GetItemLabel(item)
if ESX.Items[item] then
return ESX.Items[item].label
end
end
ESX.GetJobs = function()
function ESX.GetJobs()
return ESX.Jobs
end
ESX.GetUsableItems = function()
function ESX.GetUsableItems()
local Usables = {}
for k in pairs(Core.UsableItemsCallbacks) do
Usables[k] = true
@@ -280,7 +280,7 @@ ESX.GetUsableItems = function()
return Usables
end
ESX.CreatePickup = function(type, name, count, label, playerId, components, tintIndex)
function ESX.CreatePickup(type, name, count, label, playerId, components, tintIndex)
local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1)
local xPlayer = ESX.GetPlayerFromId(playerId)
local coords = xPlayer.getCoords()
@@ -300,7 +300,7 @@ ESX.CreatePickup = function(type, name, count, label, playerId, components, tint
Core.PickupId = pickupId
end
ESX.DoesJobExist = function(job, grade)
function ESX.DoesJobExist(job, grade)
grade = tostring(grade)
if job and grade then
@@ -312,7 +312,7 @@ ESX.DoesJobExist = function(job, grade)
return false
end
Core.IsPlayerAdmin = function(playerId)
function Core.IsPlayerAdmin(playerId)
if (IsPlayerAceAllowed(playerId, 'command') or GetConvar('sv_lan', '') == 'true') and true or false then
return true
end
+1 -1
View File
@@ -1,4 +1,4 @@
StartPayCheck = function()
function StartPayCheck()
CreateThread(function()
while true do
Wait(Config.PaycheckInterval)
+2 -2
View File
@@ -1,7 +1,7 @@
local GUI, MenuType = {}, 'default'
GUI.Time = 0
local openMenu = function(namespace, name, data)
local function openMenu(namespace, name, data)
SendNUIMessage({
action = 'openMenu',
namespace = namespace,
@@ -10,7 +10,7 @@ local openMenu = function(namespace, name, data)
})
end
local closeMenu = function(namespace, name)
local function closeMenu(namespace, name)
SendNUIMessage({
action = 'closeMenu',
namespace = namespace,
+2 -2
View File
@@ -1,6 +1,6 @@
local Timeouts, OpenedMenus, MenuType = {}, {}, 'dialog'
local openMenu = function(namespace, name, data)
local function openMenu(namespace, name, data)
for i=1, #Timeouts, 1 do
ESX.ClearTimeout(Timeouts[i])
end
@@ -21,7 +21,7 @@ local openMenu = function(namespace, name, data)
table.insert(Timeouts, timeoutId)
end
local closeMenu = function(namespace, name)
local function closeMenu(namespace, name)
OpenedMenus[namespace .. '_' .. name] = nil
SendNUIMessage({
+2 -2
View File
@@ -2,7 +2,7 @@ CreateThread(function()
local MenuType = 'list'
local OpenedMenus = {}
local openMenu = function(namespace, name, data)
local function openMenu(namespace, name, data)
OpenedMenus[namespace .. '_' .. name] = true
@@ -19,7 +19,7 @@ CreateThread(function()
end
local closeMenu = function(namespace, name)
local function closeMenu(namespace, name)
OpenedMenus[namespace .. '_' .. name] = nil
local OpenedMenuCount = 0
@@ -5,22 +5,22 @@ function CreateAddonAccount(name, owner, money)
self.owner = owner
self.money = money
self.addMoney = function(m)
function self.addMoney(m)
self.money = self.money + m
self.save()
end
self.removeMoney = function(m)
function self.removeMoney(m)
self.money = self.money - m
self.save()
end
self.setMoney = function(m)
function self.setMoney(m)
self.money = m
self.save()
end
self.save = function()
function self.save()
if self.owner == nil then
MySQL.update('UPDATE addon_account_data SET money = ? WHERE account_name = ?', {self.money, self.name})
else
@@ -5,28 +5,28 @@ function CreateAddonInventory(name, owner, items)
self.owner = owner
self.items = items
self.addItem = function(name, count)
function self.addItem(name, count)
local item = self.getItem(name)
item.count = item.count + count
Wait(100)
self.saveItem(name, item.count)
end
self.removeItem = function(name, count)
function self.removeItem(name, count)
local item = self.getItem(name)
item.count = item.count - count
self.saveItem(name, item.count)
end
self.setItem = function(name, count)
function self.setItem(name, count)
local item = self.getItem(name)
item.count = count
self.saveItem(name, item.count)
end
self.getItem = function(name)
function self.getItem(name)
for i=1, #self.items, 1 do
if self.items[i].name == name then
return self.items[i]
@@ -61,7 +61,7 @@ function CreateAddonInventory(name, owner, items)
return item
end
self.saveItem = function(name, count)
function self.saveItem(name, count)
if self.owner == nil then
MySQL.update('UPDATE addon_inventory_items SET count = @count WHERE inventory_name = @inventory_name AND name = @item_name', {
['@inventory_name'] = self.name,
+1 -1
View File
@@ -78,7 +78,7 @@ function CalculateBankSavings(d, h, m)
local newMoney = result[i].money + interests
bankInterests = bankInterests + interests
local scope = function(newMoney, owner)
local function scope(newMoney, owner)
table.insert(asyncTasks, function(cb)
MySQL.update('UPDATE addon_account_data SET money = @money WHERE owner = @owner AND account_name = @account_name', {
['@money'] = newMoney,
@@ -21,12 +21,12 @@ function CreateDataStore(name, owner, data)
local timeoutCallbacks = {}
self.set = function(key, val)
function self.set(key, val)
data[key] = val
self.save()
end
self.get = function(key, i)
function self.get(key, i)
local path = stringsplit(key, '.')
local obj = self.data
@@ -41,7 +41,7 @@ function CreateDataStore(name, owner, data)
end
end
self.count = function(key, i)
function self.count(key, i)
local path = stringsplit(key, '.')
local obj = self.data
@@ -60,7 +60,7 @@ function CreateDataStore(name, owner, data)
end
end
self.save = function()
function self.save()
for i=1, #timeoutCallbacks, 1 do
ESX.ClearTimeout(timeoutCallbacks[i])
timeoutCallbacks[i] = nil
+3 -3
View File
@@ -59,7 +59,7 @@ AddEventHandler('esx_garage:hasEnteredMarker', function(name, part, parking)
for j=1, #vehicles, 1 do
if i == vehicles[j].zone then
local spawn = function(j)
local function spawn(j)
local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71)
@@ -97,7 +97,7 @@ AddEventHandler('esx_garage:hasEnteredMarker', function(name, part, parking)
for j=1, #vehicles, 1 do
if i == vehicles[j].zone then
local spawn = function(j)
local function spawn(j)
local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71)
@@ -138,7 +138,7 @@ AddEventHandler('esx_garage:hasEnteredMarker', function(name, part, parking)
for j=1, #vehicles, 1 do
if i == vehicles[j].zone then
local spawn = function(j)
local function spawn(j)
local vehicle = GetClosestVehicle(garage.Parkings[i].Pos.x, garage.Parkings[i].Pos.y, garage.Parkings[i].Pos.z, 2.0, 0, 71)
@@ -9,23 +9,23 @@ function CreateStatus(name, default, color, visible, tickCallback)
self.visible = visible
self.tickCallback = tickCallback
self._set = function(k, v)
function self._set(k, v)
self[k] = v
end
self._get = function(k)
function self._get(k)
return self[k]
end
self.onTick = function()
function self.onTick()
self.tickCallback(self)
end
self.set = function(val)
function self.set(val)
self.val = val
end
self.add = function(val)
function self.add(val)
if self.val + val > Config.StatusMax then
self.val = Config.StatusMax
else
@@ -33,7 +33,7 @@ function CreateStatus(name, default, color, visible, tickCallback)
end
end
self.remove = function(val)
function self.remove(val)
if self.val - val < 0 then
self.val = 0
else
@@ -41,7 +41,7 @@ function CreateStatus(name, default, color, visible, tickCallback)
end
end
self.getPercent = function()
function self.getPercent()
return (self.val / Config.StatusMax) * 100
end
@@ -11,23 +11,23 @@ function CreateStatus(xPlayer, name, default, color, visible, tickCallback, clie
self.tickCallback = tickCallback
self.clientAction = clientAction
self._set = function(k, v)
function self._set(k, v)
self[k] = v
end
self._get = function(k)
function self._get(k)
return self[k]
end
self.onTick = function()
function self.onTick()
self.tickCallback(self)
end
self.set = function(val)
function self.set(val)
self.val = val
end
self.add = function(val)
function self.add(val)
if self.val + val > Config.StatusMax then
self.val = Config.StatusMax
else
@@ -35,7 +35,7 @@ function CreateStatus(xPlayer, name, default, color, visible, tickCallback, clie
end
end
self.remove = function(val)
function self.remove(val)
if self.val - val < 0 then
self.val = 0
else
@@ -43,11 +43,11 @@ function CreateStatus(xPlayer, name, default, color, visible, tickCallback, clie
end
end
self.getPercent = function()
function self.getPercent()
return (self.val / Config.StatusMax) * 100
end
self.updateClient = function()
function self.updateClient()
TriggerEvent('esx_status:updateClient', self.xPlayer.source)
end
+1 -1
View File
@@ -608,7 +608,7 @@ CreateThread(function()
TriggerServerEvent('esx_taxijob:success')
RemoveBlip(DestinationBlip)
local scope = function(customer)
local function scope(customer)
ESX.SetTimeout(60000, function()
DeletePed(customer)
end)
+1 -1
View File
@@ -20,7 +20,7 @@ AddEventHandler('esx:setJob', function(job)
ESX.PlayerData.job = job
end)
OnPlayerData = function(key, val, last)
function OnPlayerData(key, val, last)
if type(val) == 'table' then val = json.encode(val) end
print('PlayerData.'..key..' was set to '..val)
if key == 'job' then