Hi,

I have a problem on my server. The first person connected does not see the second person while the second person sees the first. I may have been poorly expressed so here are two pictures (Maxime6678 is the first person).

I stubbornly took over the spawnmanager in lua that I converted to C #. Here it is:

using CitizenFX.Core;
using System.Threading.Tasks;
using static CitizenFX.Core.Native.API;

namespace AlesiaClient.Managers
{
    public class SpawnManager : BaseScript
    {
        private static bool _spawnLock = false;

        public static void FreezePlayer(int playerId, bool freeze)
        {
            var ped = GetPlayerPed(playerId);

            SetPlayerControl(playerId, !freeze, 0);

            if (!freeze)
            {
                SetEntityVisible(ped, true, true);
                SetEntityCollision(ped, true, true);
                FreezeEntityPosition(ped, false);
                //SetCharNeverTargetted(ped, false)
                SetPlayerInvincible(playerId, false);
            }
            else
            {
                SetEntityVisible(ped, false, false);
                SetEntityCollision(ped, false, true);
                FreezeEntityPosition(ped, true);
                //SetCharNeverTargetted(ped, true)
                SetPlayerInvincible(playerId, true);
                if (IsPedFatallyInjured(ped))
                    ClearPedTasksImmediately(ped);
            }
        }

        public static async Task SpawnPlayer(string skin, float x, float y, float z, float heading)
        {
            if (_spawnLock)
                return;

            _spawnLock = true;
            uint spawnModel = (uint)GetHashKey(skin);

            DoScreenFadeOut(500);

            while (IsScreenFadingOut())
            {
                await Delay(1);
            }

            FreezePlayer(PlayerId(), true);
            RequestModel(spawnModel);

            while (!HasModelLoaded(spawnModel))
            {
                RequestModel(spawnModel);
                await Delay(1);
            }

            SetPlayerModel(PlayerId(), spawnModel);
            SetModelAsNoLongerNeeded(spawnModel);
            SetPedDefaultComponentVariation(GetPlayerPed(-1));
            RequestCollisionAtCoord(x, y, z);

            var ped = GetPlayerPed(-1);

            SetEntityCoordsNoOffset(ped, x, y, z + 0.00001F, false, false, false);
            NetworkResurrectLocalPlayer(x, y, z + 0.00001F, heading, true, true);
            ClearPedTasksImmediately(ped);
            RemoveAllPedWeapons(ped, false);
            ClearPlayerWantedLevel(PlayerId());

            while (!HasCollisionLoadedAroundEntity(ped))
            {
                await Delay(1);
            }

            ShutdownLoadingScreen();
            DoScreenFadeIn(500);

            while (IsScreenFadingIn())
            {
                await Delay(1);
            }

            FreezePlayer(PlayerId(), false);

            //TriggerEvent("playerSpawned", PlayerId());

            _spawnLock = false;
        }
    }
}

Thanks for help

Call this on the ped when it spawns

SET_PED_DEFAULT_COMPONENT_VARIATION

It’s already call —

Hm. I missed that call. No idea why its doing that.

I know it’s in the original lua code, but while you’re at it, never request a model in a while loop, so change

while (!HasModelLoaded(spawnModel))
{
         RequestModel(spawnModel);
         await Delay(1);
}

to

RequestModel(spawnModel);
while (!HasModelLoaded(spawnModel))
{
        await Delay(1);
}

This might even alleviate the issue.

Have you solved this?, this happened to me the first time i started a server with no resources and a manual spawn, the guilty is the session manager, is loaded by default but you need to load it anyway, is the only must-have resource file you need to have a blank server working propertly.

No I didn’t find a solution. I notice you if I find

public static void FreezePlayer(int playerId, bool freeze)

if (!freeze) replace on if (freeze)