Merge pull request #10 from thelindat/main

fixes: Fix major issue with ESX client function, minor fixes for ESX and status
This commit is contained in:
ESXCrackhead
2021-07-13 16:15:26 -05:00
committed by GitHub
11 changed files with 205 additions and 107 deletions
+3 -5
View File
@@ -1,4 +1,4 @@
<h1 align='center'>ESX Legacy</a></h1><p align='center'><b><a href='https://discord.gg/cNx6HF9P5J'>Development Discord</a> - <a href='https://esx-framework.org/esx'>Website</a> - <a href='https://discord.gg/J6VqFPwvVp'>Support Discord</a></b></h5>
<h1 align='center'>ESX Legacy</a></h1><p align='center'><b><a href='https://discord.gg/cNx6HF9P5J'>Development Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://discord.gg/J6VqFPwvVp'>Support Discord</a></b></h5>
##### ESX is the most popular framework for creating economy-based roleplay servers on FiveM, with many official and community resources designed to utilise the tools provided here. For a taste of what's available:
@@ -10,7 +10,7 @@
> esx_vehicleshop: Allow players to purchase vehicles from a dealership, or setup society support for a player-managed dealership
> esx_ambulancejop: Adds a death and respawn system while allowing players to work as EMS to heal and revive others
> esx_ambulancejob: Adds a death and respawn system while allowing players to work as EMS to heal and revive others
Many more resources are included in this repository, or you can browse the [ESX Community Github](https://github.com/esx-community/) or [Cfx.re Releases board](https://forum.cfx.re/tag/esx) for more.
@@ -83,9 +83,7 @@ Many more resources are included in this repository, or you can browse the [ESX
### Information
ESX was initially developed by Gizz back in 2017 for his friend as the were creating an FiveM server and there wasn't any economy roleplaying frameworks available. The original code was written within a week or two and later open sourced, it has ever since been improved and parts been rewritten to further improve on it.
- [ESX Forum](https://forum.esx-framework.org/)
- [ESX Documentation](https://wiki.esx-framework.org/)
- [ESX Development Discord](https://discord.me/esx)
- [ESX Documentation](https://esx-framework.github.io/es_extended/)
- [FiveM Native Reference](https://runtime.fivem.net/doc/reference.html)
+3 -5
View File
@@ -1,4 +1,4 @@
<h1 align='center'>ESX Legacy</a></h1><p align='center'><b><a href='https://discord.gg/cNx6HF9P5J'>Development Discord</a> - <a href='https://esx-framework.org/esx'>Website</a> - <a href='https://discord.gg/J6VqFPwvVp'>Support Discord</a></b></h5>
<h1 align='center'>ESX Legacy</a></h1><p align='center'><b><a href='https://discord.gg/cNx6HF9P5J'>Development Discord</a> - <a href='https://esx-framework.org/'>Website</a> - <a href='https://discord.gg/J6VqFPwvVp'>Support Discord</a></b></h5>
##### ESX is the most popular framework for creating economy-based roleplay servers on FiveM, with many official and community resources designed to utilise the tools provided here. For a taste of what's available:
@@ -10,7 +10,7 @@
> esx_vehicleshop: Allow players to purchase vehicles from a dealership, or setup society support for a player-managed dealership
> esx_ambulancejop: Adds a death and respawn system while allowing players to work as EMS to heal and revive others
> esx_ambulancejob: Adds a death and respawn system while allowing players to work as EMS to heal and revive others
Many more resources are included in this repository, or you can browse the [ESX Community Github](https://github.com/esx-community/) or [Cfx.re Releases board](https://forum.cfx.re/tag/esx) for more.
@@ -83,9 +83,7 @@ Many more resources are included in this repository, or you can browse the [ESX
### Information
ESX was initially developed by Gizz back in 2017 for his friend as the were creating an FiveM server and there wasn't any economy roleplaying frameworks available. The original code was written within a week or two and later open sourced, it has ever since been improved and parts been rewritten to further improve on it.
- [ESX Forum](https://forum.esx-framework.org/)
- [ESX Documentation](https://wiki.esx-framework.org/)
- [ESX Development Discord](https://discord.me/esx)
- [ESX Documentation](https://esx-framework.github.io/es_extended/)
- [FiveM Native Reference](https://runtime.fivem.net/doc/reference.html)
+7 -11
View File
@@ -339,16 +339,13 @@ ESX.Game.Teleport = function(entity, coords, cb)
end
ESX.Game.SpawnObject = function(object, coords, cb, networked)
local model = (type(object) == 'number' and model or GetHashKey(object))
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
Citizen.CreateThread(function()
ESX.Streaming.RequestModel(model)
-- The below has to be done just for CreateObject since for some reason CreateObjects model argument is set
-- as an Object instead of a hash so it doesn't automatically hash the item
model = type(model) == 'number' and model or GetHashKey(model)
local obj = CreateObject(model, vector.xyz, networked, false, true)
if cb then
cb(obj)
@@ -357,7 +354,6 @@ ESX.Game.SpawnObject = function(object, coords, cb, networked)
end
ESX.Game.SpawnLocalObject = function(object, coords, cb)
-- Why have 2 separate functions for this? Just call the other one with an extra param
ESX.Game.SpawnObject(object, coords, cb, false)
end
@@ -417,13 +413,13 @@ ESX.Game.GetObjects = function() -- Leave the function for compatibility
end
ESX.Game.GetPeds = function(onlyOtherPeds)
local peds, myPed = {}, ESX.PlayerData.ped
local peds, myPed, pool = {}, ESX.PlayerData.ped, GetGamePool('CPed')
for ped in GetGamePool('CPed') do
if ((onlyOtherPeds and ped ~= myPed) or not onlyOtherPeds) then
table.insert(peds, ped)
end
end
for i=1, #pool do
if ((onlyOtherPeds and pool[i] ~= myPed) or not onlyOtherPeds) then
table.insert(peds, pool[i])
end
end
return peds
end
+9 -2
View File
@@ -18,6 +18,13 @@ function getSharedObject()
return ESX
end
local function StartDBSync()
Citizen.CreateThread(function()
Citizen.Wait(10 * 60 * 1000)
ESX.SavePlayers()
end)
end
MySQL.ready(function()
MySQL.Async.fetchAll('SELECT * FROM items', {}, function(result)
for k,v in ipairs(result) do
@@ -54,8 +61,8 @@ MySQL.ready(function()
end
ESX.Jobs = Jobs
print('[^2INFO^7] ESX ^5Legacy^0 initialized')
ESX.StartDBSync()
ESX.StartPayCheck()
StartDBSync()
StartPayCheck()
end)
end)
end)
-9
View File
@@ -239,15 +239,6 @@ ESX.SavePlayers = function(cb)
end
end
ESX.StartDBSync = function()
function saveData()
ESX.SavePlayers()
SetTimeout(10 * 60 * 1000, saveData)
end
SetTimeout(10 * 60 * 1000, saveData)
end
ESX.GetPlayers = function()
local sources = {}
+34 -38
View File
@@ -1,44 +1,40 @@
ESX.StartPayCheck = function()
function payCheck()
local xPlayers = ESX.GetPlayers()
StartPayCheck = function()
Citizen.CreateThread(function()
while true do
Citizen.Wait(Config.PaycheckInterval)
local xPlayers = ESX.GetExtendedPlayers()
for _, xPlayer in pairs(xPlayers) do
local job = xPlayer.job.grade_name
local salary = xPlayer.job.grade_salary
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
local job = xPlayer.job.grade_name
local salary = xPlayer.job.grade_salary
if salary > 0 then
if job == 'unemployed' then -- unemployed
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
elseif Config.EnableSocietyPayouts then -- possibly a society
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
if society ~= nil then -- verified society
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
if account.money >= salary then -- does the society money to pay its employees?
xPlayer.addAccountMoney('bank', salary)
account.removeMoney(salary)
if salary > 0 then
if job == 'unemployed' then -- unemployed
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_help', salary), 'CHAR_BANK_MAZE', 9)
elseif Config.EnableSocietyPayouts then -- possibly a society
TriggerEvent('esx_society:getSociety', xPlayer.job.name, function (society)
if society ~= nil then -- verified society
TriggerEvent('esx_addonaccount:getSharedAccount', society.account, function (account)
if account.money >= salary then -- does the society money to pay its employees?
xPlayer.addAccountMoney('bank', salary)
account.removeMoney(salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
else
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
end
end)
else -- not a society
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end)
else -- generic job
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
else
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), '', _U('company_nomoney'), 'CHAR_BANK_MAZE', 1)
end
end)
else -- not a society
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end)
else -- generic job
xPlayer.addAccountMoney('bank', salary)
TriggerClientEvent('esx:showAdvancedNotification', xPlayer.source, _U('bank'), _U('received_paycheck'), _U('received_salary', salary), 'CHAR_BANK_MAZE', 9)
end
end
end
end
SetTimeout(Config.PaycheckInterval, payCheck)
end
SetTimeout(Config.PaycheckInterval, payCheck)
end)
end
+9 -11
View File
@@ -74,11 +74,8 @@ end)
Citizen.CreateThread(function()
while(true) do
Citizen.Wait(10 * 60 * 1000)
SaveData()
end
end)
function SaveData()
@@ -101,17 +98,18 @@ function SaveData()
local xPlayers = ESX.GetExtendedPlayers()
for _, xPlayer in pairs(xPlayers) do
local status = ESX.Players[xPlayer.source]
local status = ESX.Players[xPlayer.source]
if status then
whenList = whenList .. string.format('when identifier = \'%s\' then \'%s\' ', xPlayer.identifier, json.encode(status))
whenList = whenList .. string.format('when identifier = \'%s\' then \'%s\' ', xPlayer.identifier, json.encode(status))
if firstItem == false then
whereList = whereList .. ', '
end
whereList = whereList .. string.format('\'%s\'', xPlayer.identifier)
if firstItem == false then
whereList = whereList .. ', '
firstItem = false
playerCount = playerCount + 1
end
whereList = whereList .. string.format('\'%s\'', xPlayer.identifier)
firstItem = false
playerCount = playerCount + 1
end
if playerCount > 0 then
+50 -3
View File
@@ -1,4 +1,51 @@
# fxserver-esx_boilerplate
FXServer ESX Boilerplate
### ESX Imports
##### Similar to importing the ESX locale functions or MySQL-Async, there is now an import for ESX
- Define `shared_script '@es_extended/imports.lua'` above all other scripts in your fxmanifest
- This will define the ESX object for both the client and server
##### The following event handler will also be created on the client
```lua
AddEventHandler('esx:setPlayerData', function(key, val)
if GetInvokingResource() == 'es_extended' then
ESX.PlayerData[key] = val
if OnPlayerData ~= nil then OnPlayerData(key, val) end
end
end)
```
- You will now receive updated ESX.PlayerData values whenever they change
- This does not include inventory or loadout data and it should still be retrieved with `ESX.GetPlayerData()`
- You can add your own functions to the import if you believe they will be useful in your resources
- You can trigger certain events or functions based on the key and value received (example in client.lua)
- The idea of this function is ensuring up-to-date values for `job, accounts, ped, and dead`
- You can set any data this way if you want to share it between resources
- Using `ESX.SetPlayerData('cuffed', true)` will create and set a new value that you can now reference anywhere
- If you are using OneSync you could set certain values to set a state bag (useful for other players to reference)
This a sample script for es_extended
### Replacement for ESX.GetPlayers()
##### Old resources would utilise the ESX.GetPlayers() function in a loop with ESX.GetPlayerFromId() to retrieve xPlayer data
- This can be referred to as an xPlayer loop, and has been the cause for server hitches in resources such as esx_society and esx_status
- It is commonly used in robbery scripts to get the active number of cops, or for determining the number of EMS in other places
##### This method is outdated and should be replaced if you are using ESX Legacy
```lua
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
if xPlayer.job.name == 'police' then
TriggerClientEvent('esx:showNotification', xPlayers[i], 'You are a cop!')
end
end
```
##### This new method retrieves all xPlayer data at once, reducing the number of function references being called
```lua
local xPlayers = ESX.GetExtendedPlayers() -- Returns all xPlayers
for _, xPlayer in pairs(xPlayers) do
if v.job.name == 'police' then
TriggerClientEvent('esx:showNotification', xPlayer.source, 'You are a cop!')
end
end
local xPlayers = ESX.GetExtendedPlayers('job', 'police') -- Returns xPlayers with the police job
for _, xPlayer in pairs(xPlayers) do
TriggerClientEvent('esx:showNotification', xPlayer.source, 'You are a cop!')
end
```
+31 -3
View File
@@ -10,8 +10,6 @@ AddEventHandler('esx:playerLogout', function(xPlayer, isNew)
ESX.PlayerData = {}
end)
-- These two functions can perform the same task
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
@@ -40,4 +38,34 @@ OnPlayerData = function(key, val, last)
end
end
end
-----------------------------------------------
-----------------------------------------------
RegisterCommand('closestobject', function()
local result = ESX.Game.GetClosestObject(GetEntityCoords(PlayerPedId()))
print(result)
end)
RegisterCommand('closestped', function()
local result = ESX.Game.GetClosestPed(GetEntityCoords(PlayerPedId()))
print(result)
end)
RegisterCommand('closestplayer', function()
local result = ESX.Game.GetClosestPlayer(GetEntityCoords(PlayerPedId()))
print(result)
end)
RegisterCommand('closestvehicle', function()
local result = ESX.Game.GetClosestVehicle(GetEntityCoords(PlayerPedId()))
print(result)
end)
RegisterCommand('areaplayer', function()
local result = ESX.Game.GetPlayersInArea(GetEntityCoords(PlayerPedId()), 20)
print(json.encode(result))
end)
RegisterCommand('areavehicle', function()
local result = ESX.Game.GetVehiclesInArea(GetEntityCoords(PlayerPedId()), 20)
print(json.encode(result))
end)
+14 -7
View File
@@ -1,3 +1,8 @@
Citizen.CreateThread(function()
Citizen.Wait(3000)
print('^1Do not run this resource in a live environment, it is solely intended for showcasing ESX functions^0')
end)
RegisterNetEvent('esx:playerLoaded') -- When a player loads in, we can store some basic information about them locally
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer, isNew)
ESX.Players[playerId] = xPlayer.job.name
@@ -16,17 +21,19 @@ AddEventHandler('onResourceStart', function(resourceName) -- The resource just r
if (GetCurrentResourceName() == resourceName) then -- Useful if we need to run functions or send events after a restart
local players = {}
for _, xPlayer in pairs(ESX.Players) do
players[playerId] = xPlayer.job.name
print( ('%s %s is online with player id %s'):format(xPlayer.job.grade_label, xPlayer.name, playerId) )
players[xPlayer.source] = xPlayer.job.name
print( ('%s %s is online with player id %s'):format(xPlayer.job.grade_label, xPlayer.name, xPlayer.source) )
end
ESX.Players = players -- Replace the data as it is a waste of memory
end
end)
Citizen.CreateThread(function()
Citizen.Wait(1000)
local xPlayers = ESX.GetExtendedPlayers('job', 'police') -- New hitchless xPlayer loop, with the ability to only return players with specific data
for _, xPlayer in pairs(xPlayers) do
ESX.RegisterCommand('get', 'user', function(xPlayer, args, showError)
local xPlayers = ESX.GetExtendedPlayers(args.key, args.val) -- New hitchless xPlayer loop, with the ability to only return players with specific data
for _, xPlayer in pairs(xPlayers) do -- Job and any non-table variable will work, ie. name, group, identifier, source
print(xPlayer.source, xPlayer.job.grade_label, xPlayer.name)
end
end)
end, true, {help = 'Display all online players with specific player data', validate = false, arguments = {
{name = 'key', help = 'Variable to check (ie. job)', type = 'string'},
{name = 'val', help = 'Value required (ie. police)', type = 'any'}
}})
+45 -13
View File
@@ -15,16 +15,17 @@ endpoint_add_udp "0.0.0.0:30120"
sv_hostname "Unconfigured ESX Server"
set steam_webApiKey "none"
set steam_webApiKey ""
sv_licenseKey ""
sv_maxclients 10 # Allow access to features usually locked behind a FiveM patreon key
sv_maxclients 10 # Allow access to features usually locked behind a FiveM patreon key
sets sv_projectName "ESX Legacy"
sets sv_projectDesc ""
sets locale "root-AQ"
sets tags "default, esx"
sv_scriptHookAllowed 0
set onesync legacy # Not recommended to use Infinity with ESX
set onesync legacy # Infinity is not recommended for ESX
set mysql_connection_string "mysql://user:password@localhost/es_extended?waitForConnections=true&charset=utf8mb4"
@@ -54,13 +55,44 @@ ensure esx_identity
ensure esx_skin
## ESX Addons
#
#
#
#
#
#
#
#
#
#
#ensure esx_multicharacter # es_extended requires Config.Multichar = true
ensure instance
ensure esx_rpchat
ensure esx_phone
ensure esx_voice
ensure esx_sit
ensure esx_animations
ensure esx_addonaccount
ensure esx_addoninventory
ensure esx_datastore
ensure esx_property
ensure esx_garage
ensure esx_society
ensure esx_service
ensure esx_billing
ensure esx_license
ensure esx_dmvschool
ensure esx_status
ensure esx_basicneeds
ensure esx_optionalneeds
ensure esx_shops
ensure esx_weaponshop
ensure esx_clotheshop
ensure esx_barbershop
ensure esx_accessories
ensure esx_vehicleshop
ensure esx_boat
ensure esx_jobs
ensure esx_joblisting
ensure esx_cruisecontrol
ensure esx_atm
ensure esx_drugs
ensure esx_holdup
ensure esx_lscustom
ensure esx_ambulancejob
ensure esx_mechanicjob
ensure esx_ambulancejob
ensure esx_policejob
ensure esx_bankerjob
ensure esx_realestateagentjob
ensure esx_taxijob