Limiting Armor in Class Based Mods!

I've seen quite a few requests for this on the Qdevels web board, so I looked into it one afternoon and I figured it out.  This add-on will let you set the maximum amount of armor that each of your classes can have.   Let's get started!

Add in the blue code and take out any pink code.

First let's open up g_local.h and go down to the client persistent structure.  We need to declare a new variable so add in the line as shown:

    // ammo capacities
    int             max_bullets;
    int             max_shells;
    int             max_rockets;
    int             max_grenades;
    int             max_cells;
    int             max_slugs;
   
   
int player_armor;

Next we need to add in a few lines in g_items.c that will check to see if we have gone over our maximum armor limit and then set it to the right amount.  Go down to the pickup_armor function and add in the indicated lines:

            // calc new armor values
            salvage = newinfo->normal_protection / oldinfo->normal_protection;
            salvagecount = salvage * newinfo->base_count;
            newcount = other->client->pers.inventory[old_armor_index] + salvagecount;
            if (newcount > oldinfo->max_count)
                newcount = oldinfo->max_count;

            // 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;

            // update current armor value
            other->client->pers.inventory[old_armor_index] = newcount;
        }
    }

    if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
        SetRespawn (ent, 20);

    if ((other->client->pers.inventory[jacket_armor_index]) + (other->client->pers.inventory[combat_armor_index]) + (other->client->pers.inventory[body_armor_index]) > (other->client->pers.player_armor))
        other->client->pers.inventory[old_armor_index] = other->client->pers.player_armor;

    return true;
}

Those few lines check to see if the total amount of armor is greater than the player_armor variable that you put in g_local.h.  Next open up p_client.c and go down to the clientpersistent function.  Depending on how you implemented your classes, this could be different.  If you followed my tutorial on adding classes then this will work just fine.  This is just an example, but you need to set the player_armor variable to a value, like this:

/*
==============
InitClientPersistant

This is only called when the game first initializes in single player,
but is called after each death and level change in deathmatch
==============
*/
void InitClientPersistant (gclient_t *client)
{   

   if (client->resp.class == 1)
    {
        //Class 1
        gitem_t          *item;

        memset (&client->pers, 0, sizeof(client->pers));

    item = FindItem("Blaster");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 1;
    item = FindItem("Jacket Armor");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 25;
    item = FindItem("Rockets");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 30;
    item = FindItem("Rocket Launcher");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 1;

        client->pers.weapon = item;

client->pers.player_armor     = 100;//Max Armor for Class1


    }
    else if (client->resp.class == 2)
    {
        //Class 2
        gitem_t          *item;

    memset (&client->pers, 0, sizeof(client->pers));

    item = FindItem("Blaster");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 1;
    item = FindItem("Combat Armor");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 50;
    item = FindItem("Slugs");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 30;
    item = FindItem("Railgun");
    client->pers.selected_item = ITEM_INDEX(item);
    client->pers.inventory[client->pers.selected_item] = 1;

    client->pers.weapon = item;


   
client->pers.player_armor    = 50;//Max Armor for Class 2

    }
    else
    {

    //Observer mode, doesn't really matter what they have
        gitem_t          *item;

        memset (&client->pers, 0, sizeof(client->pers));
   
        item = FindItem("Combat Armor");
        client->pers.selected_item = ITEM_INDEX(item);
        client->pers.inventory[client->pers.selected_item] = 1;

        client->pers.weapon = item;
    }

    client->pers.health              = 100;
    client->pers.max_health        = 100;

    client->pers.max_bullets    = 200;
    client->pers.max_shells        = 100;
    client->pers.max_rockets    = 50;
    client->pers.max_grenades    = 50;
    client->pers.max_cells        = 200;
    client->pers.max_slugs        = 50;

    client->pers.connected = true;
}

As you can see, you just need to add in the player_armor variable and set it to a value, in someplace around where you gave each class it's weapons and ammo.  That's it!  Now your classes can have different armor values, so you can give your "heavy weapons" class a very high armor count while your light "scout" classes can have low armor values.

Have fun!

Tutorial by Willi