Changing Ammo Values - Simplfied

Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Changing Ammo Values - Simplfied

Post by Lordpalandus »

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
User avatar
Eraser
Posts: 19177
Joined: Fri Dec 01, 2000 8:00 am

Re: Changing Ammo Values - Simplfied

Post by Eraser »

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: Select all

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).
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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?
User avatar
Eraser
Posts: 19177
Joined: Fri Dec 01, 2000 8:00 am

Re: Changing Ammo Values - Simplfied

Post by Eraser »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

So, in that case I'd change the interger "int MAXAMMO = 400" to make all weapons have a maximum of 400 ammo?
User avatar
Eraser
Posts: 19177
Joined: Fri Dec 01, 2000 8:00 am

Re: Changing Ammo Values - Simplfied

Post by Eraser »

You could do just this:

Code: Select all

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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?
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Changing Ammo Values - Simplfied

Post by ^misantropia^ »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

Yes just the ammo count stuff. Not interested in the rest at the moment.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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?
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

Nevermind, I see the problem there now too. I was using a different version of the source than you were using in the tutorial.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

Also the files created by running the .bat (batch) files all have the suffix .asm, not .qvm .
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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?
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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.
User avatar
Eraser
Posts: 19177
Joined: Fri Dec 01, 2000 8:00 am

Re: Changing Ammo Values - Simplfied

Post by Eraser »

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: Select all

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

Code: Select all

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

Code: Select all

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: Select all

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
User avatar
Eraser
Posts: 19177
Joined: Fri Dec 01, 2000 8:00 am

Re: Changing Ammo Values - Simplfied

Post by Eraser »

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: Select all

   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: Select all

   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.
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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?
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

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)
Lordpalandus
Posts: 24
Joined: Tue May 03, 2011 5:28 am

Re: Changing Ammo Values - Simplfied

Post by Lordpalandus »

Found weapon fire speeds under bg_pmove.c
Locked