summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/game_manager.sp
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-11-15 02:20:31 +0100
committernavewindre <nw@moneybot.cc>2023-11-15 02:20:31 +0100
commitd4d5482b5f66209d17b9d786ffe0a13cf352fb15 (patch)
treeb379882c13bdeb64d1009ce64733a8f0b7d1054c /sourcemod/scripting/game_manager.sp
parent405737846f73753ade746b0506020f6720269a51 (diff)
cleanup halftime plugin, remove money string from bot plugin, push website
Diffstat (limited to 'sourcemod/scripting/game_manager.sp')
-rw-r--r--sourcemod/scripting/game_manager.sp180
1 files changed, 180 insertions, 0 deletions
diff --git a/sourcemod/scripting/game_manager.sp b/sourcemod/scripting/game_manager.sp
new file mode 100644
index 0000000..5d0c250
--- /dev/null
+++ b/sourcemod/scripting/game_manager.sp
@@ -0,0 +1,180 @@
+#pragma semicolon 1
+#include <sourcemod>
+#include <sdktools>
+#include <cstrike>
+
+#define PLUGIN_VERSION "1.0.0"
+#define MAX_FILE_LEN 80
+
+public Plugin:myinfo =
+{
+ name = "networkheaven game manager",
+ author = "networkheaven.net",
+ description = "",
+ version = PLUGIN_VERSION,
+ url = "networkheaven.net"
+};
+
+new g_maxrounds;
+new g_roundCount;
+new bool:halftime;
+new Handle:g_h_mp_startmoney = INVALID_HANDLE;
+new Handle:g_h_mp_maxrounds = INVALID_HANDLE;
+new g_mp_startmoney;
+new bool:g_doReset = false;
+new g_CtScore, g_TScore;
+
+/* forwards */
+new Handle:g_f_on_ht = INVALID_HANDLE;
+
+// Offsets
+new g_iAccount = -1;
+
+
+// Setting halftime to false
+public OnMapStart(){
+ halftime = false;
+ g_roundCount = 0;
+
+ g_mp_startmoney = GetConVarInt(g_h_mp_startmoney);
+ g_maxrounds = GetConVarInt(g_h_mp_maxrounds);
+}
+
+public OnConfigsExecuted(){
+ halftime = false;
+}
+
+// Hooking events at plugin start
+public OnPluginStart() {
+ HookEvent("round_start", Event_RoundStart);
+ HookEvent("round_end", Event_RoundEnd);
+
+ g_h_mp_startmoney = FindConVar("mp_startmoney");
+ g_h_mp_maxrounds = FindConVar("mp_maxrounds");
+
+ g_f_on_ht = CreateGlobalForward("nthvnHalftime", ET_Ignore);
+
+ // Finding offset for CS cash
+ g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
+ if (g_iAccount == -1)
+ SetFailState("m_iAccount offset not found");
+}
+
+// RoundStart gets the maptime
+// Checks to see if halftime has passed, if not then make sure halftime is 0
+// Setting halftime false here as well since in some occasions when extending map
+// team switch can occur again.
+public Event_RoundStart( Handle:event, const String:name[], bool:dontBroadcast )
+{
+ new wepIdx;
+ new playerTeam;
+
+ g_CtScore = GetTeamScore(CS_TEAM_CT);
+ g_TScore = GetTeamScore(CS_TEAM_T);
+
+ g_roundCount = g_CtScore + g_TScore + 1;
+
+ if( g_doReset ) {
+ for( new client = 1; client <= GetMaxClients(); client++ ) {
+ if (IsClientInGame (client) && IsClientConnected(client)) {
+ for( new w = 0; w < 6; w++ ) {
+ if( w != 2 && w != 4 )
+ while( ( wepIdx = GetPlayerWeaponSlot(client, w) ) != -1 )
+ RemovePlayerItem(client, wepIdx);
+ }
+
+ playerTeam = GetClientTeam( client );
+ if( playerTeam == CS_TEAM_T ) {
+ GivePlayerItem( client, "weapon_glock" );
+ }
+ else if( playerTeam == CS_TEAM_CT ) {
+ GivePlayerItem( client, "weapon_usp" );
+ if ((wepIdx = GetPlayerWeaponSlot( client, 6 ) ) != -1)
+ RemovePlayerItem(client, wepIdx);
+ }
+ SetEntProp(client, Prop_Send, "m_ArmorValue", 0, 1);
+ SetEntProp(client, Prop_Send, "m_bHasHelmet", 0, 1);
+
+ SetEntData(client, g_iAccount, g_mp_startmoney, 4, true);
+ }
+ }
+ }
+ g_doReset = false;
+}
+
+public Event_RoundEnd (Handle:event, const String:name[], bool:dontBroadcast)
+{
+ new reason = GetEventInt(event, "reason");
+ new winner = GetEventInt(event, "winner");
+
+ g_mp_startmoney = GetConVarInt(g_h_mp_startmoney);
+ g_maxrounds = GetConVarInt(g_h_mp_maxrounds);
+
+ // game commencing
+ if( reason == 15 ) {
+ g_CtScore = 0;
+ g_TScore = 0;
+ g_roundCount = 0;
+ return;
+ }
+
+ if( winner==CS_TEAM_T )
+ g_TScore++;
+ else if( winner==CS_TEAM_CT )
+ g_CtScore++;
+
+ if( g_TScore > g_maxrounds/2 || g_CtScore > g_maxrounds/2 ) {
+ SetConVarInt( g_h_mp_maxrounds, 1, true, false );
+ PrintToChatAll("\x04============[ game end ]============");
+
+ if( g_TScore > g_CtScore ) {
+ PrintToChatAll("\x04Winner: T");
+ }
+ else {
+ PrintToChatAll("\x04Winner: CT");
+ }
+ }
+
+ LogMessage( "roundEnd: ct: %d t: %d rounds: %d max: %d", g_CtScore, g_TScore, g_roundCount, g_maxrounds/2 );
+ if( halftime || g_roundCount < g_maxrounds/2 ) {
+ SetTeamScore( CS_TEAM_CT, g_CtScore );
+ SetTeamScore( CS_TEAM_T, g_TScore );
+ return;
+ }
+
+ new playerTeam;
+
+ Call_StartForward(g_f_on_ht);
+ Call_Finish();
+
+ halftime = true;
+ for( new i = 1; i <= GetMaxClients(); i++ ) {
+ if( IsClientInGame( i ) && IsClientConnected( i ) ) {
+
+ // kill bots
+ if( IsFakeClient( i ) ) {
+ ForcePlayerSuicide( i );
+ }
+
+ g_doReset = true;
+
+ playerTeam = GetClientTeam(i);
+ if( playerTeam == CS_TEAM_T ) {
+ CS_SwitchTeam( i, CS_TEAM_CT );
+ }
+ else if( playerTeam == CS_TEAM_CT ) {
+ CS_SwitchTeam( i, CS_TEAM_T );
+ }
+ }
+ }
+
+ new tmp;
+ tmp = g_CtScore;
+ g_CtScore = g_TScore;
+ g_TScore = tmp;
+
+ PrintToChatAll("\x04==========[ halftime switch ]==========");
+
+ SetTeamScore( CS_TEAM_CT, g_CtScore );
+ SetTeamScore( CS_TEAM_T, g_TScore );
+}