mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-28 22:01:29 +00:00
fix(es_extended/server): add missing params to stop warnings
This commit is contained in:
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"Lua.diagnostics.globals": [
|
||||
"MySQL",
|
||||
"GetPlayerTimeOnline"
|
||||
]
|
||||
}
|
||||
@@ -4,7 +4,6 @@ RegisterNetEvent("esx:requestModel", function(model)
|
||||
ESX.Streaming.RequestModel(model)
|
||||
end)
|
||||
|
||||
|
||||
local function EnablePvP()
|
||||
if Config.EnablePVP then
|
||||
SetCanAttackFriendly(ESX.PlayerData.ped, true, false)
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
local _GetPlayerPed = GetPlayerPed
|
||||
local _GetEntityCoords = GetEntityCoords
|
||||
local _GetEntityHeading = GetEntityHeading
|
||||
local _ExecuteCommand = ExecuteCommand
|
||||
local _SetEntityCoords = SetEntityCoords
|
||||
local _SetEntityHeading = SetEntityHeading
|
||||
local _TriggerClientEvent = TriggerClientEvent
|
||||
local _DropPlayer = DropPlayer
|
||||
local _TriggerEvent = TriggerEvent
|
||||
local _GiveWeaponToPed = GiveWeaponToPed
|
||||
local _SetPedAmmo = SetPedAmmo
|
||||
local _RemoveWeaponFromPed = RemoveWeaponFromPed
|
||||
local _assert = assert
|
||||
---@class xPlayer
|
||||
---@field accounts table
|
||||
---@field coords table
|
||||
---@field group string
|
||||
---@field identifier string
|
||||
---@field inventory table
|
||||
---@field job table
|
||||
---@field loadout table
|
||||
---@field name string
|
||||
---@field playerId number
|
||||
---@field source number
|
||||
---@field variables table
|
||||
---@field weight number
|
||||
---@field maxWeight number
|
||||
---@field metadata table
|
||||
---@field lastPlaytime number
|
||||
---@field admin boolean
|
||||
---@field license string
|
||||
|
||||
---@param playerId number
|
||||
---@param identifier string
|
||||
@@ -26,6 +31,7 @@ local _assert = assert
|
||||
function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords, metadata)
|
||||
local targetOverrides = Config.PlayerFunctionOverride and Core.PlayerFunctionOverrides[Config.PlayerFunctionOverride] or {}
|
||||
|
||||
---@class xPlayer
|
||||
local self = {}
|
||||
|
||||
self.accounts = accounts
|
||||
@@ -45,12 +51,15 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.lastPlaytime = self.metadata.lastPlaytime or 0
|
||||
self.admin = Core.IsPlayerAdmin(playerId)
|
||||
if Config.Multichar then
|
||||
self.license = "license" .. identifier:sub(identifier:find(":"), identifier:len())
|
||||
local startIndex = identifier:find(":", 1)
|
||||
if startIndex then
|
||||
self.license = ("license%s"):format(identifier:sub(startIndex, identifier:len()))
|
||||
end
|
||||
else
|
||||
self.license = "license:" .. identifier
|
||||
self.license = ("license:%s"):format(identifier)
|
||||
end
|
||||
|
||||
_ExecuteCommand(("add_principal identifier.%s group.%s"):format(self.license, self.group))
|
||||
ExecuteCommand(("add_principal identifier.%s group.%s"):format(self.license, self.group))
|
||||
|
||||
local stateBag = Player(self.source).state
|
||||
stateBag:set("identifier", self.identifier, false)
|
||||
@@ -61,33 +70,33 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param eventName string
|
||||
---@param ... any
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.triggerEvent(eventName, ...)
|
||||
_assert(type(eventName) == "string", "eventName should be string!")
|
||||
_TriggerClientEvent(eventName, self.source, ...)
|
||||
assert(type(eventName) == "string", "eventName should be string!")
|
||||
TriggerClientEvent(eventName, self.source, ...)
|
||||
end
|
||||
|
||||
---@param coordinates vector4 | vector3 | table
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setCoords(coordinates)
|
||||
local ped <const> = _GetPlayerPed(self.source)
|
||||
local vector = type(coordinates) == "vector4" and coordinates or type(coordinates) == "vector3" and vector4(coordinates, 0.0) or vec(coordinates.x, coordinates.y, coordinates.z, coordinates.heading or 0.0)
|
||||
_SetEntityCoords(ped, vector.xyz, false, false, false, false)
|
||||
_SetEntityHeading(ped, vector.w)
|
||||
local ped <const> = GetPlayerPed(self.source)
|
||||
|
||||
SetEntityCoords(ped, coordinates.x, coordinates.y, coordinates.z, false, false, false, false)
|
||||
SetEntityHeading(ped, coordinates.w or coordinates.heading or 0.0)
|
||||
end
|
||||
|
||||
---@param vector boolean
|
||||
---@param heading boolean
|
||||
---@return vector3 | vector4 | table
|
||||
function self.getCoords(vector, heading)
|
||||
local ped <const> = _GetPlayerPed(self.source)
|
||||
local entityCoords <const> = _GetEntityCoords(ped)
|
||||
local entityHeading <const> = _GetEntityHeading(ped)
|
||||
local ped <const> = GetPlayerPed(self.source)
|
||||
local entityCoords <const> = GetEntityCoords(ped)
|
||||
local entityHeading <const> = GetEntityHeading(ped)
|
||||
|
||||
local coordinates = { x = entityCoords.x, y = entityCoords.y, z = entityCoords.z }
|
||||
|
||||
if vector then
|
||||
coordinates = (heading and vector4(entityCoords.xyz, entityHeading) or entityCoords)
|
||||
coordinates = (heading and vector4(entityCoords.x, entityCoords.y, entityCoords.z, entityHeading) or entityCoords)
|
||||
else
|
||||
if heading then
|
||||
coordinates.heading = entityHeading
|
||||
@@ -98,9 +107,10 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param reason string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.kick(reason)
|
||||
_DropPlayer(self.source, reason)
|
||||
local source <const> = tostring(self.source)
|
||||
DropPlayer(source, reason)
|
||||
end
|
||||
|
||||
---@return number
|
||||
@@ -109,9 +119,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param money number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setMoney(money)
|
||||
_assert(type(money) == "number", "money should be number!")
|
||||
assert(type(money) == "number", "money should be number!")
|
||||
money = ESX.Math.Round(money)
|
||||
self.setAccountMoney("money", money)
|
||||
end
|
||||
@@ -123,7 +133,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param money number
|
||||
---@param reason string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.addMoney(money, reason)
|
||||
money = ESX.Math.Round(money)
|
||||
self.addAccountMoney("money", money, reason)
|
||||
@@ -131,7 +141,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param money number
|
||||
---@param reason string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.removeMoney(money, reason)
|
||||
money = ESX.Math.Round(money)
|
||||
self.removeAccountMoney("money", money, reason)
|
||||
@@ -143,19 +153,19 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param newGroup string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setGroup(newGroup)
|
||||
local lastGroup = self.group
|
||||
|
||||
_ExecuteCommand(("remove_principal identifier.%s group.%s"):format(self.license, self.group))
|
||||
ExecuteCommand(("remove_principal identifier.%s group.%s"):format(self.license, self.group))
|
||||
|
||||
self.group = newGroup
|
||||
|
||||
_TriggerEvent("esx:setGroup", self.source, self.group, lastGroup)
|
||||
TriggerEvent("esx:setGroup", self.source, self.group, lastGroup)
|
||||
self.triggerEvent("esx:setGroup", self.group, lastGroup)
|
||||
Player(self.source).state:set("group", self.group, true)
|
||||
|
||||
_ExecuteCommand(("add_principal identifier.%s group.%s"):format(self.license, self.group))
|
||||
ExecuteCommand(("add_principal identifier.%s group.%s"):format(self.license, self.group))
|
||||
end
|
||||
|
||||
---@return string
|
||||
@@ -165,7 +175,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param k string
|
||||
---@param v any
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.set(k, v)
|
||||
self.variables[k] = v
|
||||
end
|
||||
@@ -266,7 +276,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param newName string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setName(newName)
|
||||
self.name = newName
|
||||
Player(self.source).state:set("name", self.name, true)
|
||||
@@ -274,8 +284,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param accountName string
|
||||
---@param money number
|
||||
---@param reason string
|
||||
---@return void
|
||||
---@param reason string | nil
|
||||
---@return nil
|
||||
function self.setAccountMoney(accountName, money, reason)
|
||||
reason = reason or "unknown"
|
||||
if not tonumber(money) then
|
||||
@@ -290,7 +300,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.accounts[account.index].money = money
|
||||
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
_TriggerEvent("esx:setAccountMoney", self.source, accountName, money, reason)
|
||||
TriggerEvent("esx:setAccountMoney", self.source, accountName, money, reason)
|
||||
else
|
||||
error(("Tried To Set Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
|
||||
end
|
||||
@@ -301,8 +311,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param accountName string
|
||||
---@param money number
|
||||
---@param reason string
|
||||
---@return void
|
||||
---@param reason string | nil
|
||||
---@return nil
|
||||
function self.addAccountMoney(accountName, money, reason)
|
||||
reason = reason or "Unknown"
|
||||
if not tonumber(money) then
|
||||
@@ -316,7 +326,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.accounts[account.index].money = self.accounts[account.index].money + money
|
||||
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
_TriggerEvent("esx:addAccountMoney", self.source, accountName, money, reason)
|
||||
TriggerEvent("esx:addAccountMoney", self.source, accountName, money, reason)
|
||||
else
|
||||
error(("Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
|
||||
end
|
||||
@@ -327,8 +337,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param accountName string
|
||||
---@param money number
|
||||
---@param reason string
|
||||
---@return void
|
||||
---@param reason string | nil
|
||||
---@return nil
|
||||
function self.removeAccountMoney(accountName, money, reason)
|
||||
reason = reason or "Unknown"
|
||||
if not tonumber(money) then
|
||||
@@ -347,7 +357,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.accounts[account.index].money = self.accounts[account.index].money - money
|
||||
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
_TriggerEvent("esx:removeAccountMoney", self.source, accountName, money, reason)
|
||||
TriggerEvent("esx:removeAccountMoney", self.source, accountName, money, reason)
|
||||
else
|
||||
error(("Tried To Set Add To Invalid Account ^5%s^0 For Player ^5%s^0!"):format(accountName, self.playerId))
|
||||
end
|
||||
@@ -369,7 +379,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param itemName string
|
||||
---@param count number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.addInventoryItem(itemName, count)
|
||||
local item = self.getInventoryItem(itemName)
|
||||
|
||||
@@ -378,14 +388,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
item.count = item.count + count
|
||||
self.weight = self.weight + (item.weight * count)
|
||||
|
||||
_TriggerEvent("esx:onAddInventoryItem", self.source, item.name, item.count)
|
||||
TriggerEvent("esx:onAddInventoryItem", self.source, item.name, item.count)
|
||||
self.triggerEvent("esx:addInventoryItem", item.name, item.count)
|
||||
end
|
||||
end
|
||||
|
||||
---@param itemName string
|
||||
---@param count number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.removeInventoryItem(itemName, count)
|
||||
local item = self.getInventoryItem(itemName)
|
||||
|
||||
@@ -398,7 +408,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
item.count = newCount
|
||||
self.weight = self.weight - (item.weight * count)
|
||||
|
||||
_TriggerEvent("esx:onRemoveInventoryItem", self.source, item.name, item.count)
|
||||
TriggerEvent("esx:onRemoveInventoryItem", self.source, item.name, item.count)
|
||||
self.triggerEvent("esx:removeInventoryItem", item.name, item.count)
|
||||
end
|
||||
else
|
||||
@@ -409,7 +419,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param itemName string
|
||||
---@param count number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setInventoryItem(itemName, count)
|
||||
local item = self.getInventoryItem(itemName)
|
||||
|
||||
@@ -445,6 +455,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
return newWeight <= self.maxWeight
|
||||
else
|
||||
print(('[^3WARNING^7] Item ^5"%s"^7 was used but does not exist!'):format(itemName))
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -455,7 +466,13 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
---@return boolean
|
||||
function self.canSwapItem(firstItem, firstItemCount, testItem, testItemCount)
|
||||
local firstItemObject = self.getInventoryItem(firstItem)
|
||||
if not firstItemObject then
|
||||
return false
|
||||
end
|
||||
local testItemObject = self.getInventoryItem(testItem)
|
||||
if not testItemObject then
|
||||
return false
|
||||
end
|
||||
|
||||
if firstItemObject.count >= firstItemCount then
|
||||
local weightWithoutFirstItem = ESX.Math.Round(self.weight - (firstItemObject.weight * firstItemCount))
|
||||
@@ -468,7 +485,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param newWeight number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setMaxWeight(newWeight)
|
||||
self.maxWeight = newWeight
|
||||
self.triggerEvent("esx:setMaxWeight", self.maxWeight)
|
||||
@@ -476,13 +493,13 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param newJob string
|
||||
---@param grade string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setJob(newJob, grade)
|
||||
grade = tostring(grade)
|
||||
local lastJob = self.job
|
||||
|
||||
if not ESX.DoesJobExist(newJob, grade) then
|
||||
return print(("[es_extended] [^3WARNING^7] Ignoring invalid ^5.setJob()^7 usage for ID: ^5%s^7, Job: ^5%s^7"):format(self.source, newJob))
|
||||
return print(("[ESX] [^3WARNING^7] Ignoring invalid ^5.setJob()^7 usage for ID: ^5%s^7, Job: ^5%s^7"):format(self.source, newJob))
|
||||
end
|
||||
|
||||
local jobObject, gradeObject = ESX.Jobs[newJob], ESX.Jobs[newJob].grades[grade]
|
||||
@@ -501,14 +518,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {},
|
||||
}
|
||||
|
||||
_TriggerEvent("esx:setJob", self.source, self.job, lastJob)
|
||||
TriggerEvent("esx:setJob", self.source, self.job, lastJob)
|
||||
self.triggerEvent("esx:setJob", self.job, lastJob)
|
||||
Player(self.source).state:set("job", self.job, true)
|
||||
end
|
||||
|
||||
---@param weaponName string
|
||||
---@param ammo number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.addWeapon(weaponName, ammo)
|
||||
if not self.hasWeapon(weaponName) then
|
||||
local weaponLabel <const> = ESX.GetWeaponLabel(weaponName)
|
||||
@@ -521,14 +538,14 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
tintIndex = 0,
|
||||
})
|
||||
|
||||
_GiveWeaponToPed(_GetPlayerPed(self.source), joaat(weaponName), ammo, false, false)
|
||||
GiveWeaponToPed(GetPlayerPed(self.source), joaat(weaponName), ammo, false, false)
|
||||
self.triggerEvent("esx:addInventoryItem", weaponLabel, false, true)
|
||||
end
|
||||
end
|
||||
|
||||
---@param weaponName string
|
||||
---@param weaponComponent string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.addWeaponComponent(weaponName, weaponComponent)
|
||||
local loadoutNum <const>, weapon <const> = self.getWeapon(weaponName)
|
||||
|
||||
@@ -548,19 +565,19 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param weaponName string
|
||||
---@param ammoCount number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.addWeaponAmmo(weaponName, ammoCount)
|
||||
local _, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if weapon then
|
||||
weapon.ammo = weapon.ammo + ammoCount
|
||||
_SetPedAmmo(GetPlayerPed(self.source), joaat(weaponName), weapon.ammo)
|
||||
SetPedAmmo(GetPlayerPed(self.source), joaat(weaponName), weapon.ammo)
|
||||
end
|
||||
end
|
||||
|
||||
---@param weaponName string
|
||||
---@param ammoCount number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.updateWeaponAmmo(weaponName, ammoCount)
|
||||
local _, weapon = self.getWeapon(weaponName)
|
||||
|
||||
@@ -571,7 +588,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param weaponName string
|
||||
---@param weaponTintIndex number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setWeaponTint(weaponName, weaponTintIndex)
|
||||
local loadoutNum <const>, weapon <const> = self.getWeapon(weaponName)
|
||||
|
||||
@@ -599,9 +616,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param weaponName string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.removeWeapon(weaponName)
|
||||
local weaponLabel, playerPed <const> = nil, _GetPlayerPed(self.source)
|
||||
local weaponLabel, playerPed <const> = nil, GetPlayerPed(self.source)
|
||||
|
||||
if not playerPed then
|
||||
return error("xPlayer.removeWeapon ^5invalid^7 player ped!")
|
||||
@@ -616,8 +633,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
local weaponHash = joaat(v.name)
|
||||
_RemoveWeaponFromPed(playerPed, weaponHash)
|
||||
_SetPedAmmo(playerPed, weaponHash, 0)
|
||||
RemoveWeaponFromPed(playerPed, weaponHash)
|
||||
SetPedAmmo(playerPed, weaponHash, 0)
|
||||
|
||||
table.remove(self.loadout, k)
|
||||
break
|
||||
@@ -631,7 +648,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param weaponName string
|
||||
---@param weaponComponent string
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.removeWeaponComponent(weaponName, weaponComponent)
|
||||
local loadoutNum <const>, weapon <const> = self.getWeapon(weaponName)
|
||||
|
||||
@@ -657,13 +674,13 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
|
||||
---@param weaponName string
|
||||
---@param ammoCount number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.removeWeaponAmmo(weaponName, ammoCount)
|
||||
local _, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if weapon then
|
||||
weapon.ammo = weapon.ammo - ammoCount
|
||||
_SetPedAmmo(GetPlayerPed(self.source), joaat(weaponName), weapon.ammo)
|
||||
SetPedAmmo(GetPlayerPed(self.source), joaat(weaponName), weapon.ammo)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -699,7 +716,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param item string
|
||||
---@return table, number | false
|
||||
---@return table | false, number | nil
|
||||
function self.hasItem(item)
|
||||
for _, v in ipairs(self.inventory) do
|
||||
if v.name == item and v.count >= 1 then
|
||||
@@ -711,7 +728,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
|
||||
---@param weaponName string
|
||||
---@return number, table | nil
|
||||
---@return number | nil, table | nil
|
||||
function self.getWeapon(weaponName)
|
||||
for k, v in ipairs(self.loadout) do
|
||||
if v.name == weaponName then
|
||||
@@ -719,13 +736,13 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param type string
|
||||
---@param notifyType string
|
||||
---@param length number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.showNotification(msg, notifyType, length)
|
||||
self.triggerEvent("esx:showNotification", msg, notifyType, length)
|
||||
end
|
||||
@@ -738,7 +755,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
---@param flash boolean
|
||||
---@param saveToBrief boolean
|
||||
---@param hudColorIndex number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.showAdvancedNotification(sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex)
|
||||
self.triggerEvent("esx:showAdvancedNotification", sender, subject, msg, textureDict, iconType, flash, saveToBrief, hudColorIndex)
|
||||
end
|
||||
@@ -747,21 +764,22 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
---@param thisFrame boolean
|
||||
---@param beep boolean
|
||||
---@param duration number
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.showHelpNotification(msg, thisFrame, beep, duration)
|
||||
self.triggerEvent("esx:showHelpNotification", msg, thisFrame, beep, duration)
|
||||
end
|
||||
|
||||
---@param index any
|
||||
---@param subIndex any
|
||||
---@return table
|
||||
---@return table | nil
|
||||
function self.getMeta(index, subIndex)
|
||||
if not index then
|
||||
return self.metadata
|
||||
end
|
||||
|
||||
if type(index) ~= "string" then
|
||||
return error("xPlayer.getMeta ^5index^7 should be ^5string^7!")
|
||||
error("xPlayer.getMeta ^5index^7 should be ^5string^7!")
|
||||
return
|
||||
end
|
||||
|
||||
local metaData = self.metadata[index]
|
||||
@@ -792,7 +810,8 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
return returnValues
|
||||
end
|
||||
|
||||
return error(("xPlayer.getMeta subIndex should be ^5string^7 or ^5table^7!, received ^5%s^7!"):format(_type))
|
||||
error(("xPlayer.getMeta subIndex should be ^5string^7 or ^5table^7!, received ^5%s^7!"):format(_type))
|
||||
return
|
||||
end
|
||||
|
||||
return metaData
|
||||
@@ -801,7 +820,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
---@param index any
|
||||
---@param value any
|
||||
---@param subValue any
|
||||
---@return void
|
||||
---@return nil
|
||||
function self.setMeta(index, value, subValue)
|
||||
if not index then
|
||||
return error("xPlayer.setMeta ^5index^7 is Missing!")
|
||||
|
||||
@@ -77,7 +77,7 @@ ESX.RegisterCommand(
|
||||
local playerPed = GetPlayerPed(xPlayer.source)
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
local playerHeading = GetEntityHeading(playerPed)
|
||||
local playerVehicle = GetVehiclePedIsIn(playerPed)
|
||||
local playerVehicle = GetVehiclePedIsIn(playerPed, false)
|
||||
|
||||
if not args.car or type(args.car) ~= "string" then
|
||||
args.car = "adder"
|
||||
@@ -126,11 +126,15 @@ ESX.RegisterCommand(
|
||||
{ "cardel", "dv" },
|
||||
"admin",
|
||||
function(xPlayer, args)
|
||||
local PedVehicle = GetVehiclePedIsIn(GetPlayerPed(xPlayer.source), false)
|
||||
if DoesEntityExist(PedVehicle) then
|
||||
DeleteEntity(PedVehicle)
|
||||
local ped = GetPlayerPed(xPlayer.source)
|
||||
local pedVehicle = GetVehiclePedIsIn(ped, false)
|
||||
|
||||
if DoesEntityExist(pedVehicle) then
|
||||
DeleteEntity(pedVehicle)
|
||||
end
|
||||
local Vehicles = ESX.OneSync.GetVehiclesInArea(GetEntityCoords(GetPlayerPed(xPlayer.source)), tonumber(args.radius) or 5.0)
|
||||
|
||||
local coords = GetEntityCoords(ped)
|
||||
local Vehicles = ESX.OneSync.GetVehiclesInArea(coords, tonumber(args.radius) or 5.0)
|
||||
for i = 1, #Vehicles do
|
||||
local Vehicle = NetworkGetEntityFromNetworkId(Vehicles[i])
|
||||
if DoesEntityExist(Vehicle) then
|
||||
@@ -548,6 +552,14 @@ ESX.RegisterCommand("info", { "user", "admin" }, function(xPlayer)
|
||||
print(("^2ID: ^5%s^0 | ^2Name: ^5%s^0 | ^2Group: ^5%s^0 | ^2Job: ^5%s^0"):format(xPlayer.source, xPlayer.getName(), xPlayer.getGroup(), job))
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("playtime", { "user", "admin" }, function(xPlayer)
|
||||
local playtime = xPlayer.getPlayTime()
|
||||
local days = math.floor(playtime / 86400)
|
||||
local hours = math.floor((playtime % 86400) / 3600)
|
||||
local minutes = math.floor((playtime % 3600) / 60)
|
||||
print(("Playtime: ^5%s^0 Days | ^5%s^0 Hours | ^5%s^0 Minutes"):format(days, hours, minutes))
|
||||
end, false)
|
||||
|
||||
ESX.RegisterCommand("coords", "admin", function(xPlayer)
|
||||
local ped = GetPlayerPed(xPlayer.source)
|
||||
local coords = GetEntityCoords(ped, false)
|
||||
|
||||
@@ -20,7 +20,7 @@ end)
|
||||
if Config.OxInventory then
|
||||
Config.PlayerFunctionOverride = "OxInventory"
|
||||
SetConvarReplicated("inventory:framework", "esx")
|
||||
SetConvarReplicated("inventory:weight", Config.MaxWeight * 1000)
|
||||
SetConvarReplicated("inventory:weight", tostring(Config.MaxWeight * 1000))
|
||||
end
|
||||
|
||||
local function StartDBSync()
|
||||
|
||||
@@ -348,7 +348,7 @@ end
|
||||
---@param model string|number
|
||||
---@param player number playerId
|
||||
---@param cb function
|
||||
|
||||
---@diagnostic disable-next-line: duplicate-set-field
|
||||
function ESX.GetVehicleType(model, player, cb)
|
||||
model = type(model) == "string" and joaat(model) or model
|
||||
|
||||
@@ -381,7 +381,9 @@ function ESX.DiscordLog(name, title, color, message)
|
||||
}
|
||||
PerformHttpRequest(
|
||||
webHook,
|
||||
nil,
|
||||
function ()
|
||||
return
|
||||
end,
|
||||
"POST",
|
||||
json.encode({
|
||||
username = "Logs",
|
||||
@@ -413,7 +415,9 @@ function ESX.DiscordLogFields(name, title, color, fields)
|
||||
}
|
||||
PerformHttpRequest(
|
||||
webHook,
|
||||
nil,
|
||||
function ()
|
||||
return
|
||||
end,
|
||||
"POST",
|
||||
json.encode({
|
||||
username = "Logs",
|
||||
|
||||
@@ -19,6 +19,54 @@ end
|
||||
|
||||
loadPlayer = loadPlayer .. " FROM `users` WHERE identifier = ?"
|
||||
|
||||
local function createESXPlayer(identifier, playerId, data)
|
||||
local accounts = {}
|
||||
|
||||
for account, money in pairs(Config.StartingAccountMoney) do
|
||||
accounts[account] = money
|
||||
end
|
||||
|
||||
local defaultGroup = "user"
|
||||
if Core.IsPlayerAdmin(playerId) then
|
||||
print(("[^2INFO^0] Player ^5%s^0 Has been granted admin permissions via ^5Ace Perms^7."):format(playerId))
|
||||
defaultGroup = "admin"
|
||||
end
|
||||
|
||||
local parameters = Config.Multichar and { json.encode(accounts), identifier, defaultGroup, data.firstname, data.lastname, data.dateofbirth, data.sex, data.height } or { json.encode(accounts), identifier, defaultGroup }
|
||||
|
||||
if Config.StartingInventoryItems then
|
||||
table.insert(parameters, json.encode(Config.StartingInventoryItems))
|
||||
end
|
||||
|
||||
MySQL.prepare(newPlayer, parameters, function()
|
||||
loadESXPlayer(identifier, playerId, true)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
local function onPlayerJoined(playerId)
|
||||
local identifier = ESX.GetIdentifier(playerId)
|
||||
if identifier then
|
||||
if ESX.GetPlayerFromIdentifier(identifier) then
|
||||
DropPlayer(
|
||||
playerId,
|
||||
("there was an error loading your character!\nError code: identifier-active-ingame\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same Rockstar account.\n\nYour Rockstar identifier: %s"):format(
|
||||
identifier
|
||||
)
|
||||
)
|
||||
else
|
||||
local result = MySQL.scalar.await("SELECT 1 FROM users WHERE identifier = ?", { identifier })
|
||||
if result then
|
||||
loadESXPlayer(identifier, playerId, false)
|
||||
else
|
||||
createESXPlayer(identifier, playerId)
|
||||
end
|
||||
end
|
||||
else
|
||||
DropPlayer(playerId, "there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.")
|
||||
end
|
||||
end
|
||||
|
||||
if Config.Multichar then
|
||||
AddEventHandler("esx:onPlayerJoined", function(src, char, data)
|
||||
while not next(ESX.Jobs) do
|
||||
@@ -48,53 +96,6 @@ else
|
||||
end)
|
||||
end
|
||||
|
||||
function onPlayerJoined(playerId)
|
||||
local identifier = ESX.GetIdentifier(playerId)
|
||||
if identifier then
|
||||
if ESX.GetPlayerFromIdentifier(identifier) then
|
||||
DropPlayer(
|
||||
playerId,
|
||||
("there was an error loading your character!\nError code: identifier-active-ingame\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same Rockstar account.\n\nYour Rockstar identifier: %s"):format(
|
||||
identifier
|
||||
)
|
||||
)
|
||||
else
|
||||
local result = MySQL.scalar.await("SELECT 1 FROM users WHERE identifier = ?", { identifier })
|
||||
if result then
|
||||
loadESXPlayer(identifier, playerId, false)
|
||||
else
|
||||
createESXPlayer(identifier, playerId)
|
||||
end
|
||||
end
|
||||
else
|
||||
DropPlayer(playerId, "there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.")
|
||||
end
|
||||
end
|
||||
|
||||
function createESXPlayer(identifier, playerId, data)
|
||||
local accounts = {}
|
||||
|
||||
for account, money in pairs(Config.StartingAccountMoney) do
|
||||
accounts[account] = money
|
||||
end
|
||||
|
||||
local defaultGroup = "user"
|
||||
if Core.IsPlayerAdmin(playerId) then
|
||||
print(("[^2INFO^0] Player ^5%s^0 Has been granted admin permissions via ^5Ace Perms^7."):format(playerId))
|
||||
defaultGroup = "admin"
|
||||
end
|
||||
|
||||
local parameters = Config.Multichar and { json.encode(accounts), identifier, defaultGroup, data.firstname, data.lastname, data.dateofbirth, data.sex, data.height } or { json.encode(accounts), identifier, defaultGroup }
|
||||
|
||||
if Config.StartingInventoryItems then
|
||||
table.insert(parameters, json.encode(Config.StartingInventoryItems))
|
||||
end
|
||||
|
||||
MySQL.prepare(newPlayer, parameters, function()
|
||||
loadESXPlayer(identifier, playerId, true)
|
||||
end)
|
||||
end
|
||||
|
||||
if not Config.Multichar then
|
||||
AddEventHandler("playerConnecting", function(_, _, deferrals)
|
||||
deferrals.defer()
|
||||
@@ -613,7 +614,7 @@ ESX.RegisterServerCallback("esx:isUserAdmin", function(source, cb)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback("esx:getGameBuild", function(_, cb)
|
||||
cb(tonumber(GetConvar("sv_enforceGameBuild", 1604)))
|
||||
cb(tonumber(GetConvar("sv_enforceGameBuild", "1604")))
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback("esx:getOtherPlayerData", function(_, cb, target)
|
||||
@@ -653,7 +654,7 @@ ESX.RegisterServerCallback("esx:spawnVehicle", function(source, cb, vehData)
|
||||
if vehData.warp then
|
||||
local vehicle = NetworkGetEntityFromNetworkId(id)
|
||||
local timeout = 0
|
||||
while GetVehiclePedIsIn(ped) ~= vehicle and timeout <= 15 do
|
||||
while GetVehiclePedIsIn(ped, false) ~= vehicle and timeout <= 15 do
|
||||
Wait(0)
|
||||
TaskWarpPedIntoVehicle(ped, vehicle, -1)
|
||||
timeout += 1
|
||||
|
||||
@@ -7,6 +7,9 @@ AddEventHandler("onServerResourceStart", function(resource)
|
||||
|
||||
npwd = GetResourceState("npwd"):find("start") and exports.npwd or nil
|
||||
|
||||
if not npwd then
|
||||
return
|
||||
end
|
||||
for _, xPlayer in pairs(ESX.Players) do
|
||||
npwd:newPlayer({
|
||||
source = xPlayer.source,
|
||||
|
||||
@@ -84,23 +84,23 @@ end
|
||||
---@param properties table
|
||||
---@param cb function
|
||||
function ESX.OneSync.SpawnVehicle(model, coords, heading, properties, cb)
|
||||
local vehicleModel = joaat(model)
|
||||
local vehicleModel = type(model) == "string" and joaat(model) or model
|
||||
local vehicleProperties = properties
|
||||
|
||||
CreateThread(function()
|
||||
local xPlayer = ESX.OneSync.GetClosestPlayer(coords, 300)
|
||||
ESX.GetVehicleType(vehicleModel, xPlayer.id, function(vehicleType)
|
||||
if vehicleType then
|
||||
local createdVehicle = CreateVehicleServerSetter(vehicleModel, vehicleType, coords, heading)
|
||||
local createdVehicle = CreateVehicleServerSetter(vehicleModel, vehicleType, coords.x, coords.y, coords.z, heading)
|
||||
if not DoesEntityExist(createdVehicle) then
|
||||
return error("Unfortunately, this vehicle has not spawned")
|
||||
return error("Unable to spawn vehicle")
|
||||
end
|
||||
|
||||
local networkId = NetworkGetNetworkIdFromEntity(createdVehicle)
|
||||
Entity(createdVehicle).state:set("VehicleProperties", vehicleProperties, true)
|
||||
cb(networkId)
|
||||
else
|
||||
error(("Tried to spawn invalid vehicle - ^5%s^7!"):format(model))
|
||||
return error(("Unable to get vehicle type: ^5%s^1"):format(model))
|
||||
end
|
||||
end)
|
||||
end)
|
||||
@@ -114,9 +114,9 @@ function ESX.OneSync.SpawnObject(model, coords, heading, cb)
|
||||
if type(model) == "string" then
|
||||
model = joaat(model)
|
||||
end
|
||||
local objectCoords = type(coords) == "vector3" and coords or vector3(coords.x, coords.y, coords.z)
|
||||
local spawnCoords = type(coords) == "vector3" and coords or vector3(coords.x, coords.y, coords.z)
|
||||
CreateThread(function()
|
||||
local entity = CreateObject(model, objectCoords, true, true)
|
||||
local entity = CreateObject(model, spawnCoords.x, spawnCoords.y, spawnCoords.z, true, true, false)
|
||||
while not DoesEntityExist(entity) do
|
||||
Wait(50)
|
||||
end
|
||||
@@ -194,14 +194,14 @@ end
|
||||
|
||||
---@param coords vector3
|
||||
---@param maxDistance number
|
||||
---@param modelFilter table models to ignore, where the key is the model hash and the value is true
|
||||
---@param modelFilter table | nil models to ignore, where the key is the model hash and the value is true
|
||||
---@return table
|
||||
function ESX.OneSync.GetVehiclesInArea(coords, maxDistance, modelFilter)
|
||||
return getNearbyEntities(GetAllVehicles(), coords, modelFilter, maxDistance)
|
||||
end
|
||||
|
||||
local function getClosestEntity(entities, coords, modelFilter, isPed)
|
||||
local distance, closestEntity, closestCoords = 100, nil, nil
|
||||
local distance, closestEntity, closestCoords = 100, 0, vector3(0, 0, 0)
|
||||
coords = type(coords) == "number" and GetEntityCoords(GetPlayerPed(coords)) or vector3(coords.x, coords.y, coords.z)
|
||||
|
||||
for _, entity in pairs(entities) do
|
||||
@@ -215,6 +215,7 @@ local function getClosestEntity(entities, coords, modelFilter, isPed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return NetworkGetNetworkIdFromEntity(closestEntity), distance, closestCoords
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user