[Code] Working with Weapons

Working Wolf3d Code Changes & Tutorials

Moderators: Andy_Nonymous, Adam Biser, BrotherTank

User avatar
the_fish
Bring 'em On
Bring 'em On
Posts: 133
Joined: Sat Nov 18, 2006 5:28 pm
Location: England

Post by the_fish »

Um...explain two weapons with one button? Is that like multiple weapons that can be cycled through with repeated button presses, or a weapon that gets changed/upgraded later in the game, or what?
Mostly away: revising for finals (argh!)
User avatar
insurrectionman
DieHard Mutant
DieHard Mutant
Posts: 770
Joined: Sat May 07, 2005 6:09 pm

Post by insurrectionman »

Like doom's Shotgun and Super shotgun. Press 3 to get shotgun, press it again to receive the supershotgun. I have it sort of working, but it doesn't switch back and forth accurately.
Youtube Channel: TreeSapThief
Twitter: @treesapthief
User avatar
BrotherTank
Forum Administrator
<b>Forum Administrator</b>
Posts: 2203
Joined: Sat Mar 01, 2003 4:34 pm
Location: Ontario

Post by BrotherTank »

Give me an hour or so and I'll give you the fix for it. It's not difficult really (some small playing is needed for the weapon check). I'll post the code once I have tested it to make sure it's working 100%.

Greg
BrotherTank
User avatar
BrotherTank
Forum Administrator
<b>Forum Administrator</b>
Posts: 2203
Joined: Sat Mar 01, 2003 4:34 pm
Location: Ontario

[Code] Working with Weapons

Post by BrotherTank »

First in WL_DEF.H file, I would suggest that everyone playing with the weapons and code change the weapon define to look like this before adding any weapons. This way, NUMWEAPONS is always correct (it's actually 1 higher than we actually have in the original source):
typedef enum	{
	wp_knife,				// 0
	wp_pistol,				// 1
	wp_machinegun,			// 2
	wp_chaingun,			// 3
// Insert New Weapons Before the NUMWEAPONS line below	
	NUMWEAPONS
} weapontype;
________________________________________________

Ok InsurrectionMan,

Here it is... You'll actually kick yourself for not getting this... It's so simple really....

First some information that you will need to know for the other sections of the tutorial that I posted earlier in the thread. This will help you modify the other sections and understand thinsg a little better:
/*
	This is a specific change for some type of super addition to some weapon
	In this example we use a super shotgun - aka single barrel shotgun and double barrel
	Switchable between 1 single key

	Assuming Weapons are indexed as follows:  
		
	Knife, Pistol, Shotgun, SuperShotgun, Machinegun, Chaingun
		
	the values you need to know are: 
								
	Weapon Name	Keyboard Select	 Weapon #   Bestweapon #
	---------------------------------------------------------
	Knife		1		 0 		1
	Pistol		2		 1		2
	Shotgun		3		 2		4
	Super Shotgun	3		 3		8
	Machinegun	4		 4		16
	Chaingun	5		 5		32

*/

Now for your's specifically the define in wl_def.h would change to:
typedef enum	{
	wp_knife,			// 0
	wp_pistol,			// 1
	wp_shotgun,		// 2
	wp_supershotgun,		// 3
	wp_machinegun,		// 4
	wp_chaingun,		// 5
// Insert New Weapons Before the NUMWEAPONS line below	
	NUMWEAPONS
} weapontype;
So now you have the defines for your different shotguns. I assume that you know how to add the bo_?? values for picking it up and such - as well as adding a new weapon.

Now for the big change and you'll kick yourself for not seeing this... :
#ifdef BESTWEAPON 
// Checks to make sure you have ammo for weapon 
// returns "true" if yes and "false" if no 
int ChkAtkAmmo (int weapon) 
{ 
   switch (weapon) 
   {    
      case wp_knife: return 1; // Knife always has ammo
      case wp_pistol: 
#ifdef SEPERATEAMMO
				if (gamestate.ammo) return 1;
#endif
			case wp_shotgun:
			case wp_supershotgun:
#ifdef SEPERATEAMMO
				if (gamestate.ammo1) return 1;
#endif
      case wp_machinegun: 
#ifdef SEPERATEAMMO
				if (gamestate.ammo2) return 1;
#endif
      case wp_chaingun: 
#ifdef SEPERATEAMMO
	#ifdef SEPERATEAMMOCHAINGUN  // if not defined Chaingun and Machinegun use same ammo
				if (gamestate.ammo3) return 1;	
	#else
				if (gamestate.ammo2) return 1;
#else
				if (gamestate.ammo) return 1; 
#endif
			default:           	
         break; 
   } 
   return 0; 
} 
#endif 

void CheckWeaponChange (void) 
{ 
	int	i,kbuttons[11]={sc_1,sc_2,sc_3,sc_3,sc_4,sc_5,sc_6,sc_7,sc_8,sc_9,sc_0};
  for (i=0;i<NUMWEAPONS;i++)
  {
  	if ((Keyboard[kbuttonsi]]) && (i != gamestate.weapon))
    {
#ifdef BESTWEAPON
			if ((gamestate.bestweapon & (1<<i)) && ChkAtkAmmo(i))
#else	
			if (buttonstate[bt_readyknife+i-wp_knife])
#endif
			{
	#ifdef WEAPONCHANGESND
				if(gamestate.chosenweapon != i)
				{
		#ifdef NOKNIFESNDATALL
					if (i) 
				 	{
		#endif
		#ifdef SEPERATEWEAPONCHANGESNDS
						switch (i)
							case wp_knife:
			#ifdef NOKNIFESND
								break;
			#else
								SD_PlaySound(CHANGEKNIFEWEAPONSND); break;
			#endif					
							case wp_pistol:
								SD_PlaySound(CHANGEPISTOLWEAPONSND); break;
							case wp_machinegun:
								SD_PlaySound(CHANGEMACHINEWEAPONSND); break;
							case wp_chaingun:
								SD_PlaySound(CHANGECHAINGUNWEAPONSND); break;
							default:
		#endif
								SD_PlaySound(CHANGEWEAPONSND);
		#ifdef NOKNIFESNDATALL
					}
		#endif		
	#endif
				IN_ClearKeysDown();
				gamestate.weapon = gamestate.chosenweapon = i;
				DrawWeapon ();
				DrawAmmo ();
				return;
			}
		}
	}
}


That's right... all we did was include a second "sc_3" in the keyboard defines. It's that simple. If you press "3" and are using any other weapon, then it chooses the first shotgun (which is normal). If you press "3" again, it will switch to the second shotgun. To understand the routine a little more.....

The above routine scans through the kbuttons[array] until it finds the key that is pressed and checks to see if that is the weapon in use. If it's not, then it says "use this" if we actually have the weapon and ammo for it. It will continue to check the kbutton array until it has reached the end or Max weapons (NUMWEAPONS). It doesn't care what keys are in the array... or what order.

That's actually the beauty of this routine and why I wrote it the way that I did. It doesn't require any special if statements or the like. What it does look for is: What key is pressed? Do we have that weapon? Do we have Ammo? Use if Yes to those questions... Not or No to the questions...... Keep searching to see if it matches something else.

Hope that helps...

Greg
BrotherTank

PS: As you can see I included some of the other stuff I was toying with, but I did remove the other weapons like Flamethrower and Rocket Launcher as they require more changes to the code and additional routines.
User avatar
insurrectionman
DieHard Mutant
DieHard Mutant
Posts: 770
Joined: Sat May 07, 2005 6:09 pm

Post by insurrectionman »

Okay, I did that, but I never added the IN_ClearKeysDown(); and if I pressed 3 and had at least one weapon, it also had the other weapon. I don't know why, and when i would select between weapons it could randomly come up the shotgun or supershotgun. I also added gun change bob to this and it would go down, but not come up because it was selecting between each weapon at every tic. Long story short, does the IN_ClearKeysDown prevent this?
Youtube Channel: TreeSapThief
Twitter: @treesapthief
User avatar
BrotherTank
Forum Administrator
<b>Forum Administrator</b>
Posts: 2203
Joined: Sat Mar 01, 2003 4:34 pm
Location: Ontario

Post by BrotherTank »

insurrectionman wrote:Okay, I did that, but I never added the IN_ClearKeysDown(); and if I pressed 3 and had at least one weapon, it also had the other weapon.
If you had both weapons then you didn't create the seperate bo_?? assignments for each of the weapons.... The In_ClearKeysDown() I'll explain below....
insurrectionman wrote:I don't know why, and when i would select between weapons it could randomly come up the shotgun or supershotgun.
There must have been something else wrong in your code then as all this code does is bind each key to a weapon. I'll go through the logic of the code again and maybe that will help you understand.
insurrectionman wrote: I also added gun change bob to this and it would go down, but not come up because it was selecting between each weapon at every tic. Long story short, does the IN_ClearKeysDown prevent this?
Adding the change gun bob shouldn't affect anything - providing it's added correctly. The IN_ClearKeysDown is just a routine that clears any other key presses waiting in the Input Buffer once it has made a selection.

Anyhow... For your situation, you have to look at the weapons you want as two seperate weapons. You have to add the two weapons to the weapon define in wl_def.h add the new sprites for both weapons in the sprite list and so on. Basically, you do everything for adding a new weapon twice.

For Examples sake, lets say that you are adding 2 weapons to the original game.

wp_shotgun and wp_supershotgun

So your weapon define in wl_def.h would look like:
typedef enum   { 
   wp_knife,         // 0 
   wp_pistol,         // 1 
   wp_shotgun,      // 2 
   wp_supershotgun,      // 3 
   wp_machinegun,      // 4 
   wp_chaingun,      // 5 
// Insert New Weapons Before the NUMWEAPONS line below    
   NUMWEAPONS 
} weapontype;
The CheckWeaponChange routine I coded works like this:
void CheckWeaponChange (void) 
{ 
   int   i,kbuttons[11]={sc_1,sc_2,sc_3,sc_3,sc_4,sc_5,sc_6,sc_7,sc_8,sc_9,sc_0}; 
kbuttons[#]={sc_?} is an array that holds the keyboard buttons that the program will react to.
There needs to be '1' element of the array for each weapon in your game.
I included in the original code 10 different sc_? codes to define up to 10 different keys to 10 different weapons, but you can modify that section of the code to look like this:
int   i,kbuttons[NUMWEAPONS]={sc_1,sc_2,sc_3,sc_4,sc_5,sc_6}; 
So the array really only needs 1 key assignment for each weapon. Now the above would assign 1 different key for each of the weapons defined in the game. You want 1 key to do both weapons (the "3" on the keyboard), so we change that line to read:
int   i,kbuttons[NUMWEAPONS]={sc_1,sc_2,sc_3,sc_3,sc_4,sc_5}; 
Now the rest of the code I will just comment within the code bubble.
// Loop from weapon 0 - Knife to NUMWEAPONS (5) in our example case.
  for (i=0;i<NUMWEAPONS;i++)  
  { 
// If the Keyboard Scan Code Array Item "i" is pressed and we are not currently 
// using that weapon then go to next condition check - if 'No' then loop to next array
// check and next weapon.
     if ((Keyboard[kbuttons[i]) && (i != gamestate.weapon)) 
    { 
// The next 'if' lines check to make sure that you have the weapon you wanted
// to select and you actually have ammo.  If yes, then start the weapon assignment
// or more simply: 'Choose that weapon' as we have it and the ammo.
#ifdef BESTWEAPON 
         if ((gamestate.bestweapon & (1<<i)) && ChkAtkAmmo(i)) 
#else    
         if (buttonstate[bt_readyknife+i-wp_knife] && i <= gamestate.bestweapon) 
#endif 
         { 
   #ifdef WEAPONCHANGESND  // This stuff is here but not required unless you are adding sounds to the engine for use when the player is changing weapons.
            if(gamestate.chosenweapon != i)  // if not equal weapon chosen to weapon previously chosen - yes we want to make a sound
            { 
      #ifdef NOKNIFESNDATALL 
               if (i) //  knife is weapon '0' so if weapon chosen is knife 'i' would be zero or false - make no sound at all
                { 
      #endif 
      #ifdef SEPERATEWEAPONCHANGESNDS 
                  switch (i) // choose the proper selected weapon and make a sound when changing weapons 
                     case wp_knife: 
         #ifdef NOKNIFESND 
                        break; 
         #else 
                        SD_PlaySound(CHANGEKNIFEWEAPONSND); break; 
         #endif                
                     case wp_pistol: 
                        SD_PlaySound(CHANGEPISTOLWEAPONSND); break; 
                     case wp_machinegun: 
                        SD_PlaySound(CHANGEMACHINEWEAPONSND); break; 
                     case wp_chaingun: 
                        SD_PlaySound(CHANGECHAINGUNWEAPONSND); break; 
                     default: 
      #endif 
                        SD_PlaySound(CHANGEWEAPONSND); 
      #ifdef NOKNIFESNDATALL 
               } 
      #endif       
   #endif  // end of the weapon change sound stuff.
            IN_ClearKeysDown(); // We passed the above conditions so we don't need any more key presses - so clear the input buffer.
            gamestate.weapon = gamestate.chosenweapon = i; // Assign the weapon we have and the chosen weapon (for weapon fallback when you run out of ammo)
            DrawWeapon (); // Update the weapon chosen onto the statusbar
            DrawAmmo (); // Update the ammo we have on the statusbar - now if you are not using seperate ammo, you don't need this line really.  If you are using seperate ammo this line is needed as we need to update the screen to match ammo to chosen weapon.
            return; //  Exit the loop and continue in the game - we have found - chosen - and assigned the weapon the player has requested.
         } // end of we have weapon and ammo so give player that weapon check
      } // end of we checked key press and is it currently chosen check
   } // End of for-next loop - keep checking everything inside the loop until we have checked everything that has been defined as a weapon change key.  If we get here after checking everything (looping until we have reached NUMWEAPONS) then nothing matched so we have done nothing and given the player nothing.  If we did find something within the loop that matches the right conditions the 'return' line above exits this loop and returns control to the player.
} // End of function


Now... If you remove the Gun change bob, and use only the original code, this should work 100% on it's own. If it's not then you have done something wrong, or missed something in adding the weapons.

The routine itself is pretty much bulletproof.

Greg
BrotherTank
User avatar
ronwolf1705
Moderator
<b>Moderator</b>
Posts: 3830
Joined: Mon Jul 31, 2006 10:04 am

Post by ronwolf1705 »

I've added both the BESTWEAPON and the Seperate Ammo tutorial, but now everytime I select the knife, when I have both ammo types, I can't select the gun and machinegun, only the chaingun. Can anyone help me out?

EDIT:

Nevermind, I have fixed it.
User avatar
insurrectionman
DieHard Mutant
DieHard Mutant
Posts: 770
Joined: Sat May 07, 2005 6:09 pm

Post by insurrectionman »

I have implemented this into the Wolf4SDL source code, (not that hard rite?) but there is one line that this newer engine does not support and that is:

gamestate.bestweapon |= (1<<weapon);

because bestweapon is a weapontype, instead of short, it doesn't allow the |=, so is there an alternate way to do this, keeping the same kind of byte code, 1,2,4,8,16,etc.?
Youtube Channel: TreeSapThief
Twitter: @treesapthief
User avatar
Tricob
Moderator
<b>Moderator</b>
Posts: 9040
Joined: Tue Mar 15, 2005 2:43 am
Location: Neo-traditions, Inc.

Post by Tricob »

I haven't seen "|=" before. I'm familiar with "!=", but not "|=". :?
User avatar
AlumiuN
DieHard Wolfer
DieHard Wolfer
Posts: 2744
Joined: Fri Nov 30, 2007 3:34 am
Location: Christchurch, New Zealand

[Code] Working with Weapons

Post by AlumiuN »

Ahhh, the bitwise operators. Well, you could write a function like this somewhere:
long GetBit(long bitnum)
{
    return pow(2, bitnum)
}
and then throw this line at the top of the file that this is in:
#include <math.h>
Finally, change:
gamestate.bestweapon |= (1<<weapon);
to
gamestate.bestweapon += GetBit(1<<weapon);
I think that's right, but the bitnum may need a -1 on it. I'm not sure. :-) Of course, I could be entirely wrong. :-(
User avatar
the_fish
Bring 'em On
Bring 'em On
Posts: 133
Joined: Sat Nov 18, 2006 5:28 pm
Location: England

Post by the_fish »

Agh! Though AlumiuN's code may work, I just recoiled in horror at using sophisticated functions to perform bitwise operations. It's the proverbial sledgehammer cracking the nut. Waaay inefficient (won't matter, because you're calling this way less than once per frame, but it's still bad practise)

Not sure if the compiler would allow this, but try casting the 'weapontype's to 'short'. The following fudge might do it:
short sTemp;

...

sTemp = (short) gamestate.bestweapon;
sTemp |= (1<<((short) weapon)); 
gamestate.bestweapon = (weapontype) sTemp;
But without actually trying this in your compiler I won't know if it works...
Mostly away: revising for finals (argh!)
User avatar
insurrectionman
DieHard Mutant
DieHard Mutant
Posts: 770
Joined: Sat May 07, 2005 6:09 pm

Post by insurrectionman »

hey the_fish, your method worked, it looks like something I needed, but couldn't put the pieces together correctly, alumiun's didn't work at all, so thanks for the help.
Youtube Channel: TreeSapThief
Twitter: @treesapthief
User avatar
AlumiuN
DieHard Wolfer
DieHard Wolfer
Posts: 2744
Joined: Fri Nov 30, 2007 3:34 am
Location: Christchurch, New Zealand

Post by AlumiuN »

I forgot about casting. That's much simpler. I didn't think my code would work. :-)
TheManOfTheSilverPistol
Can I Play Daddy
Can I Play Daddy
Posts: 43
Joined: Sat Mar 30, 2019 6:38 pm

Post by TheManOfTheSilverPistol »

BrotherTank, I have one question, is optional is put the Weapon Base Code? and is this tutorial compatible with the one made by Jamez?
What I want to do is to follow the jamez tutorial to make a new gun and later follow your tutorial to separate the ammo and I think you should explain where to put the sprites.
Thanks you for Reading this, I wait for your respond.
I think you should rewrite the tutorial by steps because is very confusing to understand some things.
User avatar
Tricob
Moderator
<b>Moderator</b>
Posts: 9040
Joined: Tue Mar 15, 2005 2:43 am
Location: Neo-traditions, Inc.

Post by Tricob »

I'm not BrotherTank, but the W.W.W. code will probably work with Jamez's code *if* you alter the code very carefully. I wouldn't recommend this if you're a beginner.
User avatar
Dean
Moderator
<b>Moderator</b>
Posts: 2164
Joined: Wed Jan 11, 2006 1:41 am
Location: Australia

Post by Dean »

TheManOfTheSilverPistol wrote:BrotherTank, I have one question, is optional is put the Weapon Base Code? and is this tutorial compatible with the one made by Jamez?
What I want to do is to follow the jamez tutorial to make a new gun and later follow your tutorial to separate the ammo and I think you should explain where to put the sprites.
Thanks you for Reading this, I wait for your respond.
I think you should rewrite the tutorial by steps because is very confusing to understand some things.
You'll be waiting a while, he hasn't been here in over 18 months...
User avatar
crustycribb
Registered User
Registered User
Posts: 10
Joined: Fri Jun 09, 2023 9:59 pm
Location: Carentan

[Code] Working with Weapons

Post by crustycribb »

Sorry for reviving an old thread, but i have some minor issues with this.
I've added the new weapons as per this tutorial. It works, but the kill percentage on level transmission seems to be going more than 100% if i use the new weapons.
Anyone got a clue as to how this could happen?
Hello, mirror. So glad to see you, my friend...
User avatar
ReddimusVonAggrevatii
DieHard Guard
DieHard Guard
Posts: 226
Joined: Thu Oct 12, 2017 6:10 am
Location: A Jjaro space station.

Post by ReddimusVonAggrevatii »

Sounds like you might've used gamestate.killcount++ instead of gamestate.attackcount++ someplace in the code.
Other than that, you can post your changes.
I regret nothing.
User avatar
shodan
DieHard SS
DieHard SS
Posts: 353
Joined: Sat Dec 04, 2021 12:34 am

Post by shodan »

ReddimusVonAggrevatii wrote:Sounds like you might've used gamestate.killcount++ instead of gamestate.attackcount++ someplace in the code.
Other than that, you can post your changes.
That was my thought too - either incrementing killcount in extra places, or calling KillActor or DamageActor on already-dead actors.
Look at you, hacker...
User avatar
Tricob
Moderator
<b>Moderator</b>
Posts: 9040
Joined: Tue Mar 15, 2005 2:43 am
Location: Neo-traditions, Inc.

Post by Tricob »

It can also happen if you put the wrong statetype in the death frames as well.
User avatar
crustycribb
Registered User
Registered User
Posts: 10
Joined: Fri Jun 09, 2023 9:59 pm
Location: Carentan

[Code] Working with Weapons

Post by crustycribb »

Sorry for the late reply.
I assume it's on the T_Attack routine on WL_AGENT.C
/*
===============
=
= T_Attack
=
===============
*/

void   T_Attack (objtype *ob)
{
   struct   atkinf   *cur;
   int i;
   
   UpdateFace ();

   if (gamestate.victoryflag)      // watching the BJ Actor
   {
      VictorySpin ();
      return;
   }
   if ( buttonstate[bt_use] && !buttonheld[bt_use] ) buttonstate[bt_use] = false;
   if ( buttonstate[bt_attack] && !buttonheld[bt_attack]) buttonstate[bt_attack] = false;

   ControlMovement (ob);
   if (gamestate.victoryflag)      // watching the BJ actor
      return;

   plux = player->x >> UNSIGNEDSHIFT;         // scale to fit in unsigned
   pluy = player->y >> UNSIGNEDSHIFT;
   player->tilex = player->x >> TILESHIFT;      // scale to tile values
   player->tiley = player->y >> TILESHIFT;

//
// change frame and fire
//
   gamestate.attackcount -= tics;
   while (gamestate.attackcount <= 0)
   {
      cur = &attackinfo[gamestate.weapon][gamestate.attackframe];
      switch (cur->attack)
      {
#ifdef BESTWEAPON
// End of firing sequence - check ammo and fall back to best possible weapon with ammo
	 case -1:
	    ob->state = &s_player;

	    if (!ChkAtkAmmo (gamestate.weapon) && gamestate.chosenweapon != wp_knife)
	    {
	       gamestate.weapon = wp_knife;
	       for (i=wp_pistol; i<NUMWEAPONS; i++)
	       {
		  if (ChkAtkAmmo (i) &&  gamestate.bestweapon & (1<<i))
		  {
		     gamestate.weapon = i;
		  }
	       }
	       DrawWeapon ();
	       DrawAmmo ();
	    }
	    else
	    {
	       if (gamestate.weapon != gamestate.chosenweapon)
	       {
		  if (ChkAtkAmmo(gamestate.chosenweapon))
		     gamestate.weapon = gamestate.chosenweapon;
		  DrawWeapon ();
	       }
	    }
	    gamestate.attackframe = gamestate.weaponframe = 0;
	    return;

	 case 4: // Chaingun - Fall back 2 frames and fire again if button Pressed
	    if (!ChkAtkAmmo(gamestate.weapon)) break;
	    if (buttonstate[bt_attack]) gamestate.attackframe -= 2;

	 case 1: // Fire the Weapon

	  // can only happen with chain gun
	    if (!ChkAtkAmmo(wp_chaingun) && gamestate.weapon == wp_chaingun)
	       {   gamestate.attackframe++; break; }

	    if (ChkAtkAmmo(gamestate.weapon))
	    {
	       GunAttack (ob);
#ifdef SEPERATEAMMO
	     switch (gamestate.weapon)
	    {
	       case wp_rifle:
	       case wp_autorifle:
		gamestate.ammo2--; break;
	       case wp_rocketgun:
		gamestate.ammo3--; break;
	       case wp_flamer:
		gamestate.ammo4--; break;
	   default:
	       gamestate.ammo--; break;
	    }
#else
	       gamestate.ammo--;
#endif
#ifdef WEAPONTHRUST
	       // Move player slightly backwards based on weapon fired
	       Thrust(player->angle,-0x200 - (gamestate.chosenweapon * 50) );  // adjust the -0x200 to suit your liking
#endif
	DrawAmmo();
	break;
	}
	else
	{ return; }
	 case 2:
	    KnifeAttack (ob);
	    break;
	 case 3:
	    if (ChkAtkAmmo(gamestate.weapon) && buttonstate[bt_attack])
	       gamestate.attackframe -= 2;
	    break;

#else   // Old way of doing things - BESTWEAPON not enabled
	 case -1:
	    ob->state = &s_player;
	    if (!gamestate.ammo)
	    {
	       gamestate.weapon = wp_knife;
	       DrawWeapon ();
	    }
	    else
	    {
	       if (gamestate.weapon != gamestate.chosenweapon)
	       {
		  gamestate.weapon = gamestate.chosenweapon;
		  DrawWeapon ();
	       }
	    }
	    gamestate.attackframe = gamestate.weaponframe = 0;
	    return;

	 case 4:
	    if (!gamestate.ammo)   break;
	    if (buttonstate[bt_attack]) gamestate.attackframe -= 2;
	 case 1:
	    if (!gamestate.ammo)
	    {   // can only happen with chain gun
	       gamestate.attackframe++;
	       break;
	    }
	    GunAttack (ob);
	    gamestate.ammo--;
#ifdef WEAPONTHRUST
	       // Move player slightly backwards based on weapon fired
	       Thrust(player->angle,-0x200 - (gamestate.chosenweapon * 50) ); // adjust the -0x200 to suit your liking
#endif
	    DrawAmmo ();
	    break;
	 case 2:
	    KnifeAttack (ob);
	    break;
	 case 3:
	    if (gamestate.ammo && buttonstate[bt_attack])
	       gamestate.attackframe -= 2;
	    break;
#endif
      }

      gamestate.attackcount += cur->tics;
      gamestate.attackframe++;
      gamestate.weaponframe = attackinfo[gamestate.weapon][gamestate.attackframe].frame;
   }

}
Hello, mirror. So glad to see you, my friend...
User avatar
ReddimusVonAggrevatii
DieHard Guard
DieHard Guard
Posts: 226
Joined: Thu Oct 12, 2017 6:10 am
Location: A Jjaro space station.

Post by ReddimusVonAggrevatii »

Alright, I checked the source you already sent me, and the problem is not caused by the new weapons, you're calling DamageActor from GunAttack twice, once before it's determined if anybody was hit, which is why just shooting any weapon increases the kill count. Just delete the first call and it should fix it.
I regret nothing.
User avatar
BlakeMaster
DieHard Guard
DieHard Guard
Posts: 253
Joined: Tue Jan 25, 2022 6:18 pm

Re: [Code] Working with Weapons

Post by BlakeMaster »

I was wondering. Has anyone done a code where projectiles bounce off the wall until they hit the player or an enemy?

There are two weapons in the Quake Expansions that do this. One in Scourge of Armagon and another in Abyss of Pandemonium.
I live to game. I game to live.