Experience system


 

Posted by NewB (24.161.203.*) at 3:30 PM, 12/5/2000:
In reply to: Experience system posted by DreamMaster (62.100.26.*) at 5:53 AM, 12/3/2000

Ok here is a quick one.
Every line taged // NewB is a line i have added or changed
you will also have to add in somewhere that only gets executed once (like ClientConnect) "ent->client->resp.lvl = 1;"
so they have a level, so we can use level checking for suiside or mod unknow, otherwise it will crash on the exp code because it will try to refrence to a non player entity's level.

if i put a line of ~~~~~~~~~ that means i left some of the origional quake code out.

1) go into the g_local.h, find the resp structure. Add an int called lvl and exp
typedef struct
{
client_persistant_t coop_respawn;
int enterframe;
int score;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

int exp;//NEWB
int lvl;//NEWB
} client_respawn_t;


Im going to just make this easy and have the experience checking in the ClientObituary, you can make a seperate function and have it called from player_die, clientobituary, or wherever you know a player has died, and who attacked them.

void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
{
int mod;

int lvl_diff, exp, targ_lvl, attacker_lvl; // NewB exp

char *message=NULL; // Maj++ - BugFix
char *message2=""; // Maj++ - BugFix
qboolean ff;

if (coop->value && attacker->client)
meansOfDeath |= MOD_FRIENDLY_FIRE;
// Begin NewB
// Begin Exp code.
if (attacker == self || !attacker->client->resp.lvl) // NewB Checks for suiside of mod from a levelless attacker.
{
self->client->resp.exp -= (2 * (self->client->resp.lvl));
self->client->resp.save_exp -= (2 * (self->client->resp.lvl));
}
else
{
targ_lvl = self->client->resp.lvl; // find target's level
attacker_lvl = attacker->client->resp.lvl; // Find attacker's level
lvl_diff = targ_lvl - attacker_lvl; // Find level difference

if (lvl_diff < -10)
lvl_diff = -10;
exp = random()*(10 + lvl_diff) + 6; // Find Exp value for this kill
attacker->client->resp.exp += exp; // add exp to the attacker's total
Check_Levelup(attacker); // Check for level up for attacker (Quadrant allready posted this bit i think, we are working on a mod together.)
}// End EXP
// End NewB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Continue client obit code.

Now you have to add the check level up function, if you don't add it above the ClientObituary you will have to add a regrence to it, (i.e. "void Check_Levelup (edict_t *attacker;" )
This is what it looks like.


/*
================
Check_Levelup
Checks to see if that player has leveled
NewB
================
*/
void Check_Levelup (edict_t *ent)
{
int current_level, needed;

current_level = ent->client->resp.lvl; //Make the current level a local varible, easy for manipulation, neater, and shorter.
needed = 500 * (current_level) * (current_level); // Next level is 500 times your current level squared.
if (ent->client->resp.exp >= needed) // checks to see if your exp is more than what you need
{
ent->client->resp.lvl++;// If it is add one to your level.
gi.dprintf ("-----=====%s is now level %d!=====-----\n", ent->client->pers.netname, ent->client->resp.lvl); // Tell everyone you have leveled, and what level you are.
}
}//End NewB

All that we did there was
1) define the lvl, and exp varibles in the client_resp_t
2) added varible manipulation (adding experince when needed, and level up check on that experience)

Its preaty basic and should be easy to understand and use.

(my spaceing got all cramed together, so i hope it is still readable, and not cramed together to the extent that lines are run together.)

 

 


Link: King of the server 2000