From fc8a277e3bee735d6504f6db657a19c705637179 Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 8 Nov 2018 00:37:14 +0700 Subject: [PATCH] Implement voteload, modify menu --- dlls/coop.cpp | 56 ++++++++++++++++++++++++++++++++++++++------- dlls/gravgunmod.cpp | 15 ++++++------ dlls/gravgunmod.h | 1 + 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/dlls/coop.cpp b/dlls/coop.cpp index e29972b7..98290acb 100644 --- a/dlls/coop.cpp +++ b/dlls/coop.cpp @@ -354,11 +354,6 @@ void UTIL_SpawnPlayer( CBasePlayer *pPlayer ) } -// Collect all weapons tat player touchet in coop ant give to all players at spawn -void COOP_ClearWeaponList( void ) -{ - g_CoopState.p.iWeaponCount = 0; -} void COOP_GiveDefaultWeapons(CBasePlayer *pPlayer) { for(int i = 0; i < g_CoopState.p.iWeaponCount;i++) @@ -506,12 +501,12 @@ void COOP_ServerActivate( void ) } COOPMapState *pNewState = (COOPMapState *)calloc(1, sizeof( struct COOPMapState ) ); + memset( &g_CoopState.p, 0, sizeof( g_CoopState.p ) ); pNewState->pNext = g_CoopState.pMapStates; pNewState->p.vecOffset = Vector(0, 0, 0); strncpy(pNewState->p.szMapName, STRING(gpGlobals->mapname), 31); g_CoopState.pMapStates = g_CoopState.pCurrentMap = pNewState; GGM_ClearLists(); - COOP_ClearWeaponList(); } g_fPause = false; @@ -719,9 +714,10 @@ bool COOP_ClientCommand( edict_t *pEntity ) if( pPlayer->m_ggm.iState == STATE_SPAWNED ) { GGM_PlayerMenu &m = pPlayer->m_ggm.menu.New( "COOP MENU" ) - .Add( "Force respawn", "respawn" ) .Add( "Unblock", "unblock" ) - .Add( "Become spectator", "spectate" ); + /// TODO: statistics button here + .Add( "Respawn", "respawn" ) + .Add( "Other", "coopmenu1"); if( mp_coop_checkpoints.value ) m.Add( "Checkpoints", "checkpointmenu" ); m.Add( "Cancel", "" ); @@ -738,6 +734,20 @@ bool COOP_ClientCommand( edict_t *pEntity ) } } + else if( FStrEq( pcmd, "coopmenu1" ) ) + { + //UTIL_CoopMenu( pPlayer ); + if( pPlayer->m_ggm.iState == STATE_SPAWNED ) + { + pPlayer->m_ggm.menu.New( "COOP MENU" ) + .Add( "Force respawn", "respawn" ) + .Add( "Spectate", "spectate" ) + .Add( "Vote load", "voteload") + .Add( "Cancel", "" ) + .Show(); + return true; + } + } else if( FStrEq( pcmd, "respawn" ) ) { pPlayer->RemoveAllItems( TRUE ); @@ -774,6 +784,36 @@ bool COOP_ClientCommand( edict_t *pEntity ) return false; return true; } + else if( FStrEq( pcmd, "voteload") ) + { + if( !mp_coop_checkpoints.value ) + return false; + if( pPlayer->m_ggm.iState != STATE_SPAWNED ) + return false; + if( !GGM_IsTempBanned( pPlayer ) ) + { + if( CMD_ARGC() == 1) + { + GGM_PlayerMenu &menu = pPlayer->m_ggm.menu.New("Select save", false ); + + for( int i = 0; i < 4; i++ ) + if( g_CoopState.p.rgszSaveSlots[i][0] ) + menu.Add( g_CoopState.p.rgszSaveSlots[i], UTIL_VarArgs("voteload %s",g_CoopState.p.rgszSaveSlots[i]) ); + + menu.Add( "Cancel", "" ).Show(); + } + else + { + char szCommand[32]; + snprintf( szCommand, 31, "ggm_load %s", CMD_ARGV(1) ); + + GGM_StartVoteCommand( pPlayer, szCommand, UTIL_VarArgs("Load save %s", CMD_ARGV(1) )); + } + } + else + return false; + return true; + } else if( FStrEq( pcmd, "confirmchangelevel" ) ) { if( pPlayer->m_ggm.iLocalConfirm ) diff --git a/dlls/gravgunmod.cpp b/dlls/gravgunmod.cpp index 8b89d376..a1fd1449 100644 --- a/dlls/gravgunmod.cpp +++ b/dlls/gravgunmod.cpp @@ -48,7 +48,7 @@ cvar_t mp_errormdlpath = { "mp_errormdlpath", "models/error.mdl", FCVAR_SERVER } cvar_t *zombietime = NULL; static char gamedir[MAX_PATH]; void Ent_RunGC_f( void ); - +static bool g_fCmdUsed; enum GGMVoteMode { VOTE_NONE = 0, @@ -233,6 +233,7 @@ bool GGM_VoteProcess( CBasePlayer *pPlayer, const char *pszStr ) UTIL_CoopPrintMessage( "%s^7 confirmed vote\n", GGM_PlayerName( pPlayer )); if( g_Vote.iConfirm > g_Vote.iMaxCount / 2 ) { + g_fCmdUsed = false; SERVER_COMMAND( g_Vote.szCommand ); SERVER_EXECUTE(); GGM_ClearVote(); @@ -1773,7 +1774,7 @@ so perform all parsing here, allowing to change CMD_ARGV result =============================== */ -bool cmd_used; + // CMD_ARGS replacement namespace GGM { @@ -1883,7 +1884,7 @@ static void Cmd_TokenizeString( const char *text ) cmd_argc = 0; // clear previous args cmd_args = NULL; - cmd_used = true; + g_fCmdUsed = true; if( !text ) return; @@ -1921,14 +1922,14 @@ static void Cmd_TokenizeString( const char *text ) static void Cmd_Reset( void ) { - cmd_used = false; + g_fCmdUsed = false; } } extern "C" int CMD_ARGC() { - if( cmd_used ) + if( g_fCmdUsed ) { return GGM::cmd_argc; } @@ -1937,7 +1938,7 @@ extern "C" int CMD_ARGC() extern "C" const char *CMD_ARGS() { - if( cmd_used ) + if( g_fCmdUsed ) { if(!GGM::cmd_args) return ""; @@ -1947,7 +1948,7 @@ extern "C" const char *CMD_ARGS() } extern "C" const char *CMD_ARGV( int i ) { - if( cmd_used ) + if( g_fCmdUsed ) { if( i < 0 || i >= GGM::cmd_argc|| !GGM::cmd_argv[i] ) return ""; diff --git a/dlls/gravgunmod.h b/dlls/gravgunmod.h index 4d7283b0..e285caeb 100644 --- a/dlls/gravgunmod.h +++ b/dlls/gravgunmod.h @@ -199,5 +199,6 @@ bool GGM_IsTempBanned( CBaseEntity *plr ); void GGM_TempBan( CBaseEntity *pEnt ); int GGM_ChangelevelVote( CBasePlayer *pPlayer, edict_t *pTrigger, const char *pszMapName ); void GGM_ClearVote( void ); +void GGM_StartVoteCommand( CBasePlayer *pPlayer, const char *pszCommand, const char *pszMessage ); #endif // GRAVGUNMOD_H