Posted by: omega
Date posted: May 12 2003 User Rating: 4 out of 5.0 | Number of views: 3312 Number of comments: 1 | Description: aka, like a ladder. |
A few days ago someone was asking in irc how to detect if a player is in jail or not for his mod. I had already written something like this for MMXHL a few years ago to disable WallJumping while inside the entity.
All of this is based off of the ladder code.
The first thing you need to do is pull up const.h and find CONTENTS_LADDER, and create your new content value; just use the next available number after contents_ladder. For this funcjail entity, i've created CONTENTS_JAIL.
The bulk of the code is inside triggers.cpp Find CLadder and duplicate all of its functions and rename it to CFuncJail (or whatever is suitible for what you want to use it for) All of the Customization steps are in comments below:
| | //============ func jail ==================
class CFuncJail : public CBaseTrigger { public: void KeyValue( KeyValueData *pkvd ); void Spawn( void ); void Precache( void ); };
LINK_ENTITY_TO_CLASS( func_jail, CFuncJail ); //link func_jail to CFuncJail
void CFuncJail :: KeyValue( KeyValueData *pkvd ) { CBaseTrigger::KeyValue( pkvd ); } void CFuncJail :: Precache( void ) { // Do all of this in here because we need to 'convert' old saved games pev->solid = SOLID_NOT; pev->skin = CONTENTS_JAIL; //make a new content type; go to CONTENTS_LADDER, add your new //content type with the next available number. if ( CVAR_GET_FLOAT("showtriggers") == 0 ) { pev->rendermode = kRenderTransTexture; pev->renderamt = 0; } pev->effects &= ~EF_NODRAW; } void CFuncJail::Spawn( void ) { Precache();
SET_MODEL(ENT(pev), STRING(pev->model)); // set size and link into world pev->movetype = MOVETYPE_PUSH; }
|
Now i've added a boolean to CBasePlayer for the server dll to reference if the player is in jail or not.
Now in player.cpp i've added a check into PlayerPrethink to set the bool's state:
| | if (UTIL_PointContents(pev->origin) == CONTENTS_JAIL) m_bInJail = true; else m_bInJail = false;
|
Now in order for the mapper to place this entity, we'll need an entry in our mods FGD.
| | @SolidClass base(Targetname) = func_jail : "in jail while inside" []
|
Thats It. Quite simple huh? As following my last tutorial i've started a new trend of my own; optional blocks of code, or reference!
Lets say you want to check this for movement purposes, you'll want to do this in pmove right? right. So in order to check if you're inside this entity inside pmove; all you have to do is use a check like:
| | if (pmove->PM_PointContents( pmove->origin, NULL ) == CONTENTS_JAIL )) { we're in jail! }
|
any time you wan't to check it. |
|
User Comments
Showing comments 1-1
This article is really helpful...
*Edit* No, that's not sarcasm :PEdited by TelimTor on Jun 03 2004, 08:36:31
|
|
You must register to post a comment. If you have already registered, you must login.
|
Any money that is donated will go towards the server costs that I incur for running our server. Don't feel you HAVE to donate, but the link is there if you want to help us out a little. Thanks :)
|
296 Approved Articless
3 Pending Articles
3940 Registered Members
0 People Online (18 guests)
|
|