Posted by: DarkNight
Date posted: Apr 14 2003 User Rating: 5 out of 5.0 | Number of views: 3083 Number of comments: 1 | Description: Creating the Capture Point |
This part of the tutorial will show you how to create the Capture Point for the CTF Gamerules.
NOTE: This code will need modifying to suit your team system,ect so don't take this as a complete C&P (which it basically is).
Open up ctf_gameplay.h and put the following at the bottom:
| | |
// Capture point for Team 1 class CCaptureTeam1 : public CBaseEntity { public: void Spawn( ); void Precache( ); void EXPORT Touch(CBaseEntity *); void EXPORT Think( ); void KeyValue( KeyValueData* ); };
// Capture point for Team 2 class CCaptureTeam2 : public CBaseEntity { public: void Spawn( ); void Precache( ); void EXPORT Touch( CBaseEntity *); void EXPORT Think( ); void KeyValue( KeyValueData* ); };
|
In player.h, put the following in class CBasePlayer : public CBaseMonster in the publics under bool m_fHasObject;
Open up ctf_gameplay.cpp and put the following at the bottom:| | |
LINK_ENTITY_TO_CLASS( capture_team1, CCaptureTeam1 );
void CCaptureTeam1 :: Spawn( ) {
// Calls the precache function to precache any models, sounds,ect // you need before it spawns Precache( ); SET_MODEL( ENT(pev), STRING(pev->model) ); UTIL_SetOrigin( pev, pev->origin ); pev->movetype = MOVETYPE_FLY;
// This allows you to trigger it by walking through it pev->solid = SOLID_TRIGGER;
// This just sets our Touch to Touch and our Think to Think // which is down a little further. SetTouch(Touch); SetThink(Think);
// Sets next think time pev->nextthink = gpGlobals->time + 0.1;
// Make the entity invisible pev->rendermode = kRenderTransTexture; pev->renderamt = 0; }
// This is the Precache function which is called from the Spawn function.
void CCaptureTeam1 :: Precache( ) { PRECACHE_MODEL( (char*)STRING(pev->model) ); } void CCaptureTeam1 :: Think( ) { // loop through every player and check if they are in the area for(int i=0; i<gpGlobals->maxClients; i++) { CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex(i); if(pPlayer && pPlayer->m_iTeam == 1) { if((pPlayer->pev->origin.x >= pev->mins.x) && (pPlayer->pev->origin.x <= pev->maxs.x) && (pPlayer->pev->origin.y >= pev->mins.y) && (pPlayer->pev->origin.y <= pev->maxs.y) && (pPlayer->pev->origin.z >= pev->mins.z) && (pPlayer->pev->origin.z <= pev->maxs.z)) pPlayer->m_bInCapture = true; else pPlayer->m_bInCapture = false; } } // Set next think time pev->nextthink = gpGlobals->time + 0.1; }
// This is the Touch function which was set above, in the Spawn function, // its basically the stuff that runs when the capture point has been touched by a player
void CCaptureTeam1 :: Touch( CBaseEntity* pOther ) { // Determine if the object that touches it, is a player // and check if the player is alive. if(!pOther) return; if(!pOther->IsPlayer()) return; if(!pOther->IsAlive()) return;
CBasePlayer *pPlayer = (CBasePlayer *)pOther;
if(pPlayer && pPlayer->m_iTeam == 1) { // Check to see if they have the object if( !pPlayer->m_fHasObject ) return; else { // Print to HUD who has captured the flag UTIL_ClientPrintAll( HUD_PRINTCENTER, UTIL_VarArgs ( "%s has captured the Flag!\n", STRING( pPlayer->pev->netname )));
// Remove the flag pPlayer->m_fHasObject = false;
PLAYBACK_EVENT_FULL(0, pPlayer->edict(), g_usObject, 0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, FLAG_CAPTURE, 0, 0, 0);
// Reset the flag CObjectFlag *pFlag = (CObjectFlag *)UTIL_FindEntityByClassname(NULL, "object_flag"); if(pFlag) { pFlag->m_fIsInPlay = false;
// Do a funky effect on the flag when it gets reset pFlag->pev->effects = EF_BRIGHTFIELD; } } } else return; // wrong team }
void CCaptureTeam1 :: KeyValue( KeyValueData* Data ) { // This will store the points but its not fully implemented. I'll leave it for you to do. if( FStrEq( Data->szKeyName, "points" ) ) { int m_iPoints = atoi(Data->szValue); Data->fHandled = true; }
CBaseEntity::KeyValue(Data); // call the parent function }
|
| | |
LINK_ENTITY_TO_CLASS( capture_team2, CCaptureTeam2 );
void CCaptureTeam2 :: Spawn( ) { // Calls the precache function to precache any models, sounds,ect // you need before it spawns. Precache( ); SET_MODEL( ENT(pev), STRING(pev->model) ); UTIL_SetOrigin( pev, pev->origin ); pev->movetype = MOVETYPE_FLY;
// This allows you to trigger it by walking through it pev->solid = SOLID_TRIGGER;
// This just sets our Touch to Touch and our Think to Think // which is down a little further. SetTouch(Touch); SetThink(Think);
// Set next think time pev->nextthink = gpGlobals->time + 0.1;
// Make the entity invisible pev->rendermode = kRenderTransTexture; pev->renderamt = 0; }
void CCaptureTeam2 :: Precache( ) { PRECACHE_MODEL( (char*)STRING(pev->model) ); } void CCaptureTeam2 :: Think( ) { // loop through every player and check if they are in the area for(int i=0; i<gpGlobals->maxClients; i++) { CBasePlayer *pPlayer = (CBasePlayer *)UTIL_PlayerByIndex(i); if(pPlayer && pPlayer->m_iTeam == 2) { if((pPlayer->pev->origin.x >= pev->mins.x) && (pPlayer->pev->origin.x <= pev->maxs.x) && (pPlayer->pev->origin.y >= pev->mins.y) && (pPlayer->pev->origin.y <= pev->maxs.y) && (pPlayer->pev->origin.z >= pev->mins.z) && (pPlayer->pev->origin.z <= pev->maxs.z)) pPlayer->m_bInCapture = true; else pPlayer->m_bInCapture = false; } } // Set the next think time pev->nextthink = gpGlobals->time + 0.1; } void CCaptureTeam2 :: Touch( CBaseEntity* pOther ) { // Determine if the object that touches it, is a player // and check if the player is alive. if(!pOther) return; if(!pOther->IsPlayer()) return; if(!pOther->IsAlive()) return;
CBasePlayer *pPlayer = (CBasePlayer *)pOther;
if(pPlayer && pPlayer->m_iTeam == 2) { // Check to see if they have the object if( !pPlayer->m_fHasObject ) return; else { // Print to HUD who has captured the flag UTIL_ClientPrintAll( HUD_PRINTCENTER, UTIL_VarArgs ( "%s has captured the Flag!\n", STRING( pPlayer->pev->netname ))); // Remove the object pPlayer->m_fHasObject = false;
PLAYBACK_EVENT_FULL(0, pPlayer->edict(), g_usObject, 0, (float *)&g_vecZero, (float *)&g_vecZero, 0, 0, FLAG_CAPTURE, 0, 0, 0);
// Reset the object CObjectFlag *pFlag = (CObjectFlag *)UTIL_FindEntityByClassname(NULL, "object_flag"); if(pFlag) { pFlag->m_fIsInPlay = false;
// Do a funky effect on the flag when it gets reset pFlag->pev->effects = EF_BRIGHTFIELD; } } } else return; // Wrong team }
void CCaptureTeam2 :: KeyValue( KeyValueData* Data ) { // This will store the points but its not fully implemented. I'll leave it for you to do. if( FStrEq( Data->szKeyName, "points" ) ) { int m_iPoints = atoi(Data->szValue); Data->fHandled = true; }
CBaseEntity::KeyValue(Data); // call the parent function }
|
That just about raps it up for this part of the tutorial. If you have suggestions,complaints or need help with something from this tutorial, please email me at the_dark_wonderer@hotmail.com |
|
User Comments
Showing comments 1-1
Compiling... multiplay_gamerules.cpp C:\SDK\SourceCode\dlls\multiplay_gamerules.cpp(422) : error C2065: 'CDroppedFlag' : undeclared identifier C:\SDK\SourceCode\dlls\multiplay_gamerules.cpp(422) : error C2065: 'pFlag' : undeclared identifier C:\SDK\SourceCode\dlls\multiplay_gamerules.cpp(422) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\multiplay_gamerules.cpp(428) : error C2065: 'FLAG_DROPPED' : undeclared identifier teamplay_gamerules.cpp C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(371) : error C2065: 'pPlayer' : undeclared identifier C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(371) : error C2227: left of '->pev' must point to class/struct/union C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(371) : error C2227: left of '->netname' must point to class/struct/union C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(374) : error C2065: 'CDroppedFlag' : undeclared identifier C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(374) : error C2065: 'pFlag' : undeclared identifier C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(374) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\teamplay_gamerules.cpp(380) : error C2065: 'FLAG_DROPPED' : undeclared identifier ctf_gameplay.cpp C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(16) : error C2065: 'CObjectFlag' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(16) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(18) : error C2653: 'CObjectFlag' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(22) : error C2065: 'Precache' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(25) : error C2065: 'pev' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(27) : error C2227: left of '->origin' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(31) : error C2227: left of '->movetype' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(34) : error C2227: left of '->solid' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(37) : error C2065: 'm_pfnTouch' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(37) : error C2065: 'Touch' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(37) : error C2440: 'static_cast' : cannot convert from 'int' to 'void (__thiscall CBaseEntity::*)(class CBaseEntity *)' There are no conversions from integral values to pointer-to-member values C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(43) : error C2227: left of '->renderfx' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(44) : error C2227: left of '->rendercolor' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(44) : error C2228: left of '.x' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(45) : error C2227: left of '->rendercolor' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(45) : error C2228: left of '.y' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(46) : error C2227: left of '->rendercolor' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(46) : error C2228: left of '.z' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(47) : error C2227: left of '->renderamt' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(51) : error C2065: 'm_fIsInPlay' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(56) : error C2653: 'CObjectFlag' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(57) : error C2373: 'Precache' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(65) : error C2653: 'CObjectFlag' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(66) : error C2373: 'Touch' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(88) : error C2065: 'FLAG_STOLEN' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(93) : error C2227: left of '->effects' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(96) : error C2440: '=' : cannot convert from 'void (__thiscall CBaseEntity::*)(class CBaseEntity *)' to 'int' Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(101) : error C2065: 'CDroppedFlag' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(101) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(103) : error C2653: 'CDroppedFlag' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(104) : error C2084: function 'void __cdecl Spawn(void)' already has a body C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(113) : error C2227: left of '->origin' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(117) : error C2227: left of '->movetype' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(120) : error C2227: left of '->solid' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(123) : error C2440: 'static_cast' : cannot convert from 'int' to 'void (__thiscall CBaseEntity::*)(class CBaseEntity *)' There are no conversions from integral values to pointer-to-member values C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(129) : error C2227: left of '->effects' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(130) : error C2227: left of '->renderfx' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(131) : error C2227: left of '->rendercolor' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(131) : error C2228: left of '.x' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(132) : error C2227: left of '->rendercolor' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(132) : error C2228: left of '.y' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(133) : error C2227: left of '->rendercolor' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(133) : error C2228: left of '.z' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(134) : error C2227: left of '->renderamt' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(135) : error C2227: left of '->avelocity' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(135) : error C2228: left of '.z' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(140) : error C2653: 'CDroppedFlag' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(141) : error C2373: 'Precache' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(149) : error C2653: 'CDroppedFlag' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(150) : error C2373: 'Touch' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(172) : error C2065: 'm_pfnThink' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(172) : error C2065: 'SUB_Remove' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(172) : error C2440: 'static_cast' : cannot convert from 'int' to 'void (__thiscall CBaseEntity::*)(void)' There are no conversions from integral values to pointer-to-member values C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(175) : error C2227: left of '->nextthink' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(177) : error C2065: 'CCaptureTeam1' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(177) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(179) : error C2653: 'CCaptureTeam1' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(186) : error C2227: left of '->model' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(188) : error C2227: left of '->origin' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(189) : error C2227: left of '->movetype' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(192) : error C2227: left of '->solid' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(196) : error C2440: 'static_cast' : cannot convert from 'int' to 'void (__thiscall CBaseEntity::*)(class CBaseEntity *)' There are no conversions from integral values to pointer-to-member values C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(197) : error C2065: 'Think' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(197) : error C2440: 'static_cast' : cannot convert from 'int' to 'void (__thiscall CBaseEntity::*)(void)' There are no conversions from integral values to pointer-to-member values C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(200) : error C2227: left of '->nextthink' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(203) : error C2227: left of '->rendermode' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(204) : error C2227: left of '->renderamt' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(210) : error C2653: 'CCaptureTeam1' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(211) : error C2373: 'Precache' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(212) : error C2227: left of '->model' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(214) : error C2653: 'CCaptureTeam1' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(215) : error C2373: 'Think' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(220) : error C2039: 'm_iTeam' : is not a member of 'CBasePlayer' C:\SDK\SourceCode\dlls\player.h(71) : see declaration of 'CBasePlayer' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(222) : error C2227: left of '->mins' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(222) : error C2228: left of '.x' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(222) : error C2227: left of '->maxs' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(222) : error C2228: left of '.x' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(223) : error C2227: left of '->mins' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(223) : error C2228: left of '.y' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(223) : error C2227: left of '->maxs' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(223) : error C2228: left of '.y' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(224) : error C2227: left of '->mins' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(224) : error C2228: left of '.z' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(224) : error C2227: left of '->maxs' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(224) : error C2228: left of '.z' must have class/struct/union type C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(232) : error C2227: left of '->nextthink' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(238) : error C2653: 'CCaptureTeam1' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(239) : error C2373: 'Touch' : redefinition; different type modifiers C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(251) : error C2039: 'm_iTeam' : is not a member of 'CBasePlayer' C:\SDK\SourceCode\dlls\player.h(71) : see declaration of 'CBasePlayer' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(266) : error C2065: 'FLAG_CAPTURE' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(270) : error C2065: 'pFlag' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(270) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(273) : error C2227: left of '->m_fIsInPlay' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(276) : error C2227: left of '->pev' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(276) : error C2227: left of '->effects' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(284) : error C2653: 'CCaptureTeam1' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(293) : error C2352: 'CBaseEntity::KeyValue' : illegal call of non-static member function C:\SDK\SourceCode\dlls\cbase.h(149) : see declaration of 'KeyValue' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(295) : error C2065: 'CCaptureTeam2' : undeclared identifier C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(295) : error C2059: syntax error : ')' C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(297) : error C2653: 'CCaptureTeam2' : is not a class or namespace name C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(303) : error C2227: left of '->model' must point to class/struct/union C:\SDK\SourceCode\dlls\ctf_gameplay.cpp(303) : fatal error C1003: error count exceeds 100; stopping compilation Error executing cl.exe.
hl.dll - 113 error(s), 0 warning(s)
:( |
|
You must register to post a comment. If you have already registered, you must login.
|
296 Approved Articless
6 Pending Articles
3940 Registered Members
0 People Online (17 guests)
|
|