|
QuakeZone MOD Coding Tutorials
|
|
|
Introduction Code Notes Exercises |
|
| Introduction |
|
|
This tutorial shows you how to add a Lox-style regenerative healthbox to your mod. When you pick up a health item, you have a small chance of it being a healthbox. When it is, your health quickly ramps up to 400, 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 health_box; // PJT - healthbox g_items.c Add the following lines as indicated into function Pickup_Health: if (!(ent->style & HEALTH_IGNORE_MAX))
if (other->health >= other->max_health)
return false;
// PJT - health box
if (!other->client)
return false;
if (other->client->pers.health_box)
return false;
if (random() < 0.10) // change to 0.5 for testing/debugging
{
gi.cprintf (other, PRINT_HIGH, "Regeneration healthbox picked up\n");
other->max_health = 400;
other->client->pers.health_box = true;
if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
SetRespawn (ent, 30);
return true;
}
// PJT
p_client.c Add the following code as indicated into function ClientThink: level.current_entity = ent; client = ent->client; // PJT - health box if ((!ent->deadflag) && (client->pers.health_box) && (ent->health < ent->max_health)) ent->health += 1; // PJT |
| Notes |
|
|
g_local.h
g_items.c
p_client.c
|
| Exercises |
|
|