DECORATE Weapon Questions

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
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions

Post by Exosphere »

R4L wrote:Wouldn't be because your script is named "reload" and your calling "reloader" in your Reload state, would it?
Oops, thats a typo. Let me correct it.
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: DECORATE Weapon Questions

Post by Blue Shadow »

Could you post the whole code of the weapon?
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions

Post by Exosphere »

Blue Shadow wrote:Could you post the whole code of the weapon?

Code: Select all

ACTOR RifleMag : Ammo
{
	Inventory.Amount 25
	Inventory.MaxAmount 25
	+IGNORESKILL
}

ACTOR ShotgunTube : Ammo
{
	Inventory.Amount 8
	Inventory.MaxAmount 8
	+IGNORESKILL
}

ACTOR RocketMag : Ammo
{
	Inventory.Amount 3
	Inventory.MaxAmount 3
	+IGNORESKILL
}

ACTOR RifleMode : Inventory{}
ACTOR ShotgunMode : Inventory{}
ACTOR RocketMode : Inventory{}

ACTOR OICW : Weapon
{
	Tag "OICW"
	Inventory.PickupMessage ""
	Inventory.PickupSound ""
	Weapon.SlotNumber 2
	Weapon.SelectionOrder 2
	+NOAUTOFIRE
	
	States
	{
		Spawn:
			PLAS A -1
			Loop
		Ready:
			PLSG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			Loop
		Deselect:
			PLSG A 1 A_Lower //PLSG A
			Loop
		Select:
			PLSG A 1 A_Raise //PLSG A
			Loop
		Fire:
			TNT1 A 0 A_JumpIfInventory("RifleMode", 1, "RifleFire")
			TNT1 A 0 A_JumpIfInventory("ShotgunMode", 1, "ShotgunFire")
			TNT1 A 0 A_JumpIfInventory("RocketMode", 1, "RocketFire")
			Goto Ready
			
		//------------------------------
		//	9.5x25mm Caseless Rifle Mode
		//------------------------------
		RifleFire:
			OICW A 1 A_JumpIfNoAmmo("Reload")
			OICW A 1 BRIGHT A_FireProjectile("ARBullet", frandom(-1.7, 1.7), 1, 0, 0, 0, frandom(-1.7, 1.7))
			OICW A 1 A_TakeInventory("RifleMag", 1)
			OICW A 1 A_Refire
			Goto Ready
			
		//-----------------------
		//	10 Gauge Shotgun Mode
		//-----------------------
		ShotgunFire:
			OICW A 1 A_JumpIfNoAmmo("Reload")
			OICW A 15 A_FireShotgun2
			OICW A 1 A_TakeInventory("ShotgunTube", 1)
			Goto Ready
			
		//---------------------------------
		//	20mm Smart Rocket Launcher Mode
		//---------------------------------
		RocketFire:
			OICW A 1 A_JumpIfNoAmmo("Reload")
			OICW A 20 A_FireMissile
			OICW A 1 A_TakeInventory("RocketMag", 1)
			Goto Ready
			
		AltFire:
			OICW A 1 ACS_NamedExecute("Cycler", 0, 0, 0, 0)
			TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO, 50.0)
			Goto Ready
			
		Reload:
			OICW A 1 ACS_NamedExecute("Reloader", 0, 0, 0, 0)
			TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO, 50.0)
			Goto Ready
	}
}
Here is also the ACS code for Reloader and Cycler. Also, for the Cycler to work, you must give the player "RifleMode" first.

Code: Select all

#library "cyclr"
script "Cycler" (void)
{

	if (CheckWeapon("OICW") == 1)
	{
		if(CheckInventory("RocketMode")==1 && CheckInventory("RifleMode")==0)
		//If Rocket Mode is ACTIVE and RifleMode is INACTIVE 
		{
			TakeInventory("RocketMode", 1);
			GiveInventory("RifleMode", 1);
			Print(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
		}
		else if(CheckInventory("RifleMode")==1 && CheckInventory("ShotgunMode")==0)
		//If Rifle Mode is ACTIVE and Shotgun Mode is INACTIVE
		{
			TakeInventory("RifleMode", 1); 
			GiveInventory("ShotgunMode", 1);
			Print(s:"10ga Shotgun Mode: ACTIVE.");
		}
		else if(CheckInventory("ShotgunMode")==1 && CheckInventory("RocketMode")==0)
		//If Shotgun Mode is ACTIVE and RocketMode is INACTIVE
		{
			TakeInventory("ShotgunMode", 1);
			GiveInventory("RocketMode", 1);
			Print(s:"20mm Smart Rocket Mode: ACTIVE.");
		}
	}
}

#library "rldr"
script "Reloader" (void)
{
	if (CheckWeapon("OICW") == 1)
	{
		if(CheckInventory("RifleMode")==1)
		{ GiveInventory("RifleMag", 25); Print(s:"Rifle Reloaded"); }
		
		else if(CheckInventory("ShotgunMode")==1)
		{ GiveInventory("ShotgunTube", 8); Print(s:"Shotgun Reloaded"); }
		
		else if(CheckInventory("RocketMode")==1)
		{ GiveInventory("RocketMag", 3); Print(s:"Smart Rocket Reloaded");}
	}
}
Blue Shadow
Posts: 4949
Joined: Sun Nov 14, 2010 12:59 am

Re: DECORATE Weapon Questions

Post by Blue Shadow »

Your weapon is ammo-less (it lacks [wiki=Weapon_properties#Weapon.AmmoType]Weapon.AmmoType[/wiki]). This is why A_JumpIfNoAmmo doesn't work as expected. You may want to use [wiki]A_JumpIfInventory[/wiki] instead of A_JumpIfNoAmmo.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions

Post by Exosphere »

Blue Shadow wrote:Your weapon is ammo-less (it lacks [wiki=Weapon_properties#Weapon.AmmoType]Weapon.AmmoType[/wiki]). This is why A_JumpIfNoAmmo doesn't work as expected. You may want to use [wiki]A_JumpIfInventory[/wiki] instead of A_JumpIfNoAmmo.
I do understand that the weapon doesn't have an ammo type, since I would've ideally like to have three different ammo types. Also, after changing the A_JumpIfNoAmmo to A_JumpIfInventory (and putting it at the end of the state before "Goto Ready" since it would do nothing but reload), still continues to fire projectiles even after the magazine is empty.
User avatar
jdredalert
Posts: 1668
Joined: Sat Jul 13, 2013 10:13 pm

Re: DECORATE Weapon Questions

Post by jdredalert »

I made a weapon that could cycle through three different kinds of ammo, it was all made on DECORATE. Maybe you should take a look:

Click me.

Just keep in mind that i'm not actually using real ammo types, but inventory items instead.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions

Post by Exosphere »

jdredalert wrote:I made a weapon that could cycle through three different kinds of ammo, it was all made on DECORATE. Maybe you should take a look:

Click me.

Just keep in mind that i'm not actually using real ammo types, but inventory items instead.
Funny you mentioning that weapon you made. Back in the summer, I had originally looked through that to get a sense of how use more than three ammo types could work, but went with making three separate weapons. Now returning to the one weapon & multiple ammo types, I remembered your weapon.

Could you look through my code, to see what is missing or needs to be fixed? My intent is to have it so that it can switch between bullets, shotgun, and rockets (obviously), while each having its own magazine size. I've also wanted to have it so that the weapon has unlimited ammo, but still needs to be reloaded. Think of the combat rifle from Lithium. If you need it, would you also need to see the Cycler code?

Return to “Scripting”