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