summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/game_manager.sp
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-11-26 13:36:02 +0100
committernavewindre <nw@moneybot.cc>2023-11-26 13:36:02 +0100
commit2d51c1ae80693f586f719640571591779bcb0c2d (patch)
tree965852e5f8cb99a1522bb5cca1ae5aee210323d9 /sourcemod/scripting/game_manager.sp
parent6a292a21a7fcacde51f0551ea9ae76fe36972183 (diff)
aye aye
Diffstat (limited to 'sourcemod/scripting/game_manager.sp')
-rw-r--r--sourcemod/scripting/game_manager.sp233
1 files changed, 215 insertions, 18 deletions
diff --git a/sourcemod/scripting/game_manager.sp b/sourcemod/scripting/game_manager.sp
index 3fcd3c7..73d3a2d 100644
--- a/sourcemod/scripting/game_manager.sp
+++ b/sourcemod/scripting/game_manager.sp
@@ -4,6 +4,7 @@
#include <cstrike>
#include <sdkhooks>
#include <smlib>
+#include <morecolors>
#define PLUGIN_VERSION "1.0.0"
#define MAX_FILE_LEN 80
@@ -25,6 +26,7 @@ new Handle:g_h_mp_startmoney = INVALID_HANDLE;
new Handle:g_h_mp_maxrounds = INVALID_HANDLE;
new Handle:g_h_mp_buytime = INVALID_HANDLE;
new Handle:g_h_nh_warmup = INVALID_HANDLE;
+new Handle:g_h_nh_buytime = INVALID_HANDLE;
new Handle:g_h_nh_teamlimit = INVALID_HANDLE;
new Handle:g_h_mp_ignoreconditions = INVALID_HANDLE;
new g_mp_startmoney;
@@ -32,8 +34,12 @@ new bool:g_doReset = false;
new g_CtScore, g_TScore;
new Handle:g_h_roundExtentTimer = INVALID_HANDLE;
new Handle:g_h_execServerCfgTimer = INVALID_HANDLE;
-new Float:g_buytime = 0.5;
new g_lastDmMode = 0;
+new Float:g_botVoteEnd = -1.0;
+new Float:g_voteTime = 20.0;
+new bool:g_hasVoted[MAXPLAYERS + 1] = {false, ...};
+new g_voteCount[9] = {0, ...};
+new bool:g_botVoteDone = false;
/* forwards */
new Handle:g_f_on_ht = INVALID_HANDLE;
@@ -48,10 +54,13 @@ public OnMapStart(){
g_mp_startmoney = GetConVarInt( g_h_mp_startmoney );
g_maxrounds = GetConVarInt( g_h_mp_maxrounds );
- g_buytime = GetConVarFloat( g_h_mp_buytime );
g_lastDmMode = 0;
OnDmModeChanged( g_h_nh_warmup, "", "" );
+
+ g_botVoteEnd = -1.0;
+ SetConVarInt( g_h_nh_warmup, 60 );
+ CreateTimer( 20.0, BotVoteCreateTimer, _ );
}
public OnConfigsExecuted() {
@@ -71,6 +80,7 @@ public OnPluginStart() {
g_h_mp_buytime = FindConVar( "mp_buytime");
g_h_mp_ignoreconditions = FindConVar( "mp_ignore_round_win_conditions" );
g_h_nh_warmup = CreateConVar( "nh_warmup", "0", "set warmup time. -1 for infinite.", 0 );
+ g_h_nh_buytime = CreateConVar( "nh_buytime", "0.5", "buytime outside of warmup.", 0 );
g_h_nh_teamlimit = CreateConVar( "nh_teamlimit", "5", "player limit per team", 0 );
if( g_h_nh_warmup != INVALID_HANDLE ) {
HookConVarChange( g_h_nh_warmup, OnDmModeChanged );
@@ -78,6 +88,8 @@ public OnPluginStart() {
g_f_on_ht = CreateGlobalForward( "nthvnHalftime", ET_Ignore );
+ RegAdminCmd("sm_admbotvote", CreateBotVote, ADMFLAG_RCON);
+ RegConsoleCmd("sm_botvote", CreateBotVotePlayer);
// Finding offset for CS cash
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
@@ -103,7 +115,7 @@ public OnDmModeChanged( Handle:cvar, const String:oldVal[], const String:newVal[
}
if( !dm ) {
- SetConVarFloat( g_h_mp_buytime, g_buytime );
+ SetConVarFloat( g_h_mp_buytime, GetConVarFloat( g_h_nh_buytime ) );
if( g_h_roundExtentTimer ) {
KillTimer( g_h_roundExtentTimer );
g_h_roundExtentTimer = INVALID_HANDLE;
@@ -113,9 +125,7 @@ public OnDmModeChanged( Handle:cvar, const String:oldVal[], const String:newVal[
}
else {
if( g_h_roundExtentTimer == INVALID_HANDLE ) {
- g_buytime = GetConVarFloat( g_h_mp_buytime );
g_h_roundExtentTimer = CreateTimer( 1.0, WarmupTimer, 0, TIMER_REPEAT );
- SetConVarFloat( g_h_mp_buytime, 420.0 );
}
}
@@ -132,6 +142,7 @@ public Action:WarmupTimer( Handle:timer, any:userid ) {
SetConVarInt( g_h_nh_warmup, dm - 1 );
}
+ SetConVarFloat( g_h_mp_buytime, 420.0 );
new time = GameRules_GetProp( "m_iRoundTime" );
if( time < 420 * 60 )
time = 420 * 60 + 1;
@@ -142,17 +153,19 @@ public Action:WarmupTimer( Handle:timer, any:userid ) {
if( !IsValidEdict(i) || !IsValidEntity(i) )
continue;
- if( i < MaxClients && IsClientConnected( i ) && IsClientInGame( i ) ) {
- if( dm > 0 ) {
- new secs = dm % 60;
- new mins = (dm - secs) / 60;
- PrintHintText( i, "---[ WARMUP %d:%02d ]---", mins, secs );
- }
- else {
- PrintHintText( i, "---[ WARMUP ]---" );
+ if( GetGameTime() > g_botVoteEnd ) {
+ if( i < MaxClients && IsClientConnected( i ) && IsClientInGame( i ) ) {
+ if( dm > 0 ) {
+ new secs = dm % 60;
+ new mins = (dm - secs) / 60;
+ PrintHintText( i, "---[ WARMUP %d:%02d ]---", mins, secs );
+ }
+ else {
+ PrintHintText( i, "---[ WARMUP ]---" );
+ }
+
+ continue;
}
-
- continue;
}
GetEdictClassname( i, name, sizeof(name) );
@@ -167,11 +180,18 @@ public OnClientPutInServer( client ) {
KillTimer( g_h_execServerCfgTimer );
g_h_execServerCfgTimer = INVALID_HANDLE;
}
-
+
SDKHook( client, SDKHook_PostThinkPost, Hook_PostThinkPost );
+
+ for( new i = 1; i < MaxClients; ++i ) {
+ if( i != client && IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) )
+ return;
+ }
+
+ SetConVarInt( g_h_nh_warmup, 60 );
+ CreateTimer( 20.0, BotVoteCreateTimer, _ );
}
-
public Hook_PostThinkPost( entity ) {
new dm = GetConVarInt( g_h_nh_warmup );
@@ -179,6 +199,156 @@ public Hook_PostThinkPost( entity ) {
SetEntProp( entity, Prop_Send, "m_bInBuyZone", 1 );
}
+public ShowBotVoteMenu( client ) {
+ new Handle:hPanel = CreateMenu(BotVoteHandler);
+
+ AddMenuItem( hPanel, "0", "vote for the amount of bots!" );
+ AddMenuItem( hPanel, "1", "" );
+ AddMenuItem( hPanel, "2", "" );
+ AddMenuItem( hPanel, "3", "no bots" );
+ AddMenuItem( hPanel, "4", "3v3 bots" );
+ AddMenuItem( hPanel, "5", "5v5 bots" );
+ AddMenuItem( hPanel, "6", "no choice" );
+
+ DisplayMenu(hPanel, client, MENU_TIME_FOREVER);
+}
+
+public BotVoteHandler( Handle:hMenu, MenuAction:ma, client, nItem ) {
+ switch( ma ) {
+ case MenuAction_Select:
+ {
+ if( nItem == 6 ) {
+ g_hasVoted[client] = true;
+ }
+ else if( nItem < 3 && GetGameTime() < g_botVoteEnd ) {
+ ShowBotVoteMenu( client );
+ }
+ else {
+ g_voteCount[nItem - 3]++;
+ g_hasVoted[client] = true;
+ }
+ }
+
+ case MenuAction_End:
+ {
+ CloseHandle( hMenu );
+ }
+ }
+}
+
+public FinishBotVote() {
+ new winner = -1;
+ new maxvotes = 0;
+ for( new i = 0; i < 9; ++i ) {
+ if( g_voteCount[i] > maxvotes )
+ winner = i;
+ }
+
+ switch( winner ) {
+ case 0:
+ {
+ ServerCommand( "bot_kick; bot_quota 0" );
+ PrintToChatAll( "Vote for no bots won, kicking all bots." );
+ }
+ case 1:
+ {
+ ServerCommand( "bot_quota 6" );
+ PrintToChatAll( "Vote for 3v3 bots won, setting quota to 6 bots." );
+ }
+ case 2: {
+ ServerCommand( "bot_quota 10" );
+ PrintToChatAll( "Vote for 3v3 bots won, setting quota to 10 bots." );
+ }
+ }
+
+ for( new i = 0; i < 9; ++i ) {
+ g_voteCount[i] = 0;
+ }
+
+ for( new i = 0; i < MAXPLAYERS; ++i ) {
+ g_hasVoted[i] = false;
+ }
+}
+
+public Action:BotVoteTimer( Handle:timer, any:unused ) {
+ new dm = GetConVarInt( g_h_nh_warmup );
+ new String:hintStr[256];
+ new Float:diff = g_botVoteEnd - GetGameTime();
+
+ if( diff <= 0 ) {
+ FinishBotVote();
+ KillTimer( timer );
+ return;
+ }
+
+ for( new i = 1; i < MaxClients; ++i ) {
+ if( !IsClientConnected(i) || !IsClientInGame(i) || IsFakeClient(i) )
+ continue;
+
+ Format(
+ hintStr,
+ sizeof(hintStr),
+ "bot vote [%.0f sec left]:\nno bots: %d\n3v3 bots: %d\n5v5 bots: %d",
+ diff,
+ g_voteCount[0],
+ g_voteCount[1],
+ g_voteCount[2]
+ );
+
+ if( dm > 0 ) {
+ new secs = dm % 60;
+ new mins = (dm - secs) / 60;
+ Format( hintStr, sizeof(hintStr), "%s\n---[ WARMUP %d:%02d ]---", hintStr, mins, secs );
+ }
+ else if( dm < 0 ) {
+ Format( hintStr, sizeof(hintStr), "%s\n---[ WARMUP ]---", hintStr );
+ }
+
+ PrintHintText( i, hintStr );
+ if( !g_hasVoted[i] )
+ ShowBotVoteMenu( i );
+ }
+}
+
+public Action:CreateBotVote( client, args ) {
+ if( GetGameTime() < g_botVoteEnd )
+ return Plugin_Handled;
+
+ g_botVoteDone = true;
+ g_botVoteEnd = GetGameTime() + g_voteTime;
+
+ for( new i = 0; i < 9; ++i ) {
+ g_voteCount[i] = 0;
+ }
+
+ for( new i = 0; i < MAXPLAYERS; ++i ) {
+ g_hasVoted[i] = false;
+ }
+
+ BotVoteTimer( INVALID_HANDLE, 0 );
+ CreateTimer( 1.0, BotVoteTimer, 0, TIMER_REPEAT );
+ return Plugin_Handled;
+}
+
+public Action:CreateBotVotePlayer( client, args ) {
+ if( GetGameTime() < g_botVoteEnd ) {
+ g_hasVoted[client] = false;
+ ShowBotVoteMenu( client );
+ }
+
+ if( g_botVoteDone ) {
+ CPrintToChat( client, "{fuchsia}A bot vote has already concluded this round." );
+ return Plugin_Handled;
+ }
+
+ CreateBotVote( client, args );
+ return Plugin_Handled;
+}
+
+public Action:BotVoteCreateTimer( Handle: timer, any:unused ) {
+ CreateBotVote( 0, 0 );
+}
+
public OnClientDisconnect( client ) {
if( IsFakeClient( client ) )
return;
@@ -198,6 +368,7 @@ public OnClientDisconnect( client ) {
}
public Action:ExecServerCfg( Handle:timer, any:unused ) {
+ g_botVoteDone = false;
ServerCommand( "exec server.cfg" );
g_h_execServerCfgTimer = INVALID_HANDLE;
}
@@ -304,8 +475,33 @@ public Action:Listener_JoinTeam( id, const String: command[], args ) {
return Plugin_Continue;
}
+public Action:RespawnPlayerDelay( Handle: timer, any: userid ) {
+ new id = GetClientOfUserId( userid );
+
+ if( id <= 0 )
+ return Plugin_Handled;
+
+ if( !IsClientConnected( id ) || !IsClientInGame( id ) )
+ return Plugin_Handled;
+
+ if( IsPlayerAlive( id ) )
+ return Plugin_Handled;
+
+ new team = GetClientTeam( id );
+ if( team < 2 )
+ return Plugin_Handled;
+
+ CS_RespawnPlayer( id );
+}
+
public Action:Event_PlayerTeam( Handle:event, const String:name[], bool dontBroadcast ) {
CreateTimer( 0.2, VerifyTeamCounts, 0, 0 );
+ new uid = GetEventInt( event, "userid" );
+
+ if( GetConVarInt( g_h_nh_warmup ) != 0 ) {
+ CreateTimer( 0.5, RespawnPlayerDelay, uid );
+ }
+
return Plugin_Continue;
}
@@ -380,7 +576,7 @@ public Event_RoundStart( Handle:event, const String:name[], bool:dontBroadcast )
g_CtScore = GetTeamScore( CS_TEAM_CT );
g_TScore = GetTeamScore( CS_TEAM_T );
- new newRoundCount = g_CtScore = g_TScore + 1;
+ new newRoundCount = g_CtScore + g_TScore + 1;
if( newRoundCount < g_roundCount ) {
halftime = false;
g_CtScore = 0;
@@ -430,6 +626,7 @@ public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
new reason = GetEventInt(event, "reason");
new winner = GetEventInt(event, "winner");
+ g_botVoteDone = false;
g_mp_startmoney = GetConVarInt(g_h_mp_startmoney);
g_maxrounds = GetConVarInt(g_h_mp_maxrounds);