Quake3World.com Forums
     Programming Discussion
        Changing Ammo Values - Simplfied


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Changing Ammo Values - Simplfied

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-02-2011 09:33 PM           Profile Send private message  E-mail  Edit post Reply with quote


Hi, I've been playing Q3 for close to a decade now. I've always wanted to change the Maximum Ammo, for certain guns, namely the machine gun. Is there a simple way of changing the Maximum Ammo for weapons, ie an available file for download, or a quick simple guide, for someone, like myself who is not very good at coding, compiling, or modding?

Also, once the changes are made, will the game automatically register the changes?

Any help would be appreciated.

- Lordpalandus




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-02-2011 11:00 PM           Profile   Send private message  E-mail  Edit post Reply with quote


Unless there's already a mod that allows you to configure this yourself, I'm afraid that you'll end up having to write a mod for this.

Are you looking at a guide for coding your own mod? If so, read the first two pages of this article here. Once you're good to go, have a look at the file g_items.c (in the "game" directory) at the function Add_Ammo. You'll notice that it checks if the ammo for the weapon is more than 200 and if so, caps it off at 200.

You could change this code into this:

Code:
void Add_Ammo (gentity_t *ent, int weapon, int count)
{
   int maxAmmo = 200;

   if ( weapon == WP_MACHINEGUN )
      maxAmmo = 500;
   else if ( weapon == WP_SHOTGUN )
      maxAmmo = 300;
   else if ( weapon == WP_ROCKET_LAUNCHER )
      maxAmmo = 25;

   ent->client->ps.ammo[weapon] += count;
   if ( ent->client->ps.ammo[weapon] > maxAmmo ) {
      ent->client->ps.ammo[weapon] = maxAmmo;
   }
}


In this example, ammo for all weapons is capped at 200, except for the MG (you can carry 500 bullets), the SG (you can carry 300 shells) and the RL (you can carry 25 rockets).




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:13 AM           Profile Send private message  E-mail  Edit post Reply with quote


So in the example you gave, only those three weapons would have changed ammo values? All the other weapon ammo values would remain the same?




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-03-2011 09:28 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Yes indeed.
If you would want to change the max ammo for all weapons to the same value, then you could simply replace that 200 in the original code with any other number.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:34 AM           Profile Send private message  E-mail  Edit post Reply with quote


So, in that case I'd change the interger "int MAXAMMO = 400" to make all weapons have a maximum of 400 ammo?




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-03-2011 09:53 AM           Profile   Send private message  E-mail  Edit post Reply with quote


You could do just this:

Code:
void Add_Ammo (gentity_t *ent, int weapon, int count)
{
   ent->client->ps.ammo[weapon] += count;
   if ( ent->client->ps.ammo[weapon] > 400 ) {
      ent->client->ps.ammo[weapon] = 400;
   }
}


Then all weapons in the game have a maximum ammo of 400.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 02:07 PM           Profile Send private message  E-mail  Edit post Reply with quote


K, so I got it (source files) loaded up in Visual C++ Studio, and editted the ammo values. Now, how do I turn it into a playable mod?




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 03:06 PM           Profile Send private message  E-mail  Edit post Reply with quote


K, so I followed your instructions on your site, got 7 errors (dunno why) when build solution (w/ Release), and I do not know how to add the commandline parameter, or the commandline parameter is not working.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 03:08 PM           Profile Send private message  E-mail  Edit post Reply with quote


Actually found the errors in the Build Log:

Compiling...
win_wndproc.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
win_syscon.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
win_snd.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
win_shared.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
win_net.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
win_main.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
win_input.c
c:\users\jason\desktop\patch\quake3-1.32b\code\win32\win_local.h(36) : fatal error C1083: Cannot open include file: 'dinput.h': No such file or directory
vm_x86.c
vm_interpreted.c
vm.c

Don't have a clue what this all means tho.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 05-03-2011 03:28 PM           Profile Send private message  E-mail  Edit post Reply with quote


You're trying to build the engine and the SDK and don't have the DirectX SDK installed. But I wager that all you want is the SDK, that's where stuff like ammo count lives.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 04:10 PM           Profile Send private message  E-mail  Edit post Reply with quote


Yes just the ammo count stuff. Not interested in the rest at the moment.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 04:11 PM           Profile Send private message  E-mail  Edit post Reply with quote


Course, itd proly be simplest if someone else just made the thing for me and posted a download link or something. Then again, I dunno.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 05:57 PM           Profile Send private message  E-mail  Edit post Reply with quote


Ok, I noticed what I did wrong in the first, place, and I'm on the second page, but I cannot find the /bin folder. Am I supposed to run the .bat files first, or is it somewhere else?




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 05:58 PM           Profile Send private message  E-mail  Edit post Reply with quote


Nevermind, I see the problem there now too. I was using a different version of the source than you were using in the tutorial.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 08:58 PM           Profile Send private message  E-mail  Edit post Reply with quote


K, I tried it with your source code provided in the link this time. Build (Release) solution caused 0 errors this time and about 50% less warnings. dll files work fine. When trying to make the qvm files (im assuming the q stands for quake) there is no output sent to my Quake 3 Folder. There is some output in the vm folders I made in each of the sub-folders in code, but not in Quake 3 folder.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:04 PM           Profile Send private message  E-mail  Edit post Reply with quote


Also the files created by running the .bat (batch) files all have the suffix .asm, not .qvm .




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:26 PM           Profile Send private message  E-mail  Edit post Reply with quote


void Add_Ammo (gentity_t *ent, int weapon, int count)
{
int maxAmmo = 200;

if ( weapon == WP_MACHINEGUN )
maxAmmo = 500;
else if ( weapon == WP_SHOTGUN )
maxAmmo = 300;
else if ( weapon == WP_ROCKET_LAUNCHER )
maxAmmo = 25;

ent->client->ps.ammo[weapon] += count;
if ( ent->client->ps.ammo[weapon] > maxAmmo ) {
ent->client->ps.ammo[weapon] = maxAmmo;
}
}

and

void Add_Ammo (gentity_t *ent, int weapon, int count)
{
ent->client->ps.ammo[weapon] += count;
if ( ent->client->ps.ammo[weapon] > 400 ) {
ent->client->ps.ammo[weapon] = 400;
}
}

Do not work. I've tried both. The ammo maximum remains at 200 for all guns. However, the mod is functioning correctly as I have been able to change the respawn time on items, such as Ammo set to 5 seconds. And, in game the Ammo does actually respawn in 5 seconds. However I cannot increase max ammo past 200.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:35 PM           Profile Send private message  E-mail  Edit post Reply with quote


K this is strange. Altho I cannot manually get the ammo to a new maximum, somehow with the code I managed a partial victory. I got 231 ammo for the machine gun. However I couldn't pick up more ammo packs until it was 199 or less. And if I had 199, it would add 50 bullets.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:41 PM           Profile Send private message  E-mail  Edit post Reply with quote


Ok, tried changing the MaxAmmo value higher, didn't work. However still had the oddity where my machine gun ammo went up to 249, iff I had 199 ammo before picking up the ammo box.

In the code: ent->client->ps.ammo[weapon]

What does this string mean? Is it possible that "ps.ammo [weapon]" is causing issues with changing maximum ammo?




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 09:46 PM           Profile Send private message  E-mail  Edit post Reply with quote


Also, with my limited programming background, I know that with brackets you must match brackets with brackets.

ent->client->ps.ammo[weapon] += count;
if ( ent->client->ps.ammo[weapon] > 400 ) {
ent->client->ps.ammo[weapon] = 400;
}

So, why is "ent->client->ps.ammo[weapon] = 400;
}" bracketed off on its own? Also, with my limited background knowledge, usually with an IF statement, theres a THEN statement that follows. I don't see a THEN statement here.




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-03-2011 09:48 PM           Profile   Send private message  E-mail  Edit post Reply with quote


Oh right, I overlooked something.
You also need to edit the BG_CanItemBeGradded function in bg_misc.c

You'll find this bit of code in there:
Code:
case IT_AMMO:
    if ( ps->ammo[ item->giTag ] >= 200 ) {
        return qfalse;      // can't hold any more
    }
    return qtrue;


Change that to

Code:
case IT_AMMO:
    if ( ps->ammo[ item->giTag ] >= 400 ) {
        return qfalse;      // can't hold any more
    }
    return qtrue;


in combination with the

Code:
void Add_Ammo (gentity_t *ent, int weapon, int count)
{
   ent->client->ps.ammo[weapon] += count;
   if ( ent->client->ps.ammo[weapon] > 400 ) {
      ent->client->ps.ammo[weapon] = 400;
   }
}


in g_items.c

If you want to differentiate between each weapon, like in my first example, the code in bg_misc.c should be changed to something like this:

Code:
case IT_AMMO:
    switch ( item->giTag ) {
        case WP_MACHINEGUN:
            maxAmmo = 500;
            break;
        case WP_SHOTGUN:
            maxAmmo = 300;
            break;
        case WP_ROCKET_LAUNCHER:
            maxAmmo = 25;
            break;
        default:
            maxAmmo = 200;
            break;
    }
   
    if ( ps->ammo[ item->giTag ] >= maxAmmo ) {
        return qfalse;      // can't hold any more
    }
    return qtrue;


Don't forget to declare

int maxAmmo;

at the top of the function as well




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-03-2011 09:56 PM           Profile   Send private message  E-mail  Edit post Reply with quote


Lordpalandus wrote:
Also, with my limited programming background, I know that with brackets you must match brackets with brackets.

ent->client->ps.ammo[weapon] += count;
if ( ent->client->ps.ammo[weapon] > 400 ) {
ent->client->ps.ammo[weapon] = 400;
}

So, why is "ent->client->ps.ammo[weapon] = 400;
}" bracketed off on its own?


The { and } brackets are there for encapsulating code within a specific scope. So the code that should be executed if the "if" statement is true is placed between brackets. You'll notice that the opening bracket is on the same line as the if statement. It doesn't really matter if you place brackets on new lines, some people do that, it all comes down to personal preference.

Code:
   if ( ent->client->ps.ammo[weapon] > 400 )
   {
      ent->client->ps.ammo[weapon] = 400;
   }


would be just as valid. In fact, if there's only one single line of code to be executed after an if statement, the brackets can be completely omitted, which means that in this case

Code:
   if ( ent->client->ps.ammo[weapon] > 400 )
      ent->client->ps.ammo[weapon] = 400;


would be valid as well.

Lordpalandus wrote:
Also, with my limited background knowledge, usually with an IF statement, theres a THEN statement that follows. I don't see a THEN statement here.


If-statements in C are never accompanied by a "then". The same is true for C++, C#, Java, JavaScript and a whole bunch of other languages. You're probably used to seeing other programming languages such as Pascal, which do use the if ... then ... else construction.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-03-2011 10:34 PM           Profile Send private message  E-mail  Edit post Reply with quote


I'm a bit bombed at the moment so I'll try that later, and report back on it.

How would I edit things like:

1) Powerups (ie effects) [figured out how to affect respawn and duration of powerups already]

2) Maximum, unincreased HP/Armor (ie before HP or Armor slowly decreases over time)

3) Removing the Armor or HP degeneration effect above maximum HP/Armor.

4) Weapon Damage (Found Machine Gun, Guantlet and Shotgun damage, but not the other weapons)

5) Modifying the code to increase/decrease damage taken when wearing or not wearing armor, and how much armor is removed compared to HP removed when taking damage?




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-04-2011 12:18 PM           Profile Send private message  E-mail  Edit post Reply with quote


case IT_AMMO:
if ( ps->ammo[ item->giTag ] >= 200 ) {
return qfalse; // can't hold any more
}
return qtrue;

By editting this code, the ammo max values work now.

Also, found the other weapon damages under g_missile.c including splash radius + splash damage.

Still haven't figured out how to change maximum Armor/HP totals or modifying bonus HP / megahealth to different numbers (works with armor pickups tho)




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-04-2011 07:05 PM           Profile Send private message  E-mail  Edit post Reply with quote


Found weapon fire speeds under bg_pmove.c




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-05-2011 02:09 AM           Profile   Send private message  E-mail  Edit post Reply with quote


The amount of armor or health that armor and health bubbles give can be modified in bg_misc.c

In the beginning of the file you'll find the bg_itemlist definition. This holds definitions for all the items in the game.

You'll find the value 5 in the definition for armor shards, for example, right under "Armor Shard" and above IT_ARMOR. This means that armor shards give 5 of whatever they give to the player (in this case, armor). You'll notice you'll find 50 and 100 under item_armor_combat and item_armor_body respectively. You can change these values to give different amounts of armor.

Same goes for the definitions for item_health_*




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-05-2011 10:21 PM           Profile Send private message  E-mail  Edit post Reply with quote


Ah, but the thing is, if I change the amount given by the '5 hp bonus health' or the '100 hp bonus megahealth', it doesn't perform the 'bonus' part.

What I mean is, normally when you pick them up, they can increase your HP beyond the maximum of 100 to 200. If I change the values, they still heal health, but they do not increase health beyond the maximum.

The strange thing is tho, if I change the armor values, nothing bad happens and it can increase maximum armor past 100 just fine.

Also:
1) I'm trying to figure out how to increase those 'bonus' maximums from 200, to say, 300. Still haven't figured out how.
2) I can't find 'powerups' under any of the files currently... want to change say the regeneration from 5 hp/second to 10 hp/second for example. As well, what the hell does the battlesuit do?
3) How to modify the maximum clients per game without having to constantly type /sv_maxclients everytime I want more than 12 bots in a game.

Any thoughts?




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 05-06-2011 04:19 AM           Profile   Send private message  E-mail  Edit post Reply with quote


If you'd look a bit further in the BG_CanItemBeGrabbed function and the Pickup_Health function in g_items.c, The max health/armor thing can be adjusted there as well. I see something related to the health/armor countdowns when you're above 100 in the ClientTimerActions function in g_active.c, not sure if that's the only place that needs to be modified though. There's something there about the regen powerup as well.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-06-2011 11:14 AM           Profile Send private message  E-mail  Edit post Reply with quote


K thanks. Found where it degenerates HP and armor. However, was wondering how I would remove it so that any amount gained over 100 hp/armor would remain that way until you took damage? If I simply delete the code, I get an error message.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-06-2011 11:23 AM           Profile Send private message  E-mail  Edit post Reply with quote


Also, changed maximum health, I think, and the health pickups are still giving me problems.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-06-2011 11:32 AM           Profile Send private message  E-mail  Edit post Reply with quote


K, finally fixed the problem with the health pickups and maximum health. Apparently, there was 3 different spots in 3 different files where you had to change numbers around for it to work. I had been trying to do it by only changing 1 or 2 files out of 3. Now it properly increases to up to 500 hp, however, Armor values are still giving me issues pushing past 200. I'll keep looking.




Top
                 

Gibblet
Gibblet
Joined: 02 May 2011
Posts: 24
PostPosted: 05-06-2011 11:40 AM           Profile Send private message  E-mail  Edit post Reply with quote


Also, now figured out the maximum armor as well. Now to only figure out how to mess around with other powerups, removing armor/hp degeneration, and modifying the armor/hp damage ratio.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.