Dual wielding pistol

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
r3v3n93
Posts: 35
Joined: Tue Jun 09, 2020 7:16 am
Graphics Processor: nVidia (Modern GZDoom)
Location: North Korea

Dual wielding pistol

Post by r3v3n93 »

Have you ever played call of duty? Then you probably experienced Dual-wielded pistol from it. Its system is special because you can shoot both pistols rapidly by clicking both mouse buttons rapidly. I'm currently making a dual-wielding pistol with an overlay to implement the cod system. But there's a problem. It won't fire rapidly. Although [wiki]A_WeaponReady[/wiki] exists on both fire states, it won't cancel the current shooting sequence, but the sequence keep goes on until the animation done. An interesting thing is that A_WeaponReady doesn't cancel fire state and goes to altfire state, but it works when it goes to fire state from canceled fire state(or altfire from altfire).
Sorry for the bad English ability.

Code: Select all

CTOR KellyPistol : DoomWeapon replaces pistol
{
  Weapon.SelectionOrder 1900
  Weapon.AmmoUse 1
  Weapon.AmmoGive 20
  Weapon.AmmoType "Clip"
  Weapon.SlotNumber 2
  Obituary "You've been killed with Kelly's Pistols"
  +WEAPON.WIMPY_WEAPON
  Inventory.Pickupmessage "You picked up Kelly's Pistols"
  Tag "Kellys_Pistols"
  +NOAUTOFIRE
  States
  {
  Ready:
    PPPR A 0 A_Overlay(2, "RightReady")
    PPPL A 1 A_WeaponReady
    Loop
  RightReady:
    PPPR A 1
	Loop
  RightSelect:
    PPPR A 1 A_Raise
    Stop
  Deselect:
    PPPL A 1 A_Lower
    Loop
  Select:
    PPPR A 0 A_Overlay(2, "RightSelect")
    PPPL A 1 A_Raise
    Loop
  Fire:
    PPPL A 2
	PPPL B 1 
	{
	     A_FireBullets (1, 0, 5, 50, "BulletPuff");
         A_PlaySound("weapons/pap", CHAN_WEAPON);
         A_GunFlash;
    }
	PPPL CD 1 	
	PPPL DB 2 A_WeaponReady
	PPPL A 2 
    Goto Ready
  Altfire:
   PPPL A 11 A_Overlay(2, "RightFire")
   Goto Ready
  RightFire:
    PPPR A 2
	PPPR B 1 
	{
	     A_FireBullets (1, 0, 5, 50, "BulletPuff");
         A_PlaySound("weapons/pap", CHAN_WEAPON);
         A_GunFlash("Flash2");
    }
	PPPR CD 1 
	PPPR DB 2 A_WeaponReady
	PPPR A 2 
	Goto RightReady
  Flash:
    PPFL A 1 Bright A_Light1
    Goto LightDone
    PPFL A 1 Bright A_Light1
    Goto LightDone
  Flash2:
    PPFR A 1 Bright A_Light1
    Goto LightDone
    PPFR A 1 Bright A_Light1
    Goto LightDone
  }
}

The code isn't actually finished yet.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Dual wielding pistol

Post by Jarewill »

A weapon can only be in one state on one overlay, meaning that both Fire and Altfire cannot both operate at the same time.
Making an akimbo weapon is more complex and requires 2 overlays running at the same time and getting the player input.
This is an example I did a while ago:
Spoiler:
The weapon firing happens in the overlay states instead of the Ready state, which is only used for switching weapons and such. WRF_NOFIRE will prevent Fire and Altfire from triggering normally.
If LeftGun and RightGun detect the fire or altfire buttons being pressed (BT_ATTACK/BT_ALTATTACK) they will jump to the fire states. A_ReFire will break things in this example.
r3v3n93
Posts: 35
Joined: Tue Jun 09, 2020 7:16 am
Graphics Processor: nVidia (Modern GZDoom)
Location: North Korea

Re: Dual wielding pistol

Post by r3v3n93 »

Jarewill wrote:A weapon can only be in one state on one overlay, meaning that both Fire and Altfire cannot both operate at the same time.
Making an akimbo weapon is more complex and requires 2 overlays running at the same time and getting the player input.
This is an example I did a while ago:
Spoiler:
The weapon firing happens in the overlay states instead of the Ready state, which is only used for switching weapons and such. WRF_NOFIRE will prevent Fire and Altfire from triggering normally.
If LeftGun and RightGun detect the fire or altfire buttons being pressed (BT_ATTACK/BT_ALTATTACK) they will jump to the fire states. A_ReFire will break things in this example.
Appreciate it man. That's what I was lookin' for. But I think there's a problem that when I die, overlays don't disappear and still function.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Dual wielding pistol

Post by Jarewill »

You are right that's something I missed.
Try to add A_JumpIfHealthLower to make it jump to a dummy state:
Spoiler:
This will however make it instantly disappear and I don't know what can be done to prevent that.
r3v3n93
Posts: 35
Joined: Tue Jun 09, 2020 7:16 am
Graphics Processor: nVidia (Modern GZDoom)
Location: North Korea

Re: Dual wielding pistol

Post by r3v3n93 »

That'd be kinda effective, but what I've used was dumb but effective. Which is making both idle akimbo pistols sprites into a single sprite, and replaced it on "Deselect" state and used [wiki]A_ClearOverlays[/wiki].
Anyway, Thanks a lot!
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Dual wielding pistol

Post by ramon.dexter »

Jarewill wrote: This will however make it instantly disappear and I don't know what can be done to prevent that.
...which could be easily fixed by putting some actual animation sequence into the "nope" state.
r3v3n93
Posts: 35
Joined: Tue Jun 09, 2020 7:16 am
Graphics Processor: nVidia (Modern GZDoom)
Location: North Korea

Re: Dual wielding pistol

Post by r3v3n93 »

ramon.dexter wrote:
Jarewill wrote: This will however make it instantly disappear and I don't know what can be done to prevent that.
...which could be easily fixed by putting some actual animation sequence into the "nope" state.
I've already tried it but the sprite won't show up. Maybe it's just my mistake
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Dual wielding pistol

Post by Jarewill »

ramon.dexter wrote:...which could be easily fixed by putting some actual animation sequence into the "nope" state.
True, but the animation can desync if the weapons enter the state at different times.
I don't know of a method to make it completely foolproof.
r3v3n93 wrote:That'd be kinda effective, but what I've used was dumb but effective. Which is making both idle akimbo pistols sprites into a single sprite, and replaced it on "Deselect" state and used [wiki]A_ClearOverlays[/wiki].
Anyway, Thanks a lot!
This method actually works the best.
Post Reply

Return to “Scripting”