Denne side indeholder artikler med forskellige perspektiver på Identity & Access Management i private og offentlige organisationer. Artiklerne behandler aktuelle IAM-emner og leveres af producenter, rådgivere og implementeringspartnere.
#define ISCORE_NORMAL 1 // player gets 1 frag #define ISCORE_SUICIDE -1 // player loses 1 frag #define ISCORE_TEAM -1 // player loses 1 frag
//Lets also add the \'externs\' we will be using:
extern DLL_GLOBAL BOOL g_fGameOver;
extern int gmsgTeamScore; // teamname-frags-deaths extern int gmsgGameMode; // gamemode-updates scoreboard extern int gmsgSayText; // saytext (used to display messages) extern int gmsgTeamInfo; // teaminfo (sends team names to client) extern int gmsgDeathMsg; // death messages extern void respawn(entvars_t *pev, BOOL fCopyCorpse); // needed to respawn players
/* ========================================================================= | Restart Round | ========================================================================= In this function you should reset any vars used during the round, as well as clean up the map (eg reset doors, glass, etc) */ void CRoundRules::RestartRound ( void ) { m_RoundState = ROUND_NOTSTARTED; m_flRoundTime = gpGlobals->time + ROUNDTIME_SETUP; }
/* ========================================================================= | Check Round Start | ========================================================================= This checks for the start of a valid round */
void CRoundRules::CheckRoundStart (void) { int iRed = 0; int iBlue = 0; int iSpc = 0; BOOL roundstart = TRUE; BOOL roundstate = TRUE;
// loop through all clients, count number of players on each team for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
if ( plr ) { const char *pTeamName = plr->TeamID(); if (FStrEq(pTeamName, TEAM_RED)) iRed++; else if (FStrEq(pTeamName, TEAM_BLUE)) iBlue++; else if (FStrEq(pTeamName, TEAM_SPECTATOR)) iSpc++; else ALERT(at_console, \"Unknown Team <%s>\\n\", pTeamName); } }
if ((iRed==0)||(iBlue==0)) roundstart = FALSE; else roundstate = TRUE;
if (roundstart) { // start the round m_RoundState = ROUND_STARTED; // set the time of the round m_flRoundTime = gpGlobals->time + ROUNDTIME_LIMIT; // check for winner in 10 secs m_flCheckRound = gpGlobals->time + ROUNDTIME_CHECK; // respawn everyone for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i ); if (plr) respawn (plr->pev, FALSE); } } else // cant start the round yet...wait half of the setup time m_flRoundTime = gpGlobals->time + (ROUNDTIME_SETUP / 2); }
/* ========================================================================= | Check Round End | ========================================================================= This checks for the end of a round */ void CRoundRules::CheckRoundEnd ( void ) {
int iRed = 0; int iBlue = 0; int iSpc = 0; BOOL roundstart = TRUE;
// loop through all clients, count number of players on each team for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i );
if ( plr->IsAlive() ) { const char *pTeamName = plr->TeamID(); if (FStrEq(pTeamName, TEAM_RED)) iRed++; else if (FStrEq(pTeamName, TEAM_BLUE)) iBlue++; else ALERT(at_console, \"Unknown Team <%s>\\n\", pTeamName); } }
if ((iRed == 0) && (iBlue != 0)) // everyone dead team1 RoundEnd ( ALL_TEAM1_KILLED ); else if ((iBlue == 0)&&(iRed != 0)) // everyone dead team2 RoundEnd ( ALL_TEAM2_KILLED ); else if ((iBlue == 0)&&(iRed == 0)) // everyone dead RoundEnd( DRAW ); else m_flCheckRound = gpGlobals->time + 10.0;
/* ========================================================================= | CRoundRules Constructor | ========================================================================= This is the constructor...how *exciting* */
/* ========================================================================= | Think | ========================================================================= Heres another biggie...This is the heart of the round rules system (How many times have I said that?) Basically, I do a switch for the m_RoundState then depending on what time it is, I call other functions. Simple? */
void CRoundRules :: Think ( void ) { ///// Check game rules ///// switch (m_RoundState) { case ROUND_NOTSTARTED: if ( m_flRoundTime <= gpGlobals->time) CheckRoundStart() ; break; case ROUND_STARTED: if ( m_flRoundTime <= gpGlobals->time) RoundEnd ( TIME_UP ); if ( m_flCheckRound <= gpGlobals->time ) CheckRoundEnd (); break; case ROUND_END: if ( m_flRoundTime <= gpGlobals->time ) RestartRound(); break; default: ALERT(at_console, \"Unknown Round State\\n\"); }
if ( g_fGameOver ) // someone else quit the game already { CHalfLifeMultiplay::Think(); return; } }
/* ========================================================================= | Round End | ========================================================================= This function is used to delay in between rounds, inform people of who won award points, put people in observer mode and update scores. I apply the same concept as the Think() I switch the reason, and depending on what it equals, I do different things. */
void CRoundRules::RoundEnd ( int reason ) { switch (reason) { default: case TIME_UP: // inform of time up // you can use UTIL_ClientPrintAll() or a HudMessage() break; case DRAW: // inform of draw break; case ALL_TEAM1_KILLED: // award points to team2 // inform of win break; case ALL_TEAM2_KILLED: // award points to team1 // inform of win break; }
// loop through all clients, put them in observer mode for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { CBasePlayer *plr = (CBasePlayer *)UTIL_PlayerByIndex( i ); if (plr) { // plr->your observer code(); } }
UpdateScores(); // if you need to use this function } ----------
håber i kan finde ud af det.... formateringen af koden er nok blevet lidt messy nu :)
enum { ROUND_NOTSTARTED = 0, // round is preparing to start ROUND_STARTED, // round is going ROUND_END, // round is stopped (prepare to prepare?) };
// Scoring enums:
enum { TIME_UP = 0, // time up--draw ALL_TEAM1_KILLED, // team 2 win ALL_TEAM2_KILLED, // team 1 win DRAW, // draw (ie both teams empty) };
// We need to put these here to be able to check the team names in other files:
#define TEAM_RED \"Red\" // red team #define TEAM_BLUE \"Blue\" // blue team #define TEAM_SPEC \"Spectator\" // im lazy sometimes #define TEAM_SPECTATOR \"Spectator\" // observer
//Declare class
class CRoundRules : public CHalfLifeMultiplay { public: CRoundRules();
// adds ability to add new client commands: virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd ); // when a player changes names, models, etc...we find out what happened: virtual void ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ); // make it teamplay to the rest of the code (ie other files) virtual BOOL IsTeamplay( void ) { return TRUE; } // used to check for team damage or damage amongst other players virtual BOOL FPlayerCanTakeDamage( CBasePlayer *pPlayer, CBaseEntity *pAttacker ); // check the relationship between two players virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget ); // returns the team name of the player (TeamID()) virtual const char *GetTeamID( CBaseEntity *pEntity ); // dont allow auto aim---ever virtual BOOL ShouldAutoAim( CBasePlayer *pPlayer, edict_t *target ) { return FALSE; } // used for scoring--if your gamerules made it so you had one VIP team (eg TFC) // and an enemy player killed your VIP, check here and award more points. virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ); // Start up screens, sending \'Player has joined\' messages, etc virtual void InitHUD( CBasePlayer *pl ); // alert everyone when someone dies. virtual void DeathNotice( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pevInflictor ); // Return the name of your game as it appears in the HL Game browser virtual const char *GetGameDescription( void ) { return \"Simple RoundRules\"; } // Update the scoreboard, I find this useful if you have several gamerules and // wish the scoreboard to display different Scoreboard names and/or setups virtual void UpdateGameMode( CBasePlayer *pPlayer ); // Player has been killed, award points, prepare the death message virtual void PlayerKilled( CBasePlayer *pVictim, entvars_t *pKiller, entvars_t *pInflictor ); // this is the guts of the round based gameplay system, it is short and simple // but controls the flow of the game virtual void Think ( void ); // gets the name of the team of index teamIndex. I dont think I use this virtual const char *GetIndexedTeamName( int teamIndex ); // checks if the team name is a valid one and returns TRUE/FALSE according so virtual BOOL IsValidTeam( const char *pTeamName ); // sets the Default player team (simple enough?) I set the default team to \'Spectator\' const char *SetDefaultPlayerTeam( CBasePlayer *pPlayer ); // changes the players team to whatever pTeamName is virtual void ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib ); // You\'ll need these for equiping players virtual void PlayerSpawn( CBasePlayer *pPlayer ); // In my gamerules, players couldnt respawn virtual BOOL FPlayerCanRespawn( CBasePlayer *pPlayer ) { return FALSE; } // client disconnected, use this to check if they were the VIP virtual void ClientDisconnected( edict_t *pClient ); // I dont want players to drop weapons virtual int DeadPlayerWeapons( CBasePlayer *pPlayer ) { return GR_PLR_DROP_GUN_NO; } // or ammo, when they die virtual int DeadPlayerAmmo( CBasePlayer *pPlayer ) { return GR_PLR_DROP_AMMO_NO; }
// New functions added:
//Checks for the end of a round virtual void CheckRoundEnd ( void ); //checks for the start of a round (ie...are there enough people to start?) virtual void CheckRoundStart ( void ); //end the round, inform the players with reason virtual void RoundEnd ( int reason ); //restart the round (this is a bit misleading) it is actually resetting the map for play virtual void RestartRound ( void ); //this is a nice hack...it updates the score board virtual void UpdateScores ( void );
//New variables:
//used for round timing float m_flRoundTime; //used for during round timing float m_flCheckRound; //holds current state of round int m_RoundState;
//Makes these private: // I rewrote the original valve function...you will want to do the same
Ikke alle C++ compilere accepterer at du skriver void i mellem paranteserne, når du ingen argumenter har til din funktion/procedure. Tror bestem det er DET der er problæemet.
Prøv at erstatte linge 19 med extern void GameDLLInit();
borrisholt> Det kan du have ret i.... skal prøve :)
er stadig helt ny i c++
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.