[Z-script] super shotgun firing modes.

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
Gorman Frebmane
Posts: 116
Joined: Sat Jan 13, 2018 3:17 am

[Z-script] super shotgun firing modes.

Post by Gorman Frebmane »

I am new to z-script and i am trying to make a super shotgun made in zscript to have two firing modes, one where you fire one barrel and one where you can fire both barrels, thing is i want to make sure that everytime you use the firing modes they dont flip out and do wierd things such as firing one barrel and firing both barrels one after the other without reloading thus wasting 3 shells when i reality there are only two barrels.
Any advice?
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: [Z-script] super shotgun firing modes.

Post by ramon.dexter »

Here you go buddy, an example is worth thousand words:
It's the blood sawedoff shotgun made in zscript. Also it doesnt have the reload, because I don't really need it for two barrel weapon.

Also, use 'invoker.' As noted on zdoom wiki "Used to reference the inventory actor currently running ZScript code. Note that this includes player weapons. It is necessary to prefix an inventory items' local variable references or methods with invoker!", so use the invoker. to work with variables as noted here: https://zdoom.org/wiki/ZScript_special_words

Code: Select all

class BloodSawedoff : Weapon 
{   
    int sawedOffCheck;

    Default
    {
        //30337
        //$Category "SoA/weapons"
        //$color 6
        //$Title "upilovana brokovnice"
        
        //+WEAPON.CHEATNOTWEAPON;
		+WEAPON.NOALERT
        
        Tag "$T_SAWEDOFF";
        Weapon.SlotNumber 4;
        Weapon.SlotPriority 0;
        decal "bulletchip";
        inventory.pickupsound "weaponpickup";
        Inventory.icon "H_W1PU";
        Inventory.PickupMessage "$F_SAWEDOFF";
        Obituary "%o was splattered by %k's Super Shotgun!";
        Weapon.AmmoType1 "ammoShell";
        Weapon.AmmoType2 "ammoShell";
        Weapon.Kickback 100;
        Weapon.AmmoGive1 12;
        Weapon.AmmoUse1 1;
        Weapon.AmmoUse2 1;
        scale 0.5;
		
		height 16;
		radius 12;
    }
    States
    {
		Spawn:
			W1PU A -1;
			Stop;
		Ready:
			WP01 A 1 A_WeaponReady();
			Loop;
		Deselect:
			WP01 A 1 A_Lower();
			TNT1 AA 0 A_LOWER();
			Loop;
		Select:
			WP01 A 1 A_Raise();
			TNT1 AA 0 A_RAISE();
			Loop;
		Fire:
			TNT1 A 0 A_JumpIf(invoker.sawedOffCheck == 1,"Fire2");
			SWFL A 0 A_GunFlash();
			SWFL ABC 2 Bright;
			TNT1 A 5;      
			TNT1 A 0
			{
				invoker.sawedOffCheck = 1;
			}
			goto ready;
		Fire2:
			SWFL A 0 A_GunFlash();
			SWFL DEF 2 Bright;  
			TNT1 A 0 A_JumpIfInventory("NoAdvDebris",1,2,AAPTR_PLAYER1);
			TNT1 A 0 A_FireProjectile("shellCasingSpawner",-10,0,15,0);
			TNT1 A 0 A_FireProjectile("shellCasingSpawner",-10,0,15,0);
			TNT1 A 24;     
			TNT1 A 0
			{
				invoker.sawedOffCheck = 0;
			}
			goto ready;
		AltFire:
			TNT1 A 0 A_JumpIf(invoker.sawedOffCheck == 1,"Fire2");
			TNT1 A 0 A_GunFlash();
			SWF2 ABC 2 bright;
			TNT1 A 26;
			goto ready;
		Flash:
			TNT1 A 0 A_JumpIf(invoker.sawedOffCheck == 1,"Flash2");
			TNT1 A 0 A_PlaySound("weapons/wweshotgunfire");
			ANIM D 1 
			{
				A_FireBullets(9, 7, 20, 5, "puffShotgun", 1, 0);
				//A_TakeInventory("shell",1);
				A_SpawnItemEx("gunFlash", 8, 0, 16, 0);
				A_AlertMonsters();
			}					
			ANIM EFG 1; 
			ANIM GFE 1;
			ANIM DCBA 1;
			Stop;
		Flash2:
			TNT1 A 0 A_PlaySound("weapons/wweshotgunfire");
			ANIM D 1
			{
				A_FireBullets(9, 7, 20, 5, "puffShotgun", 1, 0);
				//A_TakeInventory("shell",1);
				A_SpawnItemEx("gunFlash", 8, 0, 16, 0);
				A_AlertMonsters();
			}		
			ANIM EFG 1;
			ANIM GFE 1;
			ANIM EDCB 1;
			TNT1 A 0 A_PlaySound("weapons/wweshotguncock");
			WP01 EFG 2;
			WP01 HIJKLMNOPQRST 1;
			Stop;
		altflash:
			TNT1 A 0 A_JumpIf(invoker.sawedOffCheck == 1,"Flash2");
			TNT1 A 0 A_PlaySound("weapons/wweshotgundouble");
			ANIM D 0;
			ANIM D 1 
			{
				A_FireBullets(9, 7, 20, 5, "puffShotgun", 1, 0);
				A_FireBullets(9, 7, 20, 5, "puffShotgun", 1, 0);
				//A_TakeInventory("shell",2);
				A_SpawnItemEx("gunFlash", 8, 0, 16, 0);
				A_AlertMonsters();
			}		
			ANIM EFG 1; 
			ANIM HII 1;
			ANIM HGFEDC 1;
			TNT1 A 0 A_PlaySound("weapons/wweshotguncock");
			WP01 EFG 2; 
			TNT1 A 0 A_JumpIfInventory("NoAdvDebris",1,2,AAPTR_PLAYER1);
			TNT1 A 0 A_FireProjectile("shellCasingSpawner",-10,0,15,0);
			TNT1 A 0 A_FireProjectile("shellCasingSpawner",-10,0,15,0);	  
			WP01 HIJKLMNOPQRST 1;
			stop;
		
    }  
}

Return to “Scripting”