Skip to content

Commit

Permalink
Fix for the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
NotZer0Two committed Aug 22, 2024
1 parent b0416c7 commit 5c5feb4
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions EXILED/Exiled.API/Features/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,34 +133,21 @@ public Npc(GameObject gameObject)
/// <param name="userId">The userID of the NPC.</param>
/// <param name="position">The position to spawn the NPC.</param>
/// <returns>The <see cref="Npc"/> spawned.</returns>
public static Npc Spawn(string name, RoleTypeId role, int id = 0, string userId = "", Vector3? position = null)
public static Npc Spawn(string name, RoleTypeId role, int id = 0, string userId = PlayerAuthenticationManager.DedicatedId, Vector3? position = null)
{
GameObject newObject = Object.Instantiate(NetworkManager.singleton.playerPrefab);
GameObject newObject = UnityEngine.Object.Instantiate(Mirror.NetworkManager.singleton.playerPrefab);

Npc npc = new(newObject)
{
IsVerified = userId != PlayerAuthenticationManager.DedicatedId && userId != null,
IsNPC = true,
};

try
{
npc.ReferenceHub.roleManager.InitializeNewRole(RoleTypeId.None, RoleChangeReason.None);
}
catch (Exception e)
{
Log.Debug($"Ignore: {e}");
}

if (!RecyclablePlayerId.FreeIds.Contains(id) && RecyclablePlayerId._autoIncrement >= id)
{
Log.Warn($"{Assembly.GetCallingAssembly().GetName().Name} tried to spawn an NPC with a duplicate PlayerID. Using auto-incremented ID instead to avoid issues.");
id = new RecyclablePlayerId(false).Value;
id = new RecyclablePlayerId(true).Value;
}

FakeConnection fakeConnection = new(id);
NetworkServer.AddPlayerForConnection(fakeConnection, newObject);

try
{
if (userId == PlayerAuthenticationManager.DedicatedId)
Expand All @@ -172,7 +159,7 @@ public static Npc Spawn(string name, RoleTypeId role, int id = 0, string userId
}
catch (Exception e)
{
Log.Debug($"Ignore: {e}");
Log.Debug($"Ignore: {e.Message}");
}
}
else
Expand All @@ -182,9 +169,21 @@ public static Npc Spawn(string name, RoleTypeId role, int id = 0, string userId
}
catch (Exception e)
{
Log.Debug($"Ignore: {e}");
Log.Debug($"Ignore: {e.Message}");
}

try
{
npc.ReferenceHub.roleManager.InitializeNewRole(RoleTypeId.None, RoleChangeReason.None);
}
catch (Exception e)
{
Log.Debug($"Ignore: {e.Message}");
}

FakeConnection fakeConnection = new(id);
NetworkServer.AddPlayerForConnection(fakeConnection, newObject);

npc.ReferenceHub.nicknameSync.Network_myNickSync = name;
Dictionary.Add(newObject, npc);

Expand Down

0 comments on commit 5c5feb4

Please sign in to comment.