Merge pull request #696 from Mycroft-Studios/dev

fix/feat(es_extended): Basic Statebags + Correct vehicle spawning
This commit is contained in:
Benzo
2022-11-26 18:19:55 +01:00
committed by GitHub
5 changed files with 47 additions and 22 deletions
+4
View File
@@ -13,6 +13,10 @@ CreateThread(function()
end
end)
RegisterNetEvent("esx:requestModel", function(model)
ESX.Streaming.RequestModel(model)
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
ESX.PlayerData = xPlayer
@@ -19,6 +19,12 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if Config.Multichar then self.license = 'license'.. identifier:sub(identifier:find(':'), identifier:len()) else self.license = 'license:'..identifier end
ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group))
Player(self.source).state:set("identifier", self.identifier, true)
Player(self.source).state:set("license", self.license, true)
Player(self.source).state:set("job", self.job, true)
Player(self.source).state:set("group", self.group, true)
Player(self.source).state:set("name", self.name, true)
function self.triggerEvent(eventName, ...)
TriggerClientEvent(eventName, self.source, ...)
@@ -78,6 +84,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
function self.setGroup(newGroup)
ExecuteCommand(('remove_principal identifier.%s group.%s'):format(self.license, self.group))
self.group = newGroup
Player(self.source).state:set("group", self.group, true)
ExecuteCommand(('add_principal identifier.%s group.%s'):format(self.license, self.group))
end
@@ -87,6 +94,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
function self.set(k, v)
self.variables[k] = v
Player(self.source).state:set(k, v, true)
end
function self.get(k)
@@ -170,6 +178,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
function self.setName(newName)
self.name = newName
Player(self.source).state:set("name", self.name, true)
end
function self.setAccountMoney(accountName, money, reason)
@@ -360,6 +369,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
TriggerEvent('esx:setJob', self.source, self.job, lastJob)
self.triggerEvent('esx:setJob', self.job)
Player(self.source).state:set("job", self.job, true)
else
print(('[es_extended] [^3WARNING^7] Ignoring invalid ^5.setJob()^7 usage for ID: ^5%s^7, Job: ^5%s^7'):format(self.source, job))
end
+15 -17
View File
@@ -62,23 +62,21 @@ end
---@param Properties table
---@param cb function
function ESX.OneSync.SpawnVehicle(model, coords, heading, Properties, cb)
model = type(model) == 'string' and joaat(model) or model
Properties = Properties or {}
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
CreateThread(function()
local player = nil
for _, playerId in ipairs(GetPlayers()) do
ESX.GetVehicleType(model, playerId, function(Type)
local SpawnedEntity = CreateVehicleServerSetter(model, Type, vector, heading)
Wait(250)
local NetworkId = NetworkGetNetworkIdFromEntity(SpawnedEntity)
Properties.NetId = NetworkId
Entity(SpawnedEntity).state:set('VehicleProperties', Properties, true)
cb(NetworkId)
end)
break
end
end)
model = type(model) == 'string' and joaat(model) or model
Properties = Properties or {}
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
TriggerClientEvent("esx:requestModel", -1, model)
CreateThread(function()
local xPlayer = ESX.OneSync.GetClosestPlayer(vector, 200)
ESX.GetVehicleType(model, xPlayer.id, function(Type)
local SpawnedEntity = CreateVehicleServerSetter(model, Type, vector, heading)
Wait(250)
local NetworkId = NetworkGetNetworkIdFromEntity(SpawnedEntity)
Properties.NetId = NetworkId
Entity(SpawnedEntity).state:set('VehicleProperties', Properties, true)
cb(NetworkId)
end)
end)
end
+9 -4
View File
@@ -1,16 +1,21 @@
Debug = ESX.GetConfig().EnableDebug
local IsShowing = false
---@param message string
---@param typ string
local function TextUI(message, typ)
---@param Type string
local function TextUI(message, type)
IsShowing = true
SendNUIMessage({
action = 'show',
message = message and message or 'ESX-TextUI',
type = type(typ) == "string" and typ or 'info'
type = type == 0 and "info" or type
})
end
local function HideUI()
if not IsShowing then
return
end
IsShowing = false
SendNUIMessage({
action = 'hide'
})
+9 -1
View File
@@ -14,6 +14,12 @@ ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb)
cb(jobs)
end)
function IsJobAvailable(job)
local jobs = ESX.GetJobs()
local JobToCheck = jobs[job]
return not JobToCheck.whitelisted
end
function IsNearCentre(player)
local Ped = GetPlayerPed(player)
local PedCoords = GetEntityCoords(Ped)
@@ -37,11 +43,13 @@ AddEventHandler('esx_joblisting:setJob', function(job)
local xPlayer = ESX.GetPlayerFromId(source)
local jobs = getJobs()
if xPlayer and IsNearCentre(source) then
if xPlayer and IsNearCentre(source) and IsJobAvailable(job) then
if ESX.DoesJobExist(job, 0) then
xPlayer.setJob(job, 0)
else
print("[^1ERROR^7] Tried Setting User ^5".. source .. "^7 To Invalid Job - ^5"..job .."^7!")
end
else
print("[^3WARNING^7] User ^5".. source .. "^7 Attempted to Exploit ^5`esx_joblisting:setJob`^7!")
end
end)