Welcome, Guest! Login | Register

An Entity like a CS Buy Zone [Print this Article]
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:
 CODE  

//============ 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.
 CODE  

bool m_bInJail;

Now in player.cpp i've added a check into PlayerPrethink to set the bool's state:
 CODE  

    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.
 CODE  

@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:
 CODE  

if (pmove->PM_PointContents( pmove->origin, NULL ) == CONTENTS_JAIL ))
{
we're in jail!
}

any time you wan't to check it.

Rate This Article
This article is currently rated: 4 out of 5.0 (5 Votes)

You have to register to rate this article.
User Comments Showing comments 1-1

Posted By: TelimTor on Jun 03 2004 at 08:36:15
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.
Donate
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 :)

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 04 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 
Debugging your half-life 2 mod
Half-Life 2 | Coding | Articles
By: blackshark | Aug 17 2007
 
How to add Ammocrates for missing ammo type and/or create new ammo types
Half-Life 2 | Coding | Server Side Tutorials
By: EoD | Aug 15 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: G.I. Jimbo | May 19 2007
 
Reading and Writing Entire Structures
General | General Coding
By: monokrome | Jan 27 2007
 
VGUI Scope
Half-Life | Coding | Client Side Tutorials
By: Pongles | Jan 19 2007
 
Where do we go from here
General | News
By: SilentSounD | Jan 18 2007
 

Site Info
296 Approved Articless
3 Pending Articles
3940 Registered Members
0 People Online (18 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!