Page 1 of 1

[ZScript][Solved] Dual-Wielding problem

Posted: Sun Feb 02, 2020 2:19 pm
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 ?

Re: [ZScript] Dual-Wielding problem

Posted: Sun Feb 02, 2020 2:36 pm
by comet1337
a_gunflash only utilizes a single psp layer
you'll have to use a_overlay and set each flash on seperate layers

Re: [ZScript] Dual-Wielding problem

Posted: Sun Feb 02, 2020 3:02 pm
by Ac!d
I've followed your instructions, but the problem is still the same.

Re: [ZScript] Dual-Wielding problem

Posted: Mon Feb 03, 2020 1:43 pm
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.

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

Posted: Tue Feb 04, 2020 5:14 am
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 !