True semi-auto (as opposed to slow full-auto like it is now)


(Malo) #1

The subject line is pretty self-explanatory.
In ET all the weapons are full auto, the weapons that SHOULD be semi-auto simply has a lower rate of fire.
As long as you hold your mouse button down the weapons will keep firing continuously, even the sniper rifles.

How hard would it be make the weapons stop firing after a certain amount of time? I.e. after you press your attack button, the attack sequence will break after a certain amount of time has passed, say 100ms, you’d have to press your attack button again to fire another shot.
Would it require many lines of code?

This would also be useful if a burst firemode were to be implemented; simply increase the time so that the weapon has time to fire 3 rounds before breaking.

Needless to say I’m not a developer (I’m a modeler/animator), but I’m hoping that poking around in the source, reading comments in the code and changing things and then testing to see the results will prove to be a great way to learn.
I’ve successfully changed damage, rate of fire, spread and muzzle climb and some other things in just a couple of hours.

Thanks in advance.


(bacon) #2

It woudn’t really be that hard…


(Chruker) #3

… hoping that poking around in the source, reading comments in the code and changing …

Here is a quote from q_shared.h:


#define	MAX_MODELS			256		// these are sent over the net as 8 bits (Gordon: upped to 9 bits, erm actually it was already at 9 bits, wtf?
							// NEVAR TRUST GAMECODE COMMENTS, comments are evil :E, lets hope it doesnt horribly break anything....)
#define	MAX_SOUNDS			256		// so they cannot be blindly increased

:slight_smile:


(Malo) #4

Hehe yeah I’ve found lots of other amusing comments aswell.

Anyways, after searching for a solution I stumpled upon this thread:
http://www.forumplanet.com/planetquake/topic.asp?fid=2892&tid=1237814&p=1#13356341
It seems to be a better way of doing it, it’s for q3a but since the RTCW and ET are based on the q3 engine it should work I guess.


(bacon) #5

The way I’d do it is make altfire turn on/off an entity flag on the client then “hack” the overheat data for the semi-auto weapons.


(Malo) #6

Ok, after changing the q3 code in the link I posted above from this:

   if (!(ps->pm_flags & PM_FIREHELD) || (ps->weapon != WP_YOURWEAPON)) {
      PM_AddEvent(EV_FIRE_WEAPON);
      ps->pm_flags |= PM_FIREHELD;
   }
   if (!(cmd->buttons & BUTTON_ATTACK) || (ps->weapon != WP_YOURWEAPON)) {
      ps->pm_flags &= ~FIREHELD;
   }

To this (PM_Weapon in bg_pmove.c) :

	if (!(pm->ps->pm_flags & PMF_FIREHELD) || (pm->ps->weapon != WP_COLT)) {
		PM_AddEvent(EV_FIRE_WEAPON);
		pm->ps->pm_flags |= PMF_FIREHELD;
	}

	if (!(pm->cmd.buttons & BUTTON_ATTACK) || (pm->ps->weapon != WP_COLT)) {
		pm->ps->pm_flags &= ~PMF_FIREHELD;
	}

I simply changed it until it would compile, with ps->pm_flags it would just complain that ps was undeclared, same with cmd->buttons, changed that to pm->cmd.buttons and so on.
Also added a #define PMF_FIREHELD 1024 in bg_public.h

The results as I launced the mod and started a /devmap fueldump were bizarre:
As I spawned, the thompson immediately let off a farting sound, like a RC airplane engine, and fired like 10 000+ rounds a minute, dumping spent shell casings in a thick stream.
All the weapons behaved the same, including the knife (with a different noise obviously).

This happened when the weapons were supposed to be idle, I wasn’t pressing the firing button, also the ammo count wasn’t affected.
As soon as I pressed the fire button, the weapons started firing in their normal rates of fire, and the ammo count would decrease.
Once I released the button, it went back to the bizarre fart mode.

The weapon fire sound samples were being triggered so fast that together they formed a low/medium frequency tone.

Anyways, because of this experience I’ve decided to try to pick up some C programming tutorials, it’s just that I find it hard to concentrate using that method, it’s so boring I can barely stay awake.


(bacon) #7
if (!(pm->ps->pm_flags & PMF_FIREHELD) || (pm->ps->weapon != WP_COLT)) { 
      PM_AddEvent(EV_FIRE_WEAPON); 
      pm->ps->pm_flags |= PMF_FIREHELD; 
   }

Basically, if fire is held OR the weapon isn’t a colt do this.

if (!(pm->cmd.buttons & BUTTON_ATTACK) || (pm->ps->weapon != WP_COLT)) { 
      pm->ps->pm_flags &= ~PMF_FIREHELD; 
   }

Pretty much the same as above. You might wanna change the ||s to &&s and see what happens :slight_smile:

OR you could try changing the checkfire routine to this:

// check for fire
	// if not on fire button and there's not a delayed shot this frame...
	// consider also leaning, with delayed attack reset
	if((!(pm->cmd.buttons & (BUTTON_ATTACK | WBUTTON_ATTACK2)) && !delayedFire) ||
	  (pm->ps->leanf != 0 && pm->ps->weapon != WP_GRENADE_LAUNCHER && pm->ps->weapon != WP_GRENADE_PINEAPPLE && pm->ps->weapon != WP_SMOKE_BOMB))
	{
		pm->ps->weaponTime	= 0;
		pm->ps->weaponDelay	= 0;

		// bacon - attack isn't being pressed
		if (!(pm->cmd.buttons & BUTTON_ATTACK))
			pm->ps->pm_flags &= ~PMF_FIREHELD;
	
		if(weaponstateFiring) {	// you were just firing, time to relax
			PM_ContinueWeaponAnim(PM_IdleAnimForWeapon(pm->ps->weapon));
		}

		pm->ps->weaponstate = WEAPON_READY;
		return;
	}

	// bacon - single fire
	if ( (pm->ps->pm_flags & PMF_FIREHELD) && ( pm->ps->weapon == WP_YOURWEAP1 || pm->ps->weapon == WP_YOURWEAP2) )
		return;
	pm->ps->pm_flags |= PMF_FIREHELD;

(Malo) #8

Thanks alot bacon! :slight_smile:

I think I’ve got an idea on how to enable the player to switch between single and auto now too.

I did produce some more weird stuff by randomly poking around in the code.
For example I increased the nextshot delay on all semi weapons to 10000, and then changed the "pm->ps->weaponTime <= " to 10000 in “the kewl quick fire mode” on line 3422 in bg_pmove.c
I also reduced the weapon DELAY_* to zero in bg_misc.c wich to my surprise also removed that damn double-shot bug.
At first I thought that I had finally got the single-shot solution, but then realized you couldn’t reload or switch weapons until the nextshot delay time had passed.

I’ve read some C tutorials and other documentation and now I do understand at least some of the basics of C, like for/while/do-while loops, if/else, break/continue, switch, arrays and pointers etc.

Hopefully I’ll have a clue when faced with the next major (to me) challenge comes along.

Thanks again!