From b38426245c258f8c089863b8bdb21f0e483129b5 Mon Sep 17 00:00:00 2001 From: jenz Date: Thu, 1 Feb 2024 17:39:53 +0100 Subject: [PATCH] fixed client crash by adding delay to setting speed and health --- ZombieRiot/scripting/unloze_zr.sp | 107 ++++++++++++++++++------------ 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/ZombieRiot/scripting/unloze_zr.sp b/ZombieRiot/scripting/unloze_zr.sp index be124037..94f73903 100644 --- a/ZombieRiot/scripting/unloze_zr.sp +++ b/ZombieRiot/scripting/unloze_zr.sp @@ -44,6 +44,7 @@ char g_cWeaponCommand[g_dIndexes][g_dLength]; int g_iLength = g_dLength - 1; int g_iWave; +int g_iSpeedDelayClient[MAXPLAYERS + 1]; float g_iZMScaleability; int g_iZMCount; int g_iToolsVelocity; //from zombie reloaded @@ -589,8 +590,8 @@ public void ZmarketGetWeapon(int client, int index) CS_DropWeapon(client, l_iWeapon, false, true); AcceptEntityInput(l_iWeapon, "Kill"); } - DispatchKeyValueInt(l_iEntity, "ammo", 4500); TeleportEntity(l_iEntity, l_fClientPos, NULL_VECTOR, NULL_VECTOR); + DispatchKeyValueInt(l_iEntity, "ammo", 4500); DispatchSpawn(l_iEntity); SetEntProp(client, Prop_Send, "m_iAccount", l_iClientCash - g_iWeaponPrice[index]); PrintToChat(client, "you purchased: %s", g_cWeaponNames[index][g_iLength]); @@ -995,6 +996,7 @@ public Action Timer_FixKNife(Handle timer, any userid) //---------------------------------------------------------------------------------------------------- public void OnClientPostAdminCheck(int client) { + g_iSpeedDelayClient[client] = 0; g_bClientProtection[client] = false; g_bFallDamage[client] = false; g_fKnockBackIndex[client] = 1.0; @@ -1049,6 +1051,7 @@ public void SetAdminGroups(int client) //---------------------------------------------------------------------------------------------------- public void OnClientDisconnect(int client) { + g_iSpeedDelayClient[client] = 0; g_bClientProtection[client] = false; g_bFallDamage[client] = false; g_fKnockBackIndex[client] = 1.0; @@ -1462,6 +1465,7 @@ public Action SelectWaveBasedZM(int client, int state) { ChangeClientTeam(client, CS_TEAM_T); //default putting bots to t CreateTimer(1.0, Timer_delayedRespawn, GetClientUserId(client)); + return Plugin_Handled; } //state 0 was bot, state 1 was real player. if (!IsValidClient(client)) @@ -1550,8 +1554,10 @@ public Action ModelSelection(int client, int state, int modelIndex) g_bFallDamage[client] = true; else g_bFallDamage[client] = false; - //setting the class speed simply. - SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", StringToFloat(g_cSpeed[i][g_iLength])); + g_iSpeedDelayClient[client] = i; + + //setting this shit with a delay because it otherwise causes client crashes. + CreateTimer(3.0, Timer_SetSpeed, GetClientUserId(client)); if (state < 2) { CreateTimer(g_fZMSpawnProtection, Timer_StopProtection, GetClientUserId(client)); @@ -1560,22 +1566,6 @@ public Action ModelSelection(int client, int state, int modelIndex) { CreateTimer(g_fHumanSpawnProtection, Timer_StopProtection, GetClientUserId(client)); } - if (state < 2) //setting the zombie health here using the HealthScaleAbility. - { - int l_iPlayers; - for (int j = 1; j <= MaxClients; j++) - { - if (IsValidClient(j) && !IsFakeClient(j) && CS_TEAM_CT == GetClientTeam(j)) - { - l_iPlayers++; - } - } - l_iPlayers -= 1; //first player indicates the full health of the class, each additional uses scaleability health. - int additional_zombie_health_per_player = RoundFloat(g_fZMHealthScaleability * StringToInt(g_cHealth[i][g_iLength])); - SetEntityHealth(client, StringToInt(g_cHealth[i][g_iLength]) + (additional_zombie_health_per_player * l_iPlayers)); - } - else - SetEntityHealth(client, StringToInt(g_cHealth[i][g_iLength])); g_fKnockBackIndex[client] = StringToFloat(g_cKnockback[i][g_iLength]); g_fJumpHeightIndex[client] = StringToFloat(g_cJumpHeight[i][g_iLength]); g_fJumpDistanceIndex[client] = StringToFloat(g_cJumpDistance[i][g_iLength]); @@ -1649,30 +1639,63 @@ public Action Timer_zombieSounds(Handle timer, any userid) //---------------------------------------------------------------------------------------------------- public Action Timer_Respawn(Handle timer, any userid) { - int client = GetClientOfUserId(userid); - if (client == 0) - return Plugin_Continue; - - if (!IsValidClient(client) || IsPlayerAlive(client) || (GetClientTeam(client) != CS_TEAM_T && GetClientTeam(client) != CS_TEAM_CT)) - { - return Plugin_Continue; - } + int client = GetClientOfUserId(userid); + if (client == 0) + return Plugin_Continue; + + if (!IsValidClient(client) || IsPlayerAlive(client) || (GetClientTeam(client) != CS_TEAM_T && GetClientTeam(client) != CS_TEAM_CT)) + { + return Plugin_Continue; + } - UpdateWaveCount(client); - if (!IsFakeClient(client) && g_iClientRespawnCount[client] < 1) - { - ChangeClientTeam(client, CS_TEAM_T); //ran out of respawns for CT - } - else if (IsFakeClient(client) && GetClientTeam(client) != CS_TEAM_T) - { - ChangeClientTeam(client, CS_TEAM_T); - } - else if (!IsFakeClient(client) && GetClientTeam(client) != CS_TEAM_CT) - { - ChangeClientTeam(client, CS_TEAM_CT); //default putting humans to CT team - } - CS_RespawnPlayer(client); - return Plugin_Continue; + UpdateWaveCount(client); + if (!IsFakeClient(client) && g_iClientRespawnCount[client] < 1) + { + ChangeClientTeam(client, CS_TEAM_T); //ran out of respawns for CT + } + else if (IsFakeClient(client) && GetClientTeam(client) != CS_TEAM_T) + { + ChangeClientTeam(client, CS_TEAM_T); + } + else if (!IsFakeClient(client) && GetClientTeam(client) != CS_TEAM_CT) + { + ChangeClientTeam(client, CS_TEAM_CT); //default putting humans to CT team + } + CreateTimer(1.0, Timer_delayedRespawn, GetClientUserId(client)); + return Plugin_Continue; +} + +//this shit has to be delayed because it otherwise causes client crashes +public Action Timer_SetSpeed(Handle timer, any userid) +{ + int client = GetClientOfUserId(userid); + if (client == 0) + return Plugin_Continue; + if (IsValidClient(client) && IsPlayerAlive(client) && g_iSpeedDelayClient[client] != 0) + { + //setting the class speed simply. + SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", StringToFloat(g_cSpeed[g_iSpeedDelayClient[client]][g_iLength])); + + if (GetClientTeam(client) == CS_TEAM_T) //setting the zombie health here using the HealthScaleAbility. + { + int l_iPlayers; + for (int j = 1; j <= MaxClients; j++) + { + if (IsValidClient(j) && !IsFakeClient(j) && CS_TEAM_CT == GetClientTeam(j)) + { + l_iPlayers++; + } + } + l_iPlayers -= 1; //first player indicates the full health of the class, each additional uses scaleability health. + int additional_zombie_health_per_player = RoundFloat(g_fZMHealthScaleability * StringToInt(g_cHealth[g_iSpeedDelayClient[client]][g_iLength])); + SetEntityHealth(client, StringToInt(g_cHealth[g_iSpeedDelayClient[client]][g_iLength]) + (additional_zombie_health_per_player * l_iPlayers)); + } + else if (CS_TEAM_CT == GetClientTeam(client)) + { + SetEntityHealth(client, StringToInt(g_cHealth[g_iSpeedDelayClient[client]][g_iLength])); + } + } + return Plugin_Handled; } //---------------------------------------------------------------------------------------------------- // Purpose: