From 962d6ce67f932941babcdf97197c15e7827cace2 Mon Sep 17 00:00:00 2001 From: jenz Date: Tue, 30 Jan 2024 16:16:48 +0100 Subject: [PATCH] changed check to see if bots actually spawned in, instead of checking if player spawned in. removed timer that removes weapons and use a hook instead --- ZombieRiot/scripting/unloze_zr.sp | 91 +++++++++++++++++++------------ 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/ZombieRiot/scripting/unloze_zr.sp b/ZombieRiot/scripting/unloze_zr.sp index 9d22f258..b2446bc6 100644 --- a/ZombieRiot/scripting/unloze_zr.sp +++ b/ZombieRiot/scripting/unloze_zr.sp @@ -156,20 +156,22 @@ public void OnPluginStart() public Action Timer_CheckIfRestartNeeded(Handle timer, any userid) { - int activePlayers = 0; + //the bots dont spawn right away. therefore we have the 6 seconds delay for them to actually spawn in. + int activeBots = 0; for (int i = 1; i < MaxClients; i++) { - if (IsValidClient(i) && (GetClientTeam(i) == CS_TEAM_CT || GetClientTeam(i) == CS_TEAM_T)) + if (IsValidClient(i) && IsFakeClient(i) && !IsClientSourceTV(i)) { - activePlayers++; + activeBots++; } - if (activePlayers > 1) + if (activeBots > 0) { break; } } - if (activePlayers == 1) + if (activeBots == 0) { + //bots did still not spawn. we need the restart to spawn them in. PrintToChatAll("First Player joining. Restarting the round..."); CS_TerminateRound(4.0, CSRoundEnd_Draw, true); } @@ -178,27 +180,46 @@ public Action Timer_CheckIfRestartNeeded(Handle timer, any userid) public Action ApplySettings(Event event, const char[] name, bool dontBroadcast) { - int activePlayers = 0; + int activeBots = 0; for (int i = 1; i < MaxClients; i++) { - if (IsValidClient(i) && (GetClientTeam(i) == CS_TEAM_CT || GetClientTeam(i) == CS_TEAM_T)) + if (IsValidClient(i) && IsFakeClient(i) && !IsClientSourceTV(i)) { - activePlayers++; + activeBots++; } - if (activePlayers > 1) + if (activeBots > 0) { break; } } - if (activePlayers == 1) + if (activeBots == 0) { - CreateTimer(10.0, Timer_CheckIfRestartNeeded); + CreateTimer(10.0, Timer_CheckIfRestartNeeded); //if only one guy is on a team we force a restart to spawn the bots. } + + int client = GetClientOfUserId(event.GetInt("userid")); if (!IsValidClient(client) || !IsPlayerAlive(client) || IsClientSourceTV(client)) { return Plugin_Handled; } + + //when zombies spawn remove every weapon they have except of knife. When their spawn protection runs out we also check if they have a knife. + int l_iWeapon; + if (GetClientTeam(client) == CS_TEAM_T) + { + for (int i = 0; i < 5; i++) + { + l_iWeapon = GetPlayerWeaponSlot(client, i); + if (l_iWeapon != -1 && i != 2) + { + RemovePlayerItem(client, l_iWeapon); + } + } + } + + //removing guns from zombies when they spawn. + if (!IsFakeClient(client) && g_iClientRespawnCount[client] < 1) //player ran out of human respawns and will be zm instead. { SelectWaveBasedZM(client, 1); @@ -844,7 +865,6 @@ public void OnMapStart() LoadClasses(); LoadExtraSettings(); loadWeapons(); - CreateTimer(0.5, Timer_restrictWeapons, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); CreateTimer(2.0, Timer_CheckIfBotsStuck, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); CreateTimer(g_fZMSounds, Timer_zombieSounds, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); } @@ -880,8 +900,14 @@ public void OnClientPostAdminCheck(int client) g_iClientHumanClasses[client] = 0; } SetAdminGroups(client); - SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); } + +public void OnClientPutInServer(int client) +{ + SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); + SDKHook(client, SDKHook_WeaponEquip, OnWeaponEquip); +} + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -909,6 +935,7 @@ public void OnClientDisconnect(int client) g_fDamageMultiplier[client] = 1.0; g_iClientRespawnCount[client] = 0; SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage); + SDKUnhook(client, SDKHook_WeaponEquip, OnWeaponEquip); } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -1594,28 +1621,6 @@ public Action ModelSelection(int client, int state, int modelIndex) //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- -public Action Timer_restrictWeapons(Handle timer, any userid) -{ - int l_iWeapon; - for(int j = 1; j <= MaxClients; j++) - { - if (IsValidClient(j) && GetClientTeam(j) == CS_TEAM_T) - { - for (int i = 0; i < 5; i++) - { - l_iWeapon = GetPlayerWeaponSlot(j, i); - if (l_iWeapon != -1 && i != 2) - { - RemovePlayerItem(j, l_iWeapon); - } - } - } - } - return Plugin_Handled; -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action Timer_CheckIfBotsStuck(Handle timer, any userid) { float l_fClientVelocity[3]; @@ -1831,6 +1836,22 @@ public Action OnTakeDamage(int client, int &attacker, int &inflictor, float &dam } return Plugin_Continue; } + +//why do retards suggest using OnWeaponCanUse instead when its not even stopping zombies from using weapons that you drop to them. +public Action OnWeaponEquip(int client, int weapon) +{ + if (GetClientTeam(client) == CS_TEAM_T) + { + char sWeapon[64]; + GetEdictClassname(weapon, sWeapon, sizeof(sWeapon)); + if(!StrEqual(sWeapon, "weapon_knife")) + { + return Plugin_Handled; + } + } + return Plugin_Continue; +} + //---------------------------------------------------------------------------------------------------- // Purpose: zombie reloaded copied knockback //----------------------------------------------------------------------------------------------------