[ZScript][Solved] Dual-Wielding problem

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
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

[ZScript][Solved] Dual-Wielding problem

Post by Ac!d »

When I want to shoot with to two guns at once, only one muzzle flash is visible.
Screenshot_Doom_20200202_205222.png

Code: Select all

Class DualPistols : Weapon
{
	Default {}
    action void SetWeaponState(statelabel st,int layer=PSP_WEAPON)   // Credits goes to Matt ==> Weapon input shortcuts
    {
        if(player) player.setpsprite(layer,invoker.findstate(st));
    }
    action bool PressingFire(){return player.cmd.buttons & BT_ATTACK;}
    action bool PressingAltFire(){return player.cmd.buttons & BT_ALTATTACK;}
	States
	{

	Ready:
		DP2G A 1
		{
			if(PressingFire()) SetWeaponState("FireLeftGun");
            if(PressingAltFire()) SetWeaponState("FireRightGun");		
			A_WeaponReady(WRF_NOFIRE|WRF_ALLOWRELOAD);
		}
		Loop;

	Fire:
	FireLeftGun:
		DP2G A 0 A_JumpIfInventory("Pistol2Ammo",1,1);
		Goto DryFire;
		"####" G 1 //2
		{
			A_GunFlash("Flash_L");
			A_AlertMonsters();
			A_PlaySound("Weapons/Pistol/Fire",CHAN_WEAPON);
			A_FireBullets(0,0,1,Random(7,8),"NewBulletPuff",0,2048,"BulletTracer",0,-10);
			A_SetPitch(Pitch - 0.4);
		}
		"####" H 1; //2
		"####" I 1
		{
			A_SetPitch(Pitch + 0.2);
			A_FireProjectile("PistolCasingSpawner",0,0,-9,1,FPF_NOAUTOAIM);
		}
		"####" K 1;
		"####" J 1 A_SetPitch(Pitch + 0.2);
		"####" K 1;
		Goto Ready;
	FireRightGun:
		DP2G A 0 A_JumpIfInventory("PistolAmmo",1,1);
		Goto DryFire;
		"####" B 1 //2
		{
			A_GunFlash("Flash_R");
			A_AlertMonsters();
			A_PlaySound("Weapons/Pistol/Fire",CHAN_WEAPON);
			A_FireBullets(0,0,1,Random(7,8),"NewBulletPuff",0,2048,"BulletTracer",0,10);
			A_SetPitch(Pitch - 0.4);
		}
		"####" C 1; //2
		"####" D 1
		{
			A_SetPitch(Pitch + 0.2);
			A_FireProjectile("PistolCasingSpawner",0,0,18,1,FPF_NOAUTOAIM);
		}
		"####" E 1;
		"####" E 1 A_SetPitch(Pitch + 0.2);
		"####" E 1;		
		Goto Ready;	
	DryFire:
		DP2G A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH);
		Goto Ready;
			
	Flash_L:
		DP2G G 1 Bright A_Light1;
		Goto LightDone;
	Flash_R:
		DP2G B 1 Bright A_Light1;
		Goto LightDone;
	}
}
Did someone have a solution ?
Last edited by Ac!d on Tue Feb 04, 2020 5:29 am, edited 1 time in total.
User avatar
comet1337
Posts: 876
Joined: Fri Sep 25, 2015 3:48 am
Location: elsewhere

Re: [ZScript] Dual-Wielding problem

Post by comet1337 »

a_gunflash only utilizes a single psp layer
you'll have to use a_overlay and set each flash on seperate layers
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

Re: [ZScript] Dual-Wielding problem

Post by Ac!d »

I've followed your instructions, but the problem is still the same.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: [ZScript] Dual-Wielding problem

Post by Matt »

The SetWeaponState calls also need to be in separate layers, one for each gun.

Best to have something like an enum defining PSP_LEFTGUN, PSP_RIGHTGUN, PSP_LEFTGUNFLASH and PSP_RIGHTGUNFLASH as constants (maybe 1001-1004? I don't think those #s are used by anything), then refer to those with the overlay and setweaponstate calls.
Ac!d
Posts: 348
Joined: Tue Apr 02, 2019 5:13 am

Re: [ZScript][Solved] Dual-Wielding problem

Post by Ac!d »

Matt wrote:The SetWeaponState calls also need to be in separate layers, one for each gun.

Best to have something like an enum defining PSP_LEFTGUN, PSP_RIGHTGUN, PSP_LEFTGUNFLASH and PSP_RIGHTGUNFLASH as constants (maybe 1001-1004? I don't think those #s are used by anything), then refer to those with the overlay and setweaponstate calls.

Code: Select all

Enum DualPistolsLayers
{
	PSP_LEFTGUN =	1001,
	PSP_RIGHTGUN = 1002,
};

Class EriDualPistols : Weapon
{
	Default  {}
    action void SetWeaponState(statelabel st,int layer=PSP_WEAPON)   // Credits goes to Matt ==> Weapon input shortcuts
    {
        if(player) player.setpsprite(layer,invoker.findstate(st));
    }
    action bool PressingFire(){return player.cmd.buttons & BT_ATTACK;}
    action bool PressingAltFire(){return player.cmd.buttons & BT_ALTATTACK;}
	States
	{
 	Spawn:
		DEPI A -1;
		Stop;
	Select:
		TNT1 A 15;
		DP2S DCBA 1 A_WeaponOffset(0,32,WOF_INTERPOLATE);
	Ready2:
		TNT1 A 0 A_Overlay(1001,"Ready_L");
		TNT1 A 0 A_Overlay(1002,"Ready_R");
	Ready:
		TNT1 A 1 A_WeaponReady(WRF_NOFIRE|WRF_ALLOWRELOAD);
		Loop;
	Deselect:
		TNT1 A 0 A_Overlay(1001,"Fire");
		TNT1 A 0 A_Overlay(1002,"Fire");
		DP2S ABCD 1;
		TNT1 A 15;
	FinishDeselect:
		TNT1 A 0 A_Lower;
		Loop; 

	Ready_L:
		DPFL A 1
		{
			if(PressingFire()) SetWeaponState("FireLeftGun",PSP_LEFTGUN);
		}
		Loop;		
	Ready_R:
		DPFR A 1
		{
            if(PressingAltFire()) SetWeaponState("FireRightGun",PSP_RIGHTGUN);
		}
		Loop;
		
	Fire:
		TNT1 A 0;
		Stop;
		
	FireLeftGun:
		DPFL A 0 A_JumpIfInventory("Pistol2Ammo",1,1);
		Goto DryFire;
		"####" B 1 Bright
		{
			A_Light1();
			A_AlertMonsters();
			A_PlaySound("Weapons/Pistol/Fire",CHAN_WEAPON);
			A_FireBullets(0,0,1,Random(7,8),"NewBulletPuff",0,2048,"BulletTracer",0,-10);
			A_SetPitch(Pitch - 0.4);
		}		
		"####" C 1;
		"####" D 1
		{
			A_SetPitch(Pitch + 0.2);
			A_FireProjectile("PistolCasingSpawner",0,0,-9,1,FPF_NOAUTOAIM);
		}
		"####" E 1;
		"####" F 1 A_SetPitch(Pitch + 0.2);
		"####" E 1;
		"####" A 3;
		Goto Ready_L;
	FireRightGun:
		DPFR A 0 A_JumpIfInventory("PistolAmmo",1,1);
		Goto DryFire;
		"####" B 1 Bright
		{
			A_Light1();
			A_AlertMonsters();
			A_PlaySound("Weapons/Pistol/Fire",CHAN_WEAPON);
			A_FireBullets(0,0,1,Random(7,8),"NewBulletPuff",0,2048,"BulletTracer",0,10);
			A_SetPitch(Pitch - 0.4);
		}
		"####" C 1;
		"####" D 1
		{
			A_SetPitch(Pitch + 0.2);
			A_FireProjectile("PistolCasingSpawner",0,0,18,1,FPF_NOAUTOAIM);
		}
		"####" E 1;
		"####" F 1 A_SetPitch(Pitch + 0.2);
		"####" E 1;
		"####" A 3;		
		Goto Ready_R;	
	DryFire:
		TNT1 A 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH);
		Goto Ready2;
	}
}
It's works fine now ! Thanks you Matt !
Post Reply

Return to “Scripting”