The Given key was not present in the dictionary

ive revived a nostalgic old mobile game and ive converted the offline dead servers from smart fox to photon and everything seems to work but one mode in the game doesnt work at all here is a code snippet public void BirthPlayer(PhotonPlayer player) { if (!SFS_Player_Arr.ContainsKey(player)) { Multiplayer multiplayer = new Multiplayer(player.ID); multiplayer.InitAvatar((AvatarType)player.customProperties["avatarType"], (uint)(int)player.customProperties["birthPoint"]); multiplayer.InitWeaponList((int)player.customProperties["weapon1"], (int)player.customProperties["weapon2"], (int)player.customProperties["weapon3"]); SFS_Player_Arr.Add(player, multiplayer); multiplayer.nick_name = (string)player.customProperties["nickname"]; multiplayer.Init(); multiplayer.ChangeWeaponWithindex((int)player.customProperties["weaponNum"]); } } public void InitializePlayer(PhotonPlayer player) { // Check if the player is already added, if not, add them BirthPlayer(player); }
public void OnPlayerJoin(PhotonPlayer newPlayer) { InitializePlayer(newPlayer); } public override void DoLogic(float deltaTime) { if (!is_game_excute) { return; } player.DoLogic(deltaTime); if (!is_game_over && PhotonNetwork.isMasterClient) { object[] array = new object[enemyList.Count]; enemyList.Keys.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { Enemy enemy = enemyList[array[i]] as Enemy; enemy.DoLogic(deltaTime);
7 Replies
Angius
Angius4d ago
$code
MODiX
MODiX4d ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
toon link on crack
$codegif
toon link on crack
public void BirthPlayer(PhotonPlayer player)
{
if (!SFS_Player_Arr.ContainsKey(player))
{
Multiplayer multiplayer = new Multiplayer(player.ID);
multiplayer.InitAvatar((AvatarType)player.customProperties["avatarType"], (uint)(int)player.customProperties["birthPoint"]);
multiplayer.InitWeaponList((int)player.customProperties["weapon1"], (int)player.customProperties["weapon2"], (int)player.customProperties["weapon3"]);
SFS_Player_Arr.Add(player, multiplayer);
multiplayer.nick_name = (string)player.customProperties["nickname"];
multiplayer.Init();
multiplayer.ChangeWeaponWithindex((int)player.customProperties["weaponNum"]);
}
}
public void InitializePlayer(PhotonPlayer player)
{
// Check if the player is already added, if not, add them
BirthPlayer(player);
}

public void OnPlayerJoin(PhotonPlayer newPlayer)
{
InitializePlayer(newPlayer);
}

public override void DoLogic(float deltaTime)
{
if (!is_game_excute)
{
return;
}
player.DoLogic(deltaTime);
if (!is_game_over && PhotonNetwork.isMasterClient)
{
object[] array = new object[enemyList.Count];
enemyList.Keys.CopyTo(array, 0);
for (int i = 0; i < array.Length; i++)
{
Enemy enemy = enemyList[array[i]] as Enemy;
enemy.DoLogic(deltaTime);
public void BirthPlayer(PhotonPlayer player)
{
if (!SFS_Player_Arr.ContainsKey(player))
{
Multiplayer multiplayer = new Multiplayer(player.ID);
multiplayer.InitAvatar((AvatarType)player.customProperties["avatarType"], (uint)(int)player.customProperties["birthPoint"]);
multiplayer.InitWeaponList((int)player.customProperties["weapon1"], (int)player.customProperties["weapon2"], (int)player.customProperties["weapon3"]);
SFS_Player_Arr.Add(player, multiplayer);
multiplayer.nick_name = (string)player.customProperties["nickname"];
multiplayer.Init();
multiplayer.ChangeWeaponWithindex((int)player.customProperties["weaponNum"]);
}
}
public void InitializePlayer(PhotonPlayer player)
{
// Check if the player is already added, if not, add them
BirthPlayer(player);
}

public void OnPlayerJoin(PhotonPlayer newPlayer)
{
InitializePlayer(newPlayer);
}

public override void DoLogic(float deltaTime)
{
if (!is_game_excute)
{
return;
}
player.DoLogic(deltaTime);
if (!is_game_over && PhotonNetwork.isMasterClient)
{
object[] array = new object[enemyList.Count];
enemyList.Keys.CopyTo(array, 0);
for (int i = 0; i < array.Length; i++)
{
Enemy enemy = enemyList[array[i]] as Enemy;
enemy.DoLogic(deltaTime);
Angius
Angius4d ago
Where does the error happen?
toon link on crack
bascially the key or photon player is not in the SFS_Player_Arr dictionary. this happens when 1 player tries to revive the other but it cant because it cant find the photon player or key in the dictionary causing this error for refrence here is the unity console KeyNotFoundException: The given key was not present in the dictionary. System.Collections.Generic.Dictionary`2[PhotonPlayer,Zombie3D.Player].get_Item (.PhotonPlayer key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150) Zombie3D.GameMultiplayerScene.HandleEvent (.ServerEventData data) (at Assets/Scripts/Assembly-CSharp/Zombie3D/GameMultiplayerScene.cs:222) PunCallback.OnServerEvent (.ServerEventData data) (at Assets/Scripts/Assembly-CSharp/PunCallback.cs:85) PunCallback.OnEvent (Byte eventCode, System.Object content, Int32 senderId) (at Assets/Scripts/Assembly-CSharp/PunCallback.cs:66) NetworkingPeer
Want results from more Discord servers?
Add your server