Help with ZSCRIPT: switchable fire 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!)
User avatar
Ahpiox
Posts: 98
Joined: Fri Dec 22, 2017 1:52 am

Help with ZSCRIPT: switchable fire modes

Post by Ahpiox »

All day i trying to make possible switch single mode to semi-auto mode, and vice versa. But nothing happening
Code here:

Code: Select all

Class TriRevolver : Weapon
{
 int TriMode;
 Default{
  Weapon.SelectionOrder 2000;
  Weapon.AmmoUse 1;
  +WEAPON.NOAUTOAIM
  Weapon.BobRangeX 0.0;
  Weapon.BobRangeY 0.1;
  Weapon.SlotNumber 2;
  Weapon.AmmoGive 20;
  Weapon.AmmoType "Clip";
  Inventory.PickupMessage "You got the TriRevolver";
  Obituary "%o was mowed down by %k's TriRevolver";
  Tag "$TAG_PISTOL";
 }
  States
  {
  Ready:
    TRVL A 1 A_WeaponReady;
    Loop;
  Deselect:
	TNT1 A 0
	{
		invoker.TriMode = 0;
	}
    TRVL A 1 A_Lower;
    Loop;
  Select:
    TNT1 A 0
	{
		invoker.TriMode = 0;
	}
    TRVL A 1 A_Raise;
    Loop;
  Fire:
	TRVL A 1 A_JumpIf(invoker.TriMode == 1,"Fire1");
	TRVL A 0 Bright A_FireBullets (2, 2, 1, 70, "TriPuff");
    TRVL AA 0 Bright A_FireBullets (5, 5, 1, 50, "TriPuff");
    TRVL A 1 A_PlaySound("weapons/pistol", CHAN_WEAPON);
    TRVL A 0 A_GunFlash;
	TNT1 A 0 A_Quake (6, 2, 0, 4);
    TRVL ABCD 2 A_SetPitch (pitch-2);
	TRVL B 7;
	TRVL A 19;
    TRVL A 5 A_ReFire;
    Goto Ready;
  Fire1:
	TRVL A 2 Bright A_FireBullets (5, 5, 1, 50, "TriPuff");
	TNT1 A 1 A_Quake (6, 2, 0, 4);
	TRVL A 0 A_SetPitch (pitch-2);
    TRVL A 0 A_PlaySound("weapons/pistol", CHAN_WEAPON);
	TRVL A 2 Bright A_FireBullets (5, 5, 1, 50, "TriPuff");
	TNT1 A 1 A_Quake (6, 2, 0, 4);
	TRVL A 0 A_SetPitch (pitch-2);
    TRVL A 0 A_PlaySound("weapons/pistol", CHAN_WEAPON);
	TRVL A 2 Bright A_FireBullets (5, 5, 1, 50, "TriPuff");
	TNT1 A 1 A_Quake (6, 2, 0, 4);
	TRVL A 0 A_SetPitch (pitch-2);
    TRVL A 0 A_PlaySound("weapons/pistol", CHAN_WEAPON);
    TRVL A 0 A_GunFlash;
    TRVL ABCD 2;
	TRVL B 7;
	TRVL A 19;
    TRVL A 5 A_ReFire;
    Goto Ready;
  AltFire:
	TRVL A 1 {
    if (invoker.TriMode == 0){ invoker.TriMode = 1;}}
	TRVL A 1 A_JumpIf(invoker.TriMode == 1,"Ready");
  Goto Ready;
  Spawn:
    PIST A -1;
    Stop;
  }
}
Blue Shadow
Posts: 4984
Joined: Sun Nov 14, 2010 12:59 am

Re: Help with ZSCRIPT: switchable fire modes

Post by Blue Shadow »

From what I can see from the code, once the mode is changed to 1, it can never be changed back to 0 unless you switch out the weapon. If you change the AltFire state to this code, it should fix the mode switching:

Code: Select all

AltFire:
    TRVL A 1
    {
        invoker.TriMode ^= 1; // Toggle between 0 and 1.
    }
    Goto Ready;
Whether that'll fix the issue you're having or not is something I don't know.
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

Re: Help with ZSCRIPT: switchable fire modes

Post by Matt »

I'd add an althold state that does nothing, otherwise you end up rapidly switching back and forth while you've got altfire pressed.

Code: Select all

AltFire:
    TRVL A 0
    {
        invoker.TriMode ^= 1; // Toggle between 0 and 1.
    }
    // Intentional fall-through to AltHold.
AltHold:
    TRVL A 1;
    TRVL A 0 A_Refire();
    Goto Ready;
User avatar
Ahpiox
Posts: 98
Joined: Fri Dec 22, 2017 1:52 am

Re: Help with ZSCRIPT: switchable fire modes

Post by Ahpiox »

O, thanks. I actually solved this problem by giving switching function to Reload state. But i will use this now, thanks

Return to “Scripting”