[HELP] Toggle different altfire modes

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
DoomedRabbit
Posts: 31
Joined: Sun Jul 14, 2019 1:13 pm
Graphics Processor: ATI/AMD (Modern GZDoom)

[HELP] Toggle different altfire modes

Post by DoomedRabbit »

Hello,

I need some help with an idea for a game mechanic I got. Basically, what I want to do is for all weapons to have an altfire that when pressed, the player shoots magic with his left hand. Now, what I also want to do is for the player to be able to switch between different types of altfire (spells). My idea is a boundable hotkey that when pressed, switches between spells (possibly excecuted with an ACS script?).
And then the altfire state makes a jump to a spell fire state depending on what dummy spell item the player has selected. Its a lot like how you toggle switching between equipment in DOOM 2016 with a certain key.

Also, I do not want the player to have all the spells when he starts, he would collect more as he progresses through the game in whatever order (I am thinking of 6 in total).

Here is the DECORATE code I came up with:

Code: Select all

AltFire:
    TNT1 A 0 A_JumpIfInventory("ElectroSelected",1,"AltFireElectro")
    TNT1 A 0 A_JumpIfInventory("PyroSelected",1,"AltFirePyro")
    Goto Ready
AltFireElectro:
    TNT1 A 0 A_Print("this state will fire electrokinesis",1)
    Goto Ready
AltFirePyro:
    TNT1 A 0 A_Print("this state will fire pyrokinesis",1)
    Goto Ready
I would really appreciate some help with this :D

Thanks,
-DoomedRabbit
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: [HELP] Toggle different altfire modes

Post by Jarewill »

I would recommend using the built-in keybinds. (Weapon State 1-4, also called User1-4)
For example, make User1 detect if the player has an inventory item that shows a unlocked spell, then give the player an item that makes that spell selected.

I once posted slightly edited code from my mod here. Maybe it will help.
DoomedRabbit
Posts: 31
Joined: Sun Jul 14, 2019 1:13 pm
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: [HELP] Toggle different altfire modes

Post by DoomedRabbit »

Hah, I haven't thought of that yet. Thanks for the suggestion, I will try it out! :D
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [HELP] Toggle different altfire modes

Post by ramon.dexter »

Take a look here, I made something pretty similat to what you want. I have this weapon that uses altFire as simple switch, that switches fire modes. Firing itself is done only by primaryFire.

Code: Select all

class StaffBlasterUpgr : augmentedWeapon
{
	int Fire1;
	int Fire2;
	int upStaffSwitch;
	
	Default
	{
		//$Category "SoA/weapons"
		//$color 6
		//$Title "rangerska hul lvl.2 (ground)"		
		
		+WEAPON.AMMO_OPTIONAL
        //+WEAPON.ALT_USES_BOTH
		+WEAPON.NOAUTOAIM
		+WEAPON.NOALERT
		
		Tag "$T_STFBLUP";
		Scale 0.4;
		height 16;
		radius 12;
		Inventory.icon "H_USTF";
		Inventory.pickupmessage "$F_STFBLUP";
		Obituary "%o was splattered by %k Blaster Staff";
		AttackSound "weapons/staffShoot";
		Weapon.SlotNumber 3;
		Weapon.SlotPriority 0.1;
		Weapon.kickback 40;
		Weapon.AmmoType1 "StaffUpgrMag";
		Weapon.AmmoUse1 1;
		Weapon.AmmoGive1 0;
		Weapon.AmmoType2 "EnergyPod";
		Weapon.AmmoUse2 0;
		Weapon.AmmoGive2 32;
		Decal "redShotScorch";
	}
    
	States
	{
		Spawn:
			USTD V -1;
			Stop;
					
		Ready:
			USTF J 2 
			{
				A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWUSER1);
				A_WeaponOffset(CallACS("Script_GetGunOffsetX"));
			}	
			Loop;
					
		Deselect:
			USTF J 1 A_Lower();
			Loop;
					
		Select:
			USTF J 1 A_Raise();
			Loop;

		AltFire:
			TNT1 A 0
			{
				if(invoker.upStaffSwitch == 1)
				{
					return resolveState("setFire2");
				}
				if(invoker.upStaffSwitch == 2)
				{
					return resolveState("setFire1");
				}
				return resolveState(null);
			}
			//intentional fallthrough
		setFire2:
			USTF JIH 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOFIRE | WRF_NOSWITCH|WRF_ALLOWUSER1);
			USSW A 4;
			USSW B 3;
			USSW C 3;
			USSW D 4;
			USSW E 5;
			TNT1 A 0
			{
				A_Playsound("weapons/staffClose");
				invoker.upStaffSwitch = 2;
				self.giveinventory("staffFire2token", 1);
				self.takeinventory("staffFire1token", 1);
			}
			USSW E 5;
			USSW D 4;
			USSW C 3;
 			USSW B 4;
			USSW A 3;
			USTF HIJ 3;
			goto Ready;
		setFire1:
			USTF JIH 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOFIRE | WRF_NOSWITCH|WRF_ALLOWUSER1);
			USSW A 4;
			USSW B 3;
			USSW C 3;
			USSW D 4;
			USSW E 5;
			TNT1 A 0
			{
				A_Playsound("weapons/staffClose");
				invoker.upStaffSwitch = 1;
				self.giveinventory("staffFire1token", 1);
				self.takeinventory("staffFire2token", 1);
			}
			USSW E 5;
			USSW D 4;
			USSW C 3;
 			USSW B 4;
			USSW A 3;
			USTF HIJ 3;
			goto Ready;

		Fire:
			TNT1 A 0
			{
				if(invoker.upStaffSwitch == 1)
				{
					return resolveState("Fire1");
				}
				if(invoker.upStaffSwitch == 2)
				{
					return resolveState("Fire2");
				}
				return resolveState(null);				
			}
			//intentional fallthrough
		Fire1:
			TNT1 A 0 A_JumpIf(invoker.Fire1 == 1, "RealFire1");
			USTF JIH 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOFIRE | WRF_NOSWITCH|WRF_ALLOWUSER1);
			USTF A 1 //takze hul zustane ve stredu obrazu
			{
				invoker.Fire1 = 1;
			}				
		RealFire1:			
			USTF A 0 A_JumpIfNoAmmo("Reload");
			USTF A 1;
			USTF B 3 bright 
			{
				A_FireStaffBlaster("redBlasterTracer", "redFlash");
				A_AlertMonsters();
			}
			USTF C 4;	
			USTF D 3;		
			USTF E 1;
			USTF F 3;
			USTF G 5 A_Refire("RealFire1"); //umoznuje rychlou strelbu
			USTF A 140 A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWUSER1);
			USTF HIJ 4 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOFIRE|WRF_NOSWITCH|WRF_ALLOWUSER1);
			TNT1 A 0
			{
				invoker.Fire1 = 0;
			}
			Goto Ready;
		
		Fire2:
			TNT1 A 0 A_JumpIf(invoker.Fire2 == 1, "RealFire2");
			USTF JIH 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOFIRE|WRF_NOSWITCH|WRF_ALLOWUSER1);
			USTF A 1 //takze hul zustane ve stredu obrazu
			{
				invoker.Fire2 = 1;
			}
		RealFire2:			
			USTF A 0 A_JumpIfNoAmmo("StopSoundnReload");
            USTG A 1;
            USTG BC 1 bright A_PlaySound("weapons/lightninggun/fire",7);
            USTG D 1;
        Hold:			
			USTF A 0 A_JumpIfNoAmmo("StopSoundnReload");
            USTG E 2 bright
            {
                A_PlaySound("weapons/lightninggun/loop", CHAN_6, 1.0, false);                               
                A_GunFlash();
				A_FireProjectile("greenArcLightning", 0.1*random(20,-20), 1, 0, 8, 0, 0.1*random(20,-20));
				A_SpawnItemEx("redFlash", 8, 0, 16, 0);
                A_AlertMonsters();
                A_WeaponOffset(random(-2,2), random(30,34), WOF_INTERPOLATE);
            }
            USTG F 2 bright 
            {
                A_PlaySound("weapons/lightninggun/loop", CHAN_6, 1.0, false);                                
                A_GunFlash();
				A_FireProjectile("greenArcLightning", 0.1*random(20,-20), 0, 0, 8, 0, 0.1*random(20,-20));
				A_SpawnItemEx("redFlash", 8, 0, 16, 0);
                A_AlertMonsters();
                A_WeaponOffset(random(-2,2),random(30,34), WOF_INTERPOLATE);
            }
            USTG E 0 A_Refire("Hold");
        RealFire2End:
            USTG E 1 bright Offset(0,35) A_PlaySound("weapons/lightninggun/stop",6);
            USTG D 1 bright Offset(0,34);
            USTG C 1 bright Offset(0,33);
            USTG B 1 bright Offset(0,32);
            USTG A 5 A_ReFire("RealFire2");
            USTG A 140 A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWUSER1);
			USTF HIJ 4 A_WeaponReady(WRF_ALLOWRELOAD|WRF_NOFIRE|WRF_NOSWITCH|WRF_ALLOWUSER1);
			TNT1 A 0
			{
				invoker.Fire2 = 0;
			}
			goto Ready;

		StopSoundnReload:
			TNT1 A 0 A_StopSound(CHAN_6);
			goto Reload;
		
		/*User1:
			USTF JKLMN 1;
			MLKN ABC 1;
			MLKN D 1 A_KnifeSlash();
			MLKN EFG 1;
			MLKN G 0;
			USTF MNLKJ 2;
			goto Ready;*/
							  
		ReloadFinish:	
			USTU A 3;
			USTU B 2;
			USTU C 1 A_Playsound("weapons/staffOpen");
			USTU DEFGH 2;
			USTU I 4;
			USTU J 3;
			USTU K 2;
			USTU L 3;
			USTU M 4;
			USTU N 5 A_PlaySound("weapons/staffOut");
			USTU OP 3;
			USTU QR 4;
			USTU ST 3;
			USTU UVW 2;
			USTU W 1;
			USTL W 2
			{
				A_JumpIfInventory("NoAdvDebris",1,2,AAPTR_PLAYER1);
				A_FireProjectile("staffCasingSpawner",-10,0,15,0);				
			}
			USTL WVU 3;
			USTL TS 3;
			USTL RQ 4;
			USTL PO 5;
			USTL N 5;
			USTL M 9 A_PlaySound("weapons/plasmaLoad_2");
			USTL L 5;
			USTL K 3;
			USTL J 4;
			USTL I 6;
			USTL HGFED 2;
			USTL C 2 A_Playsound("weapons/staffClose");
			USTL B 2;
			USTL A 3;
			USTL A 3;
			Goto Ready;	
	}
}
Post Reply

Return to “Scripting”