mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 02:01:31 +00:00
feat(es_extended) cache PlayerId and Player Server Id
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
Core = {}
|
||||
ESX.PlayerData = {}
|
||||
ESX.playerId = PlayerId()
|
||||
ESX.serverId = GetPlayerServerId(PlayerId())
|
||||
ESX.PlayerLoaded = false
|
||||
Core.Input = {}
|
||||
ESX.UI = {}
|
||||
@@ -19,7 +21,7 @@ CreateThread(function()
|
||||
while not Config.Multichar do
|
||||
Wait(100)
|
||||
|
||||
if NetworkIsPlayerActive(PlayerId()) then
|
||||
if NetworkIsPlayerActive(ESX.playerId) then
|
||||
exports.spawnmanager:setAutoSpawn(false)
|
||||
DoScreenFadeOut(0)
|
||||
Wait(500)
|
||||
|
||||
@@ -60,9 +60,8 @@ end
|
||||
---@param freeze boolean Whether to freeze the player
|
||||
---@return nil
|
||||
function Core.FreezePlayer(freeze)
|
||||
local player = PlayerId()
|
||||
local ped = PlayerPedId()
|
||||
SetPlayerControl(player, not freeze, 0)
|
||||
SetPlayerControl(ESX.playerId, not freeze, 0)
|
||||
|
||||
if freeze then
|
||||
SetEntityCollision(ped, false, false)
|
||||
@@ -571,14 +570,14 @@ end
|
||||
---@param returnPeds? boolean Whether to return the peds
|
||||
---@return table
|
||||
function ESX.Game.GetPlayers(onlyOtherPlayers, returnKeyValue, returnPeds)
|
||||
local players, myPlayer = {}, PlayerId()
|
||||
local players = {}
|
||||
local active = GetActivePlayers()
|
||||
|
||||
for i = 1, #active do
|
||||
local currentPlayer = active[i]
|
||||
local ped = GetPlayerPed(currentPlayer)
|
||||
|
||||
if DoesEntityExist(ped) and ((onlyOtherPlayers and currentPlayer ~= myPlayer) or not onlyOtherPlayers) then
|
||||
if DoesEntityExist(ped) and ((onlyOtherPlayers and currentPlayer ~= ESX.playerId) or not onlyOtherPlayers) then
|
||||
if returnKeyValue then
|
||||
players[currentPlayer] = ped
|
||||
else
|
||||
|
||||
@@ -108,7 +108,6 @@ local function DisableAmmoOrVehicleRewards(playerId)
|
||||
end
|
||||
|
||||
local function ApplyConfig()
|
||||
local playerId = PlayerId()
|
||||
-- RemoveHudComponents
|
||||
for i = 1, #Config.RemoveHudComponents do
|
||||
if Config.RemoveHudComponents[i] then
|
||||
@@ -117,14 +116,14 @@ local function ApplyConfig()
|
||||
end
|
||||
|
||||
if Config.DisableAimAssist then
|
||||
SetPlayerLockon(playerId, false)
|
||||
SetPlayerLockon(ESX.playerId, false)
|
||||
end
|
||||
|
||||
-- DisableNPCDrops
|
||||
if Config.DisableNPCDrops then
|
||||
local weaponPickups = { `PICKUP_WEAPON_CARBINERIFLE`, `PICKUP_WEAPON_PISTOL`, `PICKUP_WEAPON_PUMPSHOTGUN` }
|
||||
for i = 1, #weaponPickups do
|
||||
ToggleUsePickupsForPlayer(playerId, weaponPickups[i], false)
|
||||
ToggleUsePickupsForPlayer(ESX.playerId, weaponPickups[i], false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -138,11 +137,11 @@ local function ApplyConfig()
|
||||
end
|
||||
|
||||
if Config.DisableHealthRegeneration then
|
||||
SetPlayerHealthRechargeMultiplier(playerId, 0.0)
|
||||
SetPlayerHealthRechargeMultiplier(ESX.playerId, 0.0)
|
||||
end
|
||||
|
||||
if Config.DisableDisplayAmmo or Config.DisableVehicleRewards then
|
||||
DisableAmmoOrVehicleRewards(playerId)
|
||||
DisableAmmoOrVehicleRewards(ESX.playerId)
|
||||
end
|
||||
|
||||
EnablePvP()
|
||||
@@ -270,7 +269,7 @@ AddStateBagChangeHandler("VehicleProperties", nil, function(bagName, _, value)
|
||||
return
|
||||
end
|
||||
|
||||
if not NetworkGetEntityOwner(vehicle) == PlayerId() then
|
||||
if not NetworkGetEntityOwner(vehicle) == ESX.playerId then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -466,7 +465,7 @@ end
|
||||
|
||||
-- disable wanted level
|
||||
if not Config.EnableWantedLevel then
|
||||
ClearPlayerWantedLevel(PlayerId())
|
||||
ClearPlayerWantedLevel(ESX.playerId)
|
||||
SetMaxWantedLevel(0)
|
||||
end
|
||||
|
||||
@@ -691,15 +690,14 @@ end)
|
||||
|
||||
RegisterNetEvent("esx:freezePlayer")
|
||||
AddEventHandler("esx:freezePlayer", function(input)
|
||||
local player = PlayerId()
|
||||
if input == "freeze" then
|
||||
SetEntityCollision(ESX.PlayerData.ped, false, false)
|
||||
FreezeEntityPosition(ESX.PlayerData.ped, true)
|
||||
SetPlayerInvincible(player, true)
|
||||
SetPlayerInvincible(ESX.playerId, true)
|
||||
elseif input == "unfreeze" then
|
||||
SetEntityCollision(ESX.PlayerData.ped, true, true)
|
||||
FreezeEntityPosition(ESX.PlayerData.ped, false)
|
||||
SetPlayerInvincible(player, false)
|
||||
SetPlayerInvincible(ESX.playerId, false)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ CreateThread(function()
|
||||
TriggerEvent("esx:playerPedChanged", playerPed)
|
||||
TriggerServerEvent("esx:playerPedChanged", PedToNet(playerPed))
|
||||
if Config.DisableHealthRegeneration then
|
||||
SetPlayerHealthRechargeMultiplier(PlayerId(), 0.0)
|
||||
SetPlayerHealthRechargeMultiplier(ESX.PlayerId, 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,8 +58,8 @@ CreateThread(function()
|
||||
inPauseMenu = false
|
||||
TriggerEvent("esx:pauseMenuActive", inPauseMenu)
|
||||
end
|
||||
|
||||
if not isInVehicle and not IsPlayerDead(PlayerId()) then
|
||||
|
||||
if not isInVehicle and not IsPlayerDead(ESX.playerId) then
|
||||
if DoesEntityExist(GetVehiclePedIsTryingToEnter(playerPed)) and not isEnteringVehicle then
|
||||
-- trying to enter a vehicle!
|
||||
local vehicle = GetVehiclePedIsTryingToEnter(playerPed)
|
||||
@@ -89,7 +89,7 @@ CreateThread(function()
|
||||
ToggleVehicleStatus(current.vehicle, current.seat)
|
||||
end
|
||||
elseif isInVehicle then
|
||||
if (current.vehicle ~= GetVehiclePedIsUsing(playerPed)) or IsPlayerDead(PlayerId()) then
|
||||
if (current.vehicle ~= GetVehiclePedIsUsing(playerPed)) or IsPlayerDead(ESX.playerId) then
|
||||
-- bye, vehicle
|
||||
TriggerEvent("esx:exitedVehicle", current.vehicle, current.plate, current.seat, current.displayName, current.netId)
|
||||
TriggerServerEvent("esx:exitedVehicle", current.plate, current.seat, current.displayName, current.netId)
|
||||
|
||||
@@ -6,7 +6,7 @@ AddEventHandler("gameEventTriggered", function(event, data)
|
||||
if not IsPedAPlayer(victim) then
|
||||
return
|
||||
end
|
||||
local player = PlayerId()
|
||||
local player = ESX.playerId
|
||||
local playerPed = PlayerPedId()
|
||||
if victimDied and NetworkGetPlayerIndexFromPed(victim) == player and (IsPedDeadOrDying(victim, true) or IsPedFatallyInjured(victim)) then
|
||||
local killerEntity, deathCause = GetPedSourceOfDeath(playerPed), GetPedCauseOfDeath(playerPed)
|
||||
|
||||
@@ -19,7 +19,7 @@ CreateThread(function()
|
||||
while not ESX.PlayerLoaded do
|
||||
Wait(100)
|
||||
|
||||
if NetworkIsPlayerActive(ESX.PlayerData.playerId) then
|
||||
if NetworkIsPlayerActive(ESX.playerId) then
|
||||
DisableSpawnManager()
|
||||
DoScreenFadeOut(0)
|
||||
|
||||
@@ -67,4 +67,4 @@ if Config.Relog then
|
||||
|
||||
end
|
||||
end,false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ end
|
||||
function Multicharacter:ResetHideActivePlayer()
|
||||
self.playerPed = PlayerPedId()
|
||||
|
||||
MumbleSetVolumeOverride(ESX.PlayerData.playerId, -1.0)
|
||||
MumbleSetVolumeOverride(ESX.playerId, -1.0)
|
||||
SetEntityVisible(self.playerPed, true, false)
|
||||
SetPlayerInvincible(self.playerPed, true)
|
||||
FreezeEntityPosition(self.playerPed, false)
|
||||
@@ -66,7 +66,7 @@ function Multicharacter:HideActivePlayerLoop()
|
||||
|
||||
SetEntityVisible(self.playerPed, false, false)
|
||||
SetLocalPlayerVisibleLocally(true)
|
||||
SetPlayerInvincible(ESX.PlayerData.playerId, true)
|
||||
SetPlayerInvincible(ESX.playerId, true)
|
||||
|
||||
HideComponents()
|
||||
|
||||
@@ -93,7 +93,7 @@ function Multicharacter:ConcealLoop()
|
||||
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
if player ~= ESX.PlayerData.playerId and not playerPool[player] then
|
||||
if player ~= ESX.playerId and not playerPool[player] then
|
||||
playerPool[player] = true
|
||||
NetworkConcealPlayer(player, true, true)
|
||||
end
|
||||
@@ -112,7 +112,7 @@ end
|
||||
function Multicharacter:StartLoops()
|
||||
self.hidePlayers = true
|
||||
|
||||
MumbleSetVolumeOverride(ESX.PlayerData.playerId, 0.0)
|
||||
MumbleSetVolumeOverride(ESX.playerId, 0.0)
|
||||
self:HideActivePlayerLoop()
|
||||
self:ConcealLoop()
|
||||
end
|
||||
@@ -120,8 +120,6 @@ end
|
||||
function Multicharacter:SetupCharacters()
|
||||
ESX.PlayerLoaded = false
|
||||
ESX.PlayerData = {}
|
||||
ESX.PlayerData.playerId = PlayerId()
|
||||
ESX.PlayerData.serverId = GetPlayerServerId(ESX.PlayerData.playerId)
|
||||
|
||||
self.spawned = false
|
||||
self.cam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
|
||||
@@ -169,11 +167,11 @@ end
|
||||
function Multicharacter:ChangeExistingPed()
|
||||
local newCharacter = self.Characters[self.tempIndex]
|
||||
local spawnedCharacter = self.Characters[self.spawned]
|
||||
|
||||
|
||||
if spawnedCharacter and spawnedCharacter.model then
|
||||
local model = ESX.Streaming.RequestModel(newCharacter.model)
|
||||
if model then
|
||||
SetPlayerModel(ESX.PlayerData.playerId, newCharacter.model)
|
||||
SetPlayerModel(ESX.playerId, newCharacter.model)
|
||||
SetModelAsNoLongerNeeded(newCharacter.model)
|
||||
end
|
||||
end
|
||||
@@ -265,7 +263,7 @@ function Multicharacter:SetDefaultSkin(playerData)
|
||||
return
|
||||
end
|
||||
|
||||
SetPlayerModel(ESX.PlayerData.playerId, model)
|
||||
SetPlayerModel(ESX.playerId, model)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
self.playerPed = PlayerPedId()
|
||||
|
||||
@@ -333,4 +331,4 @@ function Multicharacter:PlayerLoaded(playerData, isNew, skin)
|
||||
TriggerEvent("esx:restoreLoadout")
|
||||
|
||||
self:Reset()
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user