Other than using AddEventHandler playerSpawned .. what option do i have?

Beside

AddEventHandler('playerSpawned', function(spawn)

which load too early for my specific use… (it start at my multi char menu selector and trigger too soon)… and i dont want to use a Wait command inside the AddEventHandler.

Is there a native somewhere that wait until the player is able to move… the real spawn where you actually control your ped. ?

Maybe checking if the peds coords are moving then triggering a “real spawn” function… or something better… i would really appreciate someone pointing me in the right direction

1 Like

This sentence is confusing, are you trying to open your char menu selector on the right time or are you trying to trigger something after your char select?

oups sorry, i meant the second one,
the KASHacter script run… and i need to trigger after the selection…

Couldn’t you just edit the KASHacter script to trigger you event after character selection?

It related around an exchange between my client and server… it is mass spamming my console…

and server side

Keeping the client side feed with accurate money, black money and bank…
I need to start that somewhere after the player selection… but if i do now, it generate errors because a part of the ESX is not loaded yet… and as soon as i can move a player on ground, the variables are updated, the errors stops… and everything work… but its annoying me that the console is flooded.

hard to explain quickly :slight_smile:

Everything start with the function

function UpdatePlayerMoney() 

but i need to find where to start it… so ESX is finished loading… and can handle this exchange

Isn’t there like an esx:playerloaded event

maybe but that is where my knowledge in lua ends and why i came here for pro tips…
i’ll investigate esx:playerloaded event

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
  PlayerData = xPlayer
  UpdatePlayerMoney()
end)

testing…

nope, still mass spamming
attempt to index a nil value (local ‘xPlayer’)
until the player hit the ground.

will retry a 2nd restart, redeleting the cache again… for luck… or my syntax is wrong

I took the easy way out… until i fall on a piece of code that i can run outside the kashacter script… or i will make a “if the player move” then trigger… unless you spawn inside a car seated, that could work…
at least the console is clean until better way came out

RegisterNUICallback("CharacterChosen", function(data, cb)
    SetNuiFocus(false,false)
    DoScreenFadeOut(500)
    TriggerServerEvent('kashactersS:CharacterChosen', data.charid, data.ischar)
    while not IsScreenFadedOut() do
        Citizen.Wait(10)
    end
    TriggerServerEvent('esx_burn:AskServer_UpdatePlayerMoney')  <----------
    cb("ok")
end)
2 Likes

It is spamming Nil because esx hasn’t loaded when it try’s to get to that part of the script I would think. For a project I was working the script was checking for the job name before esx would finish loading. Adding a check at the top when esx loads to make sure job is not nil fixed the issue and now waits till esx loads and then sets job name.

You could try this:

Citizen.CreateThread(function()
    while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
	while ESX.GetPlayerData().job == nil do
		Citizen.Wait(10)
	end
	    PlayerData = ESX.GetPlayerData()
end)

This solved one of my problems of a nil value from xPlayer on load not sure if it will help yours or not

yeah i already tried… it is exactly how it look like as of now…


Thank you for your suggestion tho… anything is very welcome

EDIT: well there is this ----> ESX.GetPlayerData().job vs ESX.GetPlayerData()

If you’re just wanting to do something after the player has loaded in and selected a character, just add onto your character script to fire a client and/or server event that you can handle wherever you need it.