The Place to Start


Time-Based Awards 
Extortionist
Intermediate


Time-Based Awards
Editor: New code in RED , old code in YELLOW.

Hi... This is my first tutorial, so bear with me if it's bad... Anyway, this
will show you how to give points to players after a certain amount of time. The
way I have it set up, it give points based on the current player class... In
this tutorial I'll leave that up to you... I'm sure it could be adapted for KOTH
or whatever you want to do. Now onto the code!
(I'm going to assume that you have your source and liblist.gam all set up)

Open up player.h

Anywhere in the player class, add this:

// extortionist
float   m_flNextAward;
virtual void Award( void );
// extortionist


Now go open player.cpp, and go down to about line 4890 after the Switch Weapon
function (I don't think this matters too much, but I keep my player.cpp funcs
here)

add this:

// extortionist
void CBasePlayer::Award( void )
{
        if ( /* your args here */ )
        {
                if ( gpGlobals->time >= m_flNextAward  )
                {
                        if ( /*something to seperate the awardees from the not awardees*/ )
                        {
                                pev->frags = pev->frags + CVAR_GET_FLOAT("mod_awardpoints");
                                ClientPrint(pev,HUD_PRINTTALK,"You have been awarded points!\n");
                        }

                        // if you want people to lose points when the awardees get //points
                        else if ( /* the other side of the argument before */ )
                        {
                                pev->frags = pev->frags - CVAR_GET_FLOAT("mod_awardloss");
                                ClientPrint(pev, HUD_PRINTTALK, "You have lost points!\n");
                        }
                m_flNextAward = gpGlobals->time + CVAR_GET_FLOAT("tag_awardtime");

                }
        }
}
// extortionist


Now search for PlayerThink (within the player.cpp file, not the whole project).
It'll take you to "g_pGameRules->PlayerThink( this );" Right before that, add:

// extortionist
Award();
// extortionist


Now open up game.cpp (this is where we get to define the CVars!)

scroll down until you see "cvar_t allowmonsters={"mp_allowmonsters","0",
FCVAR_SERVER};"

Right under this, add:

// extortionist
cvar_t          awardtime={"mod_awardtime","30", FCVAR_SERVER};
cvar_t          awardpoints={"mod_awardpoints","10", FCVAR_SERVER};
cvar_t          awardloss={"mod_awardloss","5", FCVAR_SERVER};
// extortionist

now scroll down to "CVAR_REGISTER (&awardloss);"

Add this below it:

// extortionist
CVAR_REGISTER (&awardtime);
CVAR_REGISTER (&awardpoints);
CVAR_REGISTER (&awardloss);
// extortionist


Now open game.h and scroll down to "extern cvar_t defaultteam;"
(btw: I'm not sure if this part is necessary, but it's better to be safe than
sorry)

Under that, add:

//extortionist
extern cvar_t   awardpoints;
extern cvar_t   awardtime;
extern cvar_t   awardloss;
//extortionist


There! All done! Go ahead and compile and test it out... assuming you have your
arguments all set up.

There three CVars we set up control the points you get (or lose), and the time
between awards. You change them by typing mod_award** * in the console while
you're playing (the ** being points, loss, or time... the * being the points or
time you want to switch to). Note: If you change the awardtime during the game,
it won't change until after the next points are given.

If you use this in a mod, please give me some credit in the readme, or at least
e-mail me and tell me thanks. If there are any problems with this (other than that 
it won't work until you put your args in the if's), e-mail me.

Any questions or suggestions should be sent to me: extortionist@halflifehq.com