diff --git a/ZombieRiot/scripting/unloze_zr.sp b/ZombieRiot/scripting/unloze_zr.sp index 1e5a25bc..8eef2610 100644 --- a/ZombieRiot/scripting/unloze_zr.sp +++ b/ZombieRiot/scripting/unloze_zr.sp @@ -42,7 +42,7 @@ char g_cWeaponCommand[g_dIndexes][g_dLength]; int g_iLength = g_dLength - 1; int g_iWave; -int g_iZMScaleability; +float g_iZMScaleability; int g_iZMCount; int g_iToolsVelocity; //from zombie reloaded int g_iClientZMClasses[g_dIndexes]; @@ -72,11 +72,11 @@ float g_fBotStuckPush; bool g_bSwitchingIndex; bool g_bRoundInProgress; -bool g_bShouldBeHuman[g_dIndexes]; -bool g_bShouldBeZM[g_dIndexes]; bool g_bFallDamage[g_dIndexes]; bool g_bClientProtection[g_dIndexes]; +bool g_bRestartRound = true; + Handle g_hClientZMCookie; Handle g_hClientHumanCookie; @@ -115,7 +115,6 @@ public void OnPluginStart() HookEvent("player_spawn", ApplySettings, EventHookMode_Post); HookEvent("round_start", Event_roundStart, EventHookMode_Post); HookEvent("player_death", Event_OnPlayerDeath, EventHookMode_Post); - HookEvent("player_connect", Event_OnFullConnect, EventHookMode_Pre); HookEvent("player_hurt", EventPlayerHurt, EventHookMode_Pre); HookEvent("player_jump", EventPlayerJump, EventHookMode_Post); @@ -128,12 +127,58 @@ public void OnPluginStart() RegAdminCmd("sm_human", Cmd_Humanize, ADMFLAG_BAN); RegAdminCmd("sm_infect", Cmd_Zombienize, ADMFLAG_BAN); } + +public Action ApplySettings(Event event, const char[] name, bool dontBroadcast) +{ + int activePlayers = 0; + for (int i = 1; i < MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i) && (GetClientTeam(i) == CS_TEAM_CT || GetClientTeam(i) == CS_TEAM_T)) + { + activePlayers++; + } + if (activePlayers > 1) + { + break; + } + } + if (activePlayers == 1 && g_bRestartRound) + { + PrintToChatAll("First Player joining. Restarting the round..."); + g_bRestartRound = false; + CS_TerminateRound(4.0, CSRoundEnd_Draw, false); + } + else if (activePlayers == 0) + { + g_bRestartRound = true; + } + + + int client = GetClientOfUserId(event.GetInt("userid")); + if (!IsValidClient(client) || !IsPlayerAlive(client) || IsClientSourceTV(client)) + { + return Plugin_Handled; + } + if (!IsFakeClient(client) && g_iClientRespawnCount[client] < 1) //player ran out of human respawns and will be zm instead. + { + SelectWaveBasedZM(client, 1); + } + else if (IsFakeClient(client)) //bot getting respawned as zm + { + SelectWaveBasedZM(client, 0); + } + else + { + SelectWavebasedHuman(client); //player getting respawned as human + } + return Plugin_Handled; +} + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action Cmd_LoadManually(int client, int args) { - //LoadClasses(); AddDownloadContent(); return Plugin_Handled; } @@ -236,47 +281,50 @@ public Action Cmd_Say(int client, int args) //---------------------------------------------------------------------------------------------------- public Action InfectionSlashHumanHandling(int client, int args, int state) { - if (args < 1) - { - ReplyToCommand(client, "[SM] Usage: sm_human <#userid|name>"); - ReplyToCommand(client, "[SM] Usage: sm_infect <#userid|name>"); - return Plugin_Handled; - } - findTarget(client, state); - return Plugin_Continue; + if (args < 1) + { + ReplyToCommand(client, "[SM] Usage: sm_human <#userid|name>"); + ReplyToCommand(client, "[SM] Usage: sm_infect <#userid|name>"); + return Plugin_Handled; + } + findTarget(client, state); + return Plugin_Continue; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void findTarget(int client, int state) { - //state 0 human, state 1 zm - char target[MAX_NAME_LENGTH]; - char targetname[MAX_NAME_LENGTH]; - int targets[g_dLength]; - int result; - bool tn_is_ml; - GetCmdArg(1, target, sizeof(target)); - // Find a target. - result = ProcessTargetString(target, client, targets, sizeof(targets), COMMAND_FILTER_ALIVE , targetname, sizeof(targetname), tn_is_ml); - // Check if there was a problem finding a client. - if (result != 1) - { - PrintToChat(client, "Found no specific Target!"); - return; - } - if (state == 0) - { - PrintToChat(client, "Humanized: %N", targets[0]); - g_bShouldBeHuman[targets[0]] = true; - SelectWavebasedHuman(targets[0]); - } - else - { - PrintToChat(client, "Infected: %N", targets[0]); - g_bShouldBeZM[targets[0]] = true; - SelectWaveBasedZM(targets[0], 1); - } + //state 0 human, state 1 zm + char target[MAX_NAME_LENGTH]; + char targetname[MAX_NAME_LENGTH]; + int targets[g_dLength]; + int result; + bool tn_is_ml; + GetCmdArg(1, target, sizeof(target)); + // Find a target. + result = ProcessTargetString(target, client, targets, sizeof(targets), COMMAND_FILTER_ALIVE , targetname, sizeof(targetname), tn_is_ml); + // Check if there was a problem finding a client. + if (result != 1) + { + PrintToChat(client, "Found no specific Target!"); + return; + } + if (!IsPlayerAlive(targets[0])) + { + PrintToChat(client, "Target is not alive. Cant be turned human or zombie."); + return; + } + if (state == 0) + { + PrintToChat(client, "Humanized: %N", targets[0]); + SelectWavebasedHuman(targets[0]); + } + else + { + PrintToChat(client, "Infected: %N", targets[0]); + SelectWaveBasedZM(targets[0], 1); + } } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -519,7 +567,7 @@ public int Zombieclass_Menu(Menu menu, MenuAction action, int client, int select g_iClientZMClasses[client] = selection + g_iZMBeginindex; IntToString(g_iClientZMClasses[client], l_cInfo, sizeof(l_cInfo)); SetClientCookie(client, g_hClientZMCookie, l_cInfo); - if (g_bSwitchingIndex && GetClientTeam(client) == CS_TEAM_T) + if (g_bSwitchingIndex && GetClientTeam(client) == CS_TEAM_T && IsPlayerAlive(client)) //beginning of round, is correct team and alive { SelectWaveBasedZM(client, 1); } @@ -540,8 +588,9 @@ public int Humanclass_Menu(Menu menu, MenuAction action, int client, int selecti char l_cInfo[4]; IntToString(selection, l_cInfo, sizeof(l_cInfo)); SetClientCookie(client, g_hClientHumanCookie, l_cInfo); + g_iClientHumanClasses[client] = selection; - if (g_bSwitchingIndex && GetClientTeam(client) == CS_TEAM_CT) + if (g_bSwitchingIndex && GetClientTeam(client) == CS_TEAM_CT && IsPlayerAlive(client)) //beginning of round, is correct team and alive { SelectWavebasedHuman(client); } @@ -766,34 +815,33 @@ public void OnMapStart() //---------------------------------------------------------------------------------------------------- public void OnClientPostAdminCheck(int client) { - g_bClientProtection[client] = false; - g_bFallDamage[client] = false; - g_bShouldBeHuman[client] = false; - g_bShouldBeZM[client] = false; - g_fKnockBackIndex[client] = 1.0; - g_fJumpHeightIndex[client] = 1.0; - g_fJumpDistanceIndex[client] = 1.0; - g_iClientRespawnCount[client] = 0; - char sCookieValue[12]; - GetClientCookie(client, g_hClientZMCookie, sCookieValue, sizeof(sCookieValue)); - if (sCookieValue[0]) - { - g_iClientZMClasses[client] = StringToInt(sCookieValue); - } - else - { - g_iClientZMClasses[client] = g_iZMBeginindex; - } - GetClientCookie(client, g_hClientHumanCookie, sCookieValue, sizeof(sCookieValue)); - if (sCookieValue[0]) - { - g_iClientHumanClasses[client] = StringToInt(sCookieValue); - } - else - { - g_iClientHumanClasses[client] = 0; - } - SetAdminGroups(client); + g_bClientProtection[client] = false; + g_bFallDamage[client] = false; + g_fKnockBackIndex[client] = 1.0; + g_fJumpHeightIndex[client] = 1.0; + g_fJumpDistanceIndex[client] = 1.0; + g_iClientRespawnCount[client] = g_iClientRespawnCountNum; + char sCookieValue[12]; + GetClientCookie(client, g_hClientZMCookie, sCookieValue, sizeof(sCookieValue)); + if (sCookieValue[0]) + { + g_iClientZMClasses[client] = StringToInt(sCookieValue); + } + else + { + g_iClientZMClasses[client] = g_iZMBeginindex; + } + GetClientCookie(client, g_hClientHumanCookie, sCookieValue, sizeof(sCookieValue)); + if (sCookieValue[0]) + { + g_iClientHumanClasses[client] = StringToInt(sCookieValue); + } + else + { + g_iClientHumanClasses[client] = 0; + } + SetAdminGroups(client); + SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -816,8 +864,6 @@ public void OnClientDisconnect(int client) { g_bClientProtection[client] = false; g_bFallDamage[client] = false; - g_bShouldBeHuman[client] = false; - g_bShouldBeZM[client] = false; g_fKnockBackIndex[client] = 1.0; g_fJumpHeightIndex[client] = 1.0; g_fJumpDistanceIndex[client] = 1.0; @@ -840,27 +886,27 @@ public MRESReturn DHook_GetPlayerMaxSpeed(int client, Handle hReturn) //---------------------------------------------------------------------------------------------------- public void Event_roundStart(Handle event, const char[] name, bool dontBroadcast) { - int l_iHumanPlayers; - g_bRoundInProgress = false; - g_bSwitchingIndex = true; - CreateTimer(g_fSwitchingTimer, Timer_switchingModel, INVALID_HANDLE); - RetrieveWaveSettings(g_iWave); - for (int i = 1; i <= MaxClients; i++) - { - if (IsValidClient(i) && !IsClientSourceTV(i)) - { - if (IsFakeClient(i)) - { - SelectWaveBasedZM(i, 0); - } - else if (GetClientTeam(i) > CS_TEAM_SPECTATOR) - { - g_iClientRespawnCount[i] = g_iClientRespawnCountNum; - SelectWavebasedHuman(i); - l_iHumanPlayers++; - } - } - } + g_bRoundInProgress = false; + g_bSwitchingIndex = true; + CreateTimer(g_fSwitchingTimer, Timer_switchingModel, INVALID_HANDLE); + RetrieveWaveSettings(g_iWave); + + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsClientSourceTV(i)) + { + if (IsFakeClient(i)) + { + SelectWaveBasedZM(i, 0); + continue; + } + g_iClientRespawnCount[i] = g_iClientRespawnCountNum; //even if not spawned in yet it should be set for every real player. + if (IsPlayerAlive(i)) + { + SelectWavebasedHuman(i); + } + } + } } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -893,174 +939,187 @@ public Action Timer_switchingModel(Handle timer, any data) //---------------------------------------------------------------------------------------------------- public void LoadWave(int wave) { - KeyValues kv = CreateKeyValues("Waves"); - int l_iBotQuote; - char l_cJumptokey[16]; - char l_cJumptokey1[16]; - char l_cLine[g_dLength]; - bool l_bKeyIndex = false; - Handle l_hFile = INVALID_HANDLE; - l_hFile = OpenFile(g_cPathsWaveSettings, "r"); - Format(l_cJumptokey, sizeof(l_cJumptokey), "Wave %i", wave); - Format(l_cJumptokey1, sizeof(l_cJumptokey1), "Wave %i", wave +1); - for (int i = 0; i < g_dIndexes; i++) - { - Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), ""); - Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), ""); - } - kv.ImportFromFile(g_cPathsWaveSettings); - if (kv.JumpToKey(l_cJumptokey, false)) - { - g_bRoundInProgress = true; - g_iZMScaleability = kv.GetNum("PlayerScaleAbility", 5); - g_fZMHealthScaleability = kv.GetFloat("HealthScaleAbility", 1.0); - g_iZMCount = kv.GetNum("Zombie Count", 5); - if (g_iZMScaleability > 0) - { - g_iZMCount *= g_iZMScaleability; - } - g_iClientRespawnCountNum = kv.GetNum("Respawns", 5); - l_iBotQuote = kv.GetNum("bot_scaling", 1); - SettingBotQoute(l_iBotQuote); - while (!IsEndOfFile(l_hFile) && ReadFileLine(l_hFile, l_cLine, sizeof(l_cLine))) - { - if (StrContains(l_cLine, l_cJumptokey) == -1 && !l_bKeyIndex) - { - continue; - } - l_bKeyIndex = true; - if (StrContains(l_cLine, "wavecommand") > -1) - { - ReplaceStrings(l_cLine, "wavecommand"); - if (strlen(l_cLine) > 0) - ServerCommand(l_cLine); - } - else if (StrContains(l_cLine, "Zombie Class") > -1) - { - ReplaceStrings(l_cLine, "Zombie Class"); - if (StrContains(l_cLine, "@all") > -1) - { - for (int i = g_iZMBeginindex; i < g_iLoadClassesIndex; i++) - { - Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); - } - } - else if (StrContains(l_cLine, "@groups") > -1) - { - for (int i = 0; i < g_dIndexes; i++) - { - if (skipIndex(i)) - { - continue; - } - if ((strlen(g_cGroup[i][g_iLength]) > 0) && StrEqual(g_cTeam[i][g_iLength], "ZM")) - { - Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); - } - } - } - else if (StrContains(l_cLine, "@flags") > -1) - { - for (int i = 0; i < g_dIndexes; i++) - { - if (skipIndex(i)) - { - continue; - } - if (strlen(g_cSMFLAGS[i][g_iLength]) > 0 && StrEqual(g_cTeam[i][g_iLength], "ZM")) - { - Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); - } - } - } - else - { - for (int i = 0; i < g_dIndexes; i++) - { - if (skipIndex(i)) - { - continue; - } - if (StrEqual(l_cLine, g_cUniqueName[i][g_iLength], false)) - { - //PrintToChatAll("l_cLine ZM SUCCESS: %s \n%i", l_cLine, i); - Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); - break; - } - } - } - } - else if (StrContains(l_cLine, "Human Class") > -1) - { - ReplaceStrings(l_cLine, "Human Class"); - if (StrContains(l_cLine, "@all") > -1) - { - for (int i = 0; i < g_iZMBeginindex; i++) - { - Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); - } - } - else if (StrContains(l_cLine, "@groups") > -1) - { - for (int i = 0; i < g_dIndexes; i++) - { - if (skipIndex(i)) - { - continue; - } - if (strlen(g_cGroup[i][g_iLength]) > 0 && StrEqual(g_cTeam[i][g_iLength], "Human")) - { - Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); - } - } - } - else if (StrContains(l_cLine, "@flags") > -1) - { - for (int i = 0; i < g_dIndexes; i++) - { - if (skipIndex(i)) - { - continue; - } - if (strlen(g_cSMFLAGS[i][g_iLength]) > 0 && StrEqual(g_cTeam[i][g_iLength], "Human")) - { - Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); - //PrintToChatAll("SUCCESS: g_cTeam[i][g_iLength]: %s", g_cTeam[i][g_iLength]); - //PrintToChatAll("g_cHumanClasses[i][g_iLength]: %s", g_cHumanClasses[i][g_iLength]); - } - } - } - else - { - for (int i = 0; i < g_dIndexes; i++) - { - if (skipIndex(i)) - { - continue; - } - if (StrEqual(l_cLine, g_cUniqueName[i][g_iLength], false)) - { - //PrintToChatAll("l_cLine SUCCESS: %s \n%i", l_cLine, i); - Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); - break; - } - } - } - } - if (StrContains(l_cLine, l_cJumptokey1) > -1) - { - break; - } - } - } - else - { - g_iWave = 1; - PrintToChatAll("Finished last Wave! Restarting..."); - CS_TerminateRound(5.0, CSRoundEnd_Draw, false); - } - delete kv; - delete l_hFile; + KeyValues kv = CreateKeyValues("Waves"); + int l_iBotQuote; + char l_cJumptokey[16]; + char l_cJumptokey1[16]; + char l_cLine[g_dLength]; + bool l_bKeyIndex = false; + Handle l_hFile = INVALID_HANDLE; + l_hFile = OpenFile(g_cPathsWaveSettings, "r"); + Format(l_cJumptokey, sizeof(l_cJumptokey), "Wave %i", wave); + Format(l_cJumptokey1, sizeof(l_cJumptokey1), "Wave %i", wave +1); + for (int i = 0; i < g_dIndexes; i++) + { + Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), ""); + Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), ""); + } + kv.ImportFromFile(g_cPathsWaveSettings); + if (kv.JumpToKey(l_cJumptokey, false)) + { + g_bRoundInProgress = true; + g_iZMScaleability = kv.GetFloat("PlayerScaleAbility", 5.0); + g_fZMHealthScaleability = kv.GetFloat("HealthScaleAbility", 1.0); + g_iZMCount = kv.GetNum("Zombie Count", 5); + + int additional_zombie_per_player = RoundFloat(g_iZMCount * g_iZMScaleability); + + int l_iPlayers; + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i) && CS_TEAM_CT == GetClientTeam(i)) + { + l_iPlayers++; + } + } + + l_iPlayers -= 1; //first player equals the zombie count. + //first player takes the zombie count, each additional player adds to additional_zombie_per_player + //if 1 player then additional_zombie_per_player * 0. so just g_iZMCount + g_iZMCount += additional_zombie_per_player * l_iPlayers; + + g_iClientRespawnCountNum = kv.GetNum("Respawns", 5); + l_iBotQuote = kv.GetNum("bot_scaling", 1); + SettingBotQoute(l_iBotQuote); + while (!IsEndOfFile(l_hFile) && ReadFileLine(l_hFile, l_cLine, sizeof(l_cLine))) + { + if (StrContains(l_cLine, l_cJumptokey) == -1 && !l_bKeyIndex) + { + continue; + } + l_bKeyIndex = true; + if (StrContains(l_cLine, "wavecommand") > -1) + { + ReplaceStrings(l_cLine, "wavecommand"); + if (strlen(l_cLine) > 0) + ServerCommand(l_cLine); + } + else if (StrContains(l_cLine, "Zombie Class") > -1) + { + ReplaceStrings(l_cLine, "Zombie Class"); + if (StrContains(l_cLine, "@all") > -1) + { + for (int i = g_iZMBeginindex; i < g_iLoadClassesIndex; i++) + { + Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); + } + } + else if (StrContains(l_cLine, "@groups") > -1) + { + for (int i = 0; i < g_dIndexes; i++) + { + if (skipIndex(i)) + { + continue; + } + if ((strlen(g_cGroup[i][g_iLength]) > 0) && StrEqual(g_cTeam[i][g_iLength], "ZM")) + { + Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); + } + } + } + else if (StrContains(l_cLine, "@flags") > -1) + { + for (int i = 0; i < g_dIndexes; i++) + { + if (skipIndex(i)) + { + continue; + } + if (strlen(g_cSMFLAGS[i][g_iLength]) > 0 && StrEqual(g_cTeam[i][g_iLength], "ZM")) + { + Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); + } + } + } + else + { + for (int i = 0; i < g_dIndexes; i++) + { + if (skipIndex(i)) + { + continue; + } + if (StrEqual(l_cLine, g_cUniqueName[i][g_iLength], false)) + { + //PrintToChatAll("l_cLine ZM SUCCESS: %s \n%i", l_cLine, i); + Format(g_cZMRoundClasses[i][g_iLength], sizeof(g_cZMRoundClasses), g_cUniqueName[i][g_iLength]); + break; + } + } + } + } + else if (StrContains(l_cLine, "Human Class") > -1) + { + ReplaceStrings(l_cLine, "Human Class"); + if (StrContains(l_cLine, "@all") > -1) + { + for (int i = 0; i < g_iZMBeginindex; i++) + { + Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); + } + } + else if (StrContains(l_cLine, "@groups") > -1) + { + for (int i = 0; i < g_dIndexes; i++) + { + if (skipIndex(i)) + { + continue; + } + if (strlen(g_cGroup[i][g_iLength]) > 0 && StrEqual(g_cTeam[i][g_iLength], "Human")) + { + Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); + } + } + } + else if (StrContains(l_cLine, "@flags") > -1) + { + for (int i = 0; i < g_dIndexes; i++) + { + if (skipIndex(i)) + { + continue; + } + if (strlen(g_cSMFLAGS[i][g_iLength]) > 0 && StrEqual(g_cTeam[i][g_iLength], "Human")) + { + Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); + //PrintToChatAll("SUCCESS: g_cTeam[i][g_iLength]: %s", g_cTeam[i][g_iLength]); + //PrintToChatAll("g_cHumanClasses[i][g_iLength]: %s", g_cHumanClasses[i][g_iLength]); + } + } + } + else + { + for (int i = 0; i < g_dIndexes; i++) + { + if (skipIndex(i)) + { + continue; + } + if (StrEqual(l_cLine, g_cUniqueName[i][g_iLength], false)) + { + //PrintToChatAll("l_cLine SUCCESS: %s \n%i", l_cLine, i); + Format(g_cHumanClasses[i][g_iLength], sizeof(g_cHumanClasses), g_cUniqueName[i][g_iLength]); + break; + } + } + } + } + if (StrContains(l_cLine, l_cJumptokey1) > -1) + { + break; + } + } + } + else + { + g_iWave = 1; + PrintToChatAll("Finished last Wave! Restarting..."); + CS_TerminateRound(5.0, CSRoundEnd_Draw, false); + } + delete kv; + delete l_hFile; } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -1086,13 +1145,11 @@ public void SettingBotQoute(int botscale) //---------------------------------------------------------------------------------------------------- public void addBots(int botcount) { - //ServerCommand("bot_kick"); - for (int i = 0; i < botcount; i++) - { - if (i > 44) //probably will be turned into a convar somewhen. - continue; - ServerCommand("bot_add_t"); - } + if (botcount > 44) + { + botcount = 44; + } + ServerCommand("bot_quota %i", botcount); } //---------------------------------------------------------------------------------------------------- // Purpose: @@ -1157,10 +1214,10 @@ public void CreateDefaultWave() } KeyValues kv = CreateKeyValues("Waves"); kv.JumpToKey("Wave 1", true); - g_iZMScaleability = 5; + g_iZMScaleability = 5.0; g_fZMHealthScaleability = 1.0; g_iZMCount = 2; - kv.SetNum("PlayerScaleAbility", g_iZMScaleability); + kv.SetFloat("PlayerScaleAbility", g_iZMScaleability); kv.SetFloat("HealthScaleAbility", g_fZMHealthScaleability); kv.SetNum("Zombie Count", g_iZMCount); //creates 10 zombies per player kv.SetNum("Respawns", 5); @@ -1322,155 +1379,84 @@ public void ReadingClassValuesFromFile(int index, char[] Line) //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- -public Action Event_OnFullConnect(Event event, const char[] name, bool dontBroadcast) -{ - int client = GetClientOfUserId(GetEventInt(event, "userid")); - if (!client || !IsClientInGame(client)) - return Plugin_Continue; - for (int i = 1; i <= MaxClients; i++) - { - if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == CS_TEAM_CT) - { - ChangeClientTeam(client, CS_TEAM_T); - if (!IsPlayerAlive(client)) - CS_RespawnPlayer(client); - else - ApplySettingsEvent(client); - return Plugin_Continue; - } - } - ChangeClientTeam(client, CS_TEAM_CT); - ServerCommand("mp_restartgame 1"); - return Plugin_Continue; -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public Action ApplySettings(Event event, const char[] name, bool dontBroadcast) -{ - int client = GetClientOfUserId(event.GetInt("userid")); - ApplySettingsEvent(client); - return Plugin_Handled; -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public Action ApplySettingsEvent(int client) -{ - if (!IsValidClient(client)) - return Plugin_Handled; - if (g_bShouldBeHuman[client]) - { - SelectWavebasedHuman(client); - g_bShouldBeHuman[client] = false; - } - else if (g_bShouldBeZM[client]) - { - SelectWaveBasedZM(client, 1); - g_bShouldBeZM[client] = false; - } - else if (IsFakeClient(client)) - { - SelectWaveBasedZM(client, 0); - } - else if (g_iClientRespawnCount[client] > 0) - { - SelectWavebasedHuman(client); - } - else - { - SelectWaveBasedZM(client, 1); - } - return Plugin_Continue; -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public bool shouldApplySettings(int client, int team, int teamDest) -{ - if (team != teamDest) - { - ChangeClientTeam(client, teamDest); - if (!IsPlayerAlive(client)) - CS_RespawnPlayer(client); - else - ApplySettingsEvent(client); - return false; - } - return true; -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- public Action SelectWavebasedHuman(int client) { - if (!IsValidClient(client)) - return Plugin_Handled; - int l_iTeam = GetClientTeam(client); - if (shouldApplySettings(client, l_iTeam, CS_TEAM_CT)) - { - ModelSelection(client, 2, g_iClientHumanClasses[client]); - } - return Plugin_Continue; + if (!IsValidClient(client)) + return Plugin_Handled; + + if (GetClientTeam(client) == CS_TEAM_T) + { + ChangeClientTeam(client, CS_TEAM_CT); //default putting humans to CT team + CS_RespawnPlayer(client); //respawning because changeclientteam kills the player on css + } + ModelSelection(client, 2, g_iClientHumanClasses[client]); + + return Plugin_Continue; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action SelectWaveBasedZM(int client, int state) { - if (!IsValidClient(client)) - return Plugin_Handled; - int l_iTeam = GetClientTeam(client); - int l_iZMIndex; - int l_ibotIndex; - if (shouldApplySettings(client, l_iTeam, CS_TEAM_T)) - { - if (state == 0) - { - for (int i = 0; i < g_dIndexes; i++) - { - if (strlen(g_cZMRoundClasses[i][g_iLength]) > 0 && strlen(g_cGroup[i][g_iLength]) < 1 && strlen(g_cSMFLAGS[i][g_iLength]) < 1) - { - l_iZMIndex++; - } - } - l_ibotIndex = GetRandomInt(0, l_iZMIndex -1); - l_iZMIndex = 0; - for (int i = 0; i < g_dIndexes; i++) - { - if (strlen(g_cZMRoundClasses[i][g_iLength]) > 0 && strlen(g_cGroup[i][g_iLength]) < 1 && strlen(g_cSMFLAGS[i][g_iLength]) < 1) - { - if (l_ibotIndex == l_iZMIndex) - { - g_iClientZMClasses[client] = i; - break; - } - else - l_iZMIndex++; - } - } - } - else if (strlen(g_cZMRoundClasses[g_iClientZMClasses[client]][g_iLength]) < 1) - { - for (int i = 0; i < g_dIndexes; i++) - { - if (strlen(g_cZMRoundClasses[i][g_iLength]) > 0) - { - g_iClientZMClasses[client] = i; - break; - } - } - } - ModelSelection(client, state, g_iClientZMClasses[client]); - } - return Plugin_Handled; + if (!IsValidClient(client)) + return Plugin_Handled; + + if (GetClientTeam(client) == CS_TEAM_CT) + { + ChangeClientTeam(client, CS_TEAM_T); //default putting bots to t + CS_RespawnPlayer(client); //respawning because changeclientteam kills the player on css + } + //state 0 was bot, state 1 was real player. + if (!IsValidClient(client)) + return Plugin_Handled; + int l_iZMIndex; + int l_ibotIndex; + + if (state == 0) + { + for (int i = 0; i < g_dIndexes; i++) + { + if (strlen(g_cZMRoundClasses[i][g_iLength]) > 0 && strlen(g_cGroup[i][g_iLength]) < 1 && strlen(g_cSMFLAGS[i][g_iLength]) < 1) + { + l_iZMIndex++; + } + } + l_ibotIndex = GetRandomInt(0, l_iZMIndex -1); + l_iZMIndex = 0; + for (int i = 0; i < g_dIndexes; i++) + { + if (strlen(g_cZMRoundClasses[i][g_iLength]) > 0 && strlen(g_cGroup[i][g_iLength]) < 1 && strlen(g_cSMFLAGS[i][g_iLength]) < 1) + { + if (l_ibotIndex == l_iZMIndex) + { + g_iClientZMClasses[client] = i; + break; + } + else + l_iZMIndex++; + } + } + } + else if (strlen(g_cZMRoundClasses[g_iClientZMClasses[client]][g_iLength]) < 1) + { + for (int i = 0; i < g_dIndexes; i++) + { + if (strlen(g_cZMRoundClasses[i][g_iLength]) > 0) + { + g_iClientZMClasses[client] = i; + break; + } + } + } + ModelSelection(client, 1, g_iClientZMClasses[client]); + return Plugin_Handled; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action ModelSelection(int client, int state, int modelIndex) { - //state 0 = zombie bots, state 1 = zombie players, state 2 = human players + //state 1 = zombie players, state 2 = human players char l_cUniqueModel[g_dLength]; int l_iModelIndex; l_iModelIndex = modelIndex; @@ -1482,6 +1468,8 @@ public Action ModelSelection(int client, int state, int modelIndex) { Format(l_cUniqueModel, sizeof(l_cUniqueModel), g_cHumanClasses[l_iModelIndex][g_iLength]); } + + for (int i = 0; i < g_dIndexes; i++) { if (strlen(g_cUniqueName[i][g_iLength]) < 1) @@ -1493,13 +1481,13 @@ public Action ModelSelection(int client, int state, int modelIndex) if (StrContains(g_cModelPath[i][g_iLength], "mdl") == -1) { //incorrect modelpaths crash at SetEntityModel - LoadClasses(); - ForcePlayerSuicide(client); + //LoadClasses(); + //ForcePlayerSuicide(client); return Plugin_Continue; } + + SetEntityModel(client, g_cModelPath[i][g_iLength]); - SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage); - SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage); g_bClientProtection[client] = true; if (StrContains(g_cNoFallDmg[i][g_iLength], "YES") > -1) g_bFallDamage[client] = true; @@ -1508,15 +1496,27 @@ public Action ModelSelection(int client, int state, int modelIndex) if (state < 2) { CreateTimer(g_fZMSpawnProtection, Timer_StopProtection, client); - Client_SetActiveWeapon(client, GetPlayerWeaponSlot(client, 2)); + //Client_SetActiveWeapon(client, GetPlayerWeaponSlot(client, 2)); } else { CreateTimer(g_fHumanSpawnProtection, Timer_StopProtection, client); - Client_SetActiveWeapon(client, GetPlayerWeaponSlot(client, 1)); + //Client_SetActiveWeapon(client, GetPlayerWeaponSlot(client, 1)); + } + 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)); } - if (state < 2 && RoundFloat(g_fZMHealthScaleability * 10.0) > 0.0) - SetEntityHealth(client, StringToInt(g_cHealth[i][g_iLength]) * RoundFloat(g_fZMHealthScaleability * 10.0) / 10); else SetEntityHealth(client, StringToInt(g_cHealth[i][g_iLength])); g_iSpeedIndex[client] = i; @@ -1625,14 +1625,15 @@ public Action Timer_Respawn(Handle timer, any userid) if (client == 0) return Plugin_Continue; - if (!IsValidClient(client) || IsPlayerAlive(client) || GetClientTeam(client) <= CS_TEAM_SPECTATOR) + 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); + ChangeClientTeam(client, CS_TEAM_T); //ran out of respawns for CT } else if (IsFakeClient(client) && GetClientTeam(client) != CS_TEAM_T) { @@ -1640,7 +1641,7 @@ public Action Timer_Respawn(Handle timer, any userid) } else if (!IsFakeClient(client) && GetClientTeam(client) != CS_TEAM_CT) { - ChangeClientTeam(client, CS_TEAM_CT); + ChangeClientTeam(client, CS_TEAM_CT); //default putting humans to CT team } CS_RespawnPlayer(client); return Plugin_Continue; @@ -1659,62 +1660,74 @@ public Action Timer_StopProtection(Handle timer, int client) //---------------------------------------------------------------------------------------------------- public Action Event_OnPlayerDeath(Handle event, const char[] name, bool dontBroadcast) { - int client = GetClientOfUserId(GetEventInt(event, "userid")); - if(!client || !IsClientInGame(client)) - return Plugin_Continue; - - if (IsFakeClient(client)) - { - CreateTimer(1.0, Timer_Respawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); - } - else - { - CreateTimer(g_fRespawnTimer, Timer_Respawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); - } - return Plugin_Continue; + int client = GetClientOfUserId(GetEventInt(event, "userid")); + if(!client || !IsClientInGame(client)) + return Plugin_Continue; + + if (IsFakeClient(client)) + { + CreateTimer(1.0, Timer_Respawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); + } + else + { + if (g_iClientRespawnCount[client] > 0) + { + PrintToChat(client, "You have %i respawns left as human. You will respawn in %f seconds.", g_iClientRespawnCount[client], g_fRespawnTimer); + } + else + { + PrintToChat(client, "You will respawn as a zombie in %f seconds.", g_fRespawnTimer); + } + CreateTimer(g_fRespawnTimer, Timer_Respawn, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE); + } + return Plugin_Continue; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action UpdateWaveCount(int client) { - //PrintToChatAll("Player %N died", client); - char l_cCount[g_dIndexes]; - if (GetClientTeam(client) == CS_TEAM_CT) - { - g_iClientRespawnCount[client]--; - for (int i = 1; i <= MaxClients; i++) - { - if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == CS_TEAM_CT) - { - return Plugin_Handled; - } - } - PrintToChatAll("All Humans died!"); - CS_TerminateRound(4.0, CSRoundEnd_TerroristWin, false); - return Plugin_Handled; - } - else if (GetClientTeam(client) == CS_TEAM_T) - { - g_iZMCount--; - SetHudTextParams(-0.5, 0.8, 10.0, 255, 0, 255, 255, 1, 0.1, 0.1, 0.1); - for (int i = 1; i <= MaxClients; i++) - { - if (IsValidClient(i) && !IsFakeClient(i)) - { - Format(l_cCount, sizeof(l_cCount), "Remaining Zombies: %i", g_iZMCount); - ShowHudText(i, 3, l_cCount); - } - } - } - if (g_iZMCount == 0 && g_bRoundInProgress) - { - PrintToChatAll("Won Round!"); - CS_TerminateRound(4.0, CSRoundEnd_CTWin, false); - g_iWave++; - g_bRoundInProgress = false; - } - return Plugin_Continue; + //PrintToChatAll("Player %N died", client); + if (GetClientTeam(client) == CS_TEAM_CT) + { + g_iClientRespawnCount[client]--; + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == CS_TEAM_CT) + { + return Plugin_Handled; + } + } + PrintToChatAll("All Humans died!"); + CS_TerminateRound(4.0, CSRoundEnd_TerroristWin, false); + return Plugin_Handled; + } + else if (GetClientTeam(client) == CS_TEAM_T) + { + g_iZMCount--; + //not using hudtext anymore + /* + char l_cCount[g_dIndexes]; + SetHudTextParams(-0.4, 0.8, 10.0, 255, 0, 255, 255, 1, 0.1, 0.1, 0.1); + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i)) + { + Format(l_cCount, sizeof(l_cCount), "Remaining Zombies: %i", g_iZMCount); + ShowHudText(i, 3, l_cCount); + } + } + */ + PrintHintTextToAll("Remaining Zombies: %i", g_iZMCount); + } + if (g_iZMCount == 0 && g_bRoundInProgress) + { + PrintToChatAll("Won Round!"); + CS_TerminateRound(4.0, CSRoundEnd_CTWin, false); + g_iWave++; + g_bRoundInProgress = false; + } + return Plugin_Continue; } //---------------------------------------------------------------------------------------------------- // Purpose: