|
QuakeZone MOD Coding Tutorials
|
|
|
Introduction Code Notes Exercises |
|
| Introduction |
|
|
This tutorial shows you how to add Lox-style regenerative organic armour to your mod. When you pick up an armour item, you have a small chance of it being turbo armour. When it is, your armour quickly ramps up to 500, and when you take damage this value is quickly restored. |
| Code |
|
|
g_local.h At the end of the client_persistant_t struct, add the following line: qboolean turbo_armour; // PJT - turbo armour g_items.c Add the following lines the top of this file as indicated: #define HEALTH_TIMED 2 #define TURBO_ARMOUR_HIT 0.1 // PJT - turbo armour 0.5 for testing 0.1 is defaultAdd the following lines to procedure Pickup_Armor as indicated in the following places:
float salvage;
int salvagecount;
// PJT - turbo armour
if (other->client->pers.turbo_armour)
return false;
// PJT
....
// if player has no armor, just use it
else if (!old_armor_index)
{
// PJT - turbo armour
if (random() < TURBO_ARMOUR_HIT)
{
gi.cprintf (other, PRINT_HIGH, "Regeneration turbo-armour picked up\n");
other->client->pers.turbo_armour = true;
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
SetRespawn (ent, 20);
return true;
}
// PJT
other->client->pers.inventory[ITEM_INDEX(ent->item)] = newinfo->base_count;
....
// PJT - turbo armour
if (random() < TURBO_ARMOUR_HIT)
{
gi.cprintf (other, PRINT_HIGH, "Regeneration turbo-armour picked up\n");
other->client->pers.turbo_armour = true;
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
SetRespawn (ent, 20);
return true;
}
// PJT
....
// if we're already maxed out then we don't need the new armor
if (other->client->pers.inventory[old_armor_index] >= newcount)
return false;
// PJT - turbo armour
if (random() < TURBO_ARMOUR_HIT)
{
gi.cprintf (other, PRINT_HIGH, "Regeneration turbo-armour picked up\n");
other->client->pers.turbo_armour = true;
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
SetRespawn (ent, 20);
return true;
}
// PJT
p_client.c Add the following code as indicated into function ClientThink: level.current_entity = ent; client = ent->client; // PJT - turbo armour if ((!ent->deadflag) && (client->pers.turbo_armour) && (client->pers.inventory[jacket_armor_index] < 500)) client->pers.inventory[jacket_armor_index] += 1; // PJT |
| Notes |
|
|
g_local.h
g_items.c
p_client.c
|
| Exercises |
|
|