[HELP] ESX - How can i trigger a event after the player spawn

I always fall over the map several times before spawning.

PS: I really need a way to freeze player for loading interiors also… Is there any way please help me.

Can someone have any solution?

This will only trigger your event on the first spawn of the player.
client:

firstSpawn = true
AddEventHandler('playerSpawned', function()
   if firstSpawn then
       -- trigger your event here
       firstSpawn = false
   end
end)
2 Likes

Nice, Is there a way to freeze player to make the map load and unfreeze.

firstSpawn = true
AddEventHandler('playerSpawned', function()
    if firstSpawn then
        local ped = GetPlayerPed(-1)
        FreezeEntityPosition(ped, true)

        -- trigger your event here / or whatever you need to load the map / Citizen.Wait instruction etc

        FreezeEntityPosition(ped, false)
        firstSpawn = false
    end
end)

Something like this. Untested but it should work.

How to understand the map loaded 100%, I mean the GTA V map not any custom map. So i can trigger unfreeze?

The character keep falling the world, because of the map not loading on spawn

I don’t really understand what you’re trying to say, sorry… :confused:

I think he wants to freeze a player until the map loads for the client. Might be a client side script as several variables affect the maps loading time.

In that case, I think something like this could work? Again, this is not tested.

firstSpawn = true
AddEventHandler('playerSpawned', function()
    if firstSpawn then
        local ped = GetPlayerPed(-1)    -- get local ped
        FreezeEntityPosition(ped, true)   -- freeze player

        -- trigger your event here / or whatever you need to load the map / Citizen.Wait instruction etc

        LoadAllObjectsNow()
        Citizen.Wait(5000)  -- 5 seconds
        FreezeEntityPosition(ped, false)   -- unfreeze player
        firstSpawn = false
    end
end)

You could also use the HasCollisionLoadedAroundEntity native