DECORATE Weapon Questions

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 a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: DECORATE Weapon Questions

Re: DECORATE Weapon Questions

by Exosphere » Tue Dec 12, 2017 2:24 pm

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?

Re: DECORATE Weapon Questions

by jdredalert » Mon Dec 11, 2017 11:31 pm

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.

Re: DECORATE Weapon Questions

by Exosphere » Mon Dec 11, 2017 10:59 pm

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.

Re: DECORATE Weapon Questions

by Blue Shadow » Mon Dec 11, 2017 10:23 pm

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.

Re: DECORATE Weapon Questions

by Exosphere » Mon Dec 11, 2017 7:37 pm

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");}
	}
}

Re: DECORATE Weapon Questions

by Blue Shadow » Mon Dec 11, 2017 6:56 pm

Could you post the whole code of the weapon?

Re: DECORATE Weapon Questions

by Exosphere » Mon Dec 11, 2017 3:12 pm

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.

Re: DECORATE Weapon Questions

by R4L » Mon Dec 11, 2017 2:27 pm

Wouldn't be because your script is named "reload" and your calling "reloader" in your Reload state, would it?

Re: DECORATE Weapon Questions

by Exosphere » Mon Dec 11, 2017 12:20 pm

R4L wrote:JumpIfNoAmmo should be the first thing in your fire state.

EDIT: Deleted most of my post because it was just plain incorrect. Looking at your new code for reloading, it seems that you have only defined how the rifle reloads, not the other two weapons.
Its ok about deleting you post, dont worry about it. :) The other reloads are mostly the same, but I can the adding details on my own.

Anyway, another update. I was still experimenting with the decorate functions before trying out ACS again. Luckily, I was surprisingly able to make it work, to an extent. The weapon will still fires even if the ammo is empty in their corresponding magazines. The +AMMO_OPTIONAL flag isnt present in the weapon.

ACS

Code: Select all

script "Reloader" (void) 
{
	if (CheckWeapon("OICW") == 1)
	{
		if(CheckInventory("RifleMode")==1)
		{ GiveInventory("RifleMag", 25); Print(s:"Rifle Reloaded"); }
	}
}
DECORATE

Code: Select all

RifleFire:
			OICW A 1 A_JumpIfNoAmmo("Reload")
			OICW A 1 BRIGHT A_FireProjectile()
			OICW A 1 A_TakeInventory("RifleMag", 1)
			OICW A 1 A_Refire
			Goto Ready

Reload:
			OICW A 1 ACS_NamedExecute("Reloader", 0, 0, 0, 0)
			//play sound indicating weapon has been reloaded
			Goto Ready

Re: DECORATE Weapon Questions

by R4L » Sun Dec 10, 2017 12:50 pm

JumpIfNoAmmo should be the first thing in your fire state.

EDIT: Deleted most of my post because it was just plain incorrect. Looking at your new code for reloading, it seems that you have only defined how the rifle reloads, not the other two weapons.

Re: DECORATE Weapon Questions

by Exosphere » Sat Dec 09, 2017 1:58 pm

R4L wrote:For reloading, you will want to do two ammo types for each mode. One type is your magazine count, the other is your reserve. In your Reload state you create a new looping state that adds 1 to your magazine and takes 1 from reserve if the weapon magazine is not full. If it is full, you go to your second reload state where you finish up the reload. Do a check in your Fire state for when there is no ammo, and jump to the Reload state.
I gave it a shot, however I am pretty sure this isnt the method you are referring to. Here is the code.

Code: Select all

ACTOR RifleMagReserve : Ammo
{
	Inventory.MaxAmount 99
	+INVENTORY.PERSISTENTPOWER
	+INVENTORY.INVBAR
	+IGNORESKILL
}
ACTOR RifleMagCount : Ammo
{
	Inventory.Amount 99
	+IGNORESKILL
}

States
{
RifleFire:
			OICW A 2 A_FireCGun
			OICW A 1 A_TakeInventory("RifleMagCount", 1)
			OICW A 1 A_Refire
			OICW A 1 A_JumpIfNoAmmo("RifleReload")
			Goto Ready
RifleReload:
			OICW A 1 A_TakeInventory("RifleMagReserve", 1)
			OICW A 1 A_GiveInventory("RifleMagCount", 1)
			OICW A 1 A_JumpIfInventory("RifleMagCount", 99, "RifleReady")
			Loop
RifleReady:
			TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO, 50.0)
			OICW A 1 A_Print("Rifle Reloaded")
			Goto Ready
}
However, I am still encountering the problem of when the Rocket launcher is fired once, it can't be fired again and I cant switch to any other mode.

Anyone have any thoughts?

Re: DECORATE Weapon Questions

by R4L » Fri Dec 08, 2017 2:16 pm

For reloading, you will want to do two ammo types for each mode. One type is your magazine count, the other is your reserve. In your Reload state you create a new looping state that adds 1 to your magazine and takes 1 from reserve if the weapon magazine is not full. If it is full, you go to your second reload state where you finish up the reload. Do a check in your Fire state for when there is no ammo, and jump to the Reload state.

Re: DECORATE Weapon Questions

by Exosphere » Fri Dec 08, 2017 11:29 am

SIgnificant Update:

After some tinkering, and with a little help from Blitzky, I was able to successfully have it so that the weapon can switch between the rifle, shotgun, and rocket launcher without fail. Now with that complete, the final aspect for the weapon that I would want to have is the ability to reload at will or once the ammo from the magazine is depleated. (The gun will use infinite ammo.) However, with the method that I had implemented, it doesnt function properly, in that it doesnt reload (with all weapons) and stalls on the rocket mode after firing one rocket. (I will include the code snippets for people to look at, along with the ACS of the improved cycler.) Let me know if anything needs to be clairified.

ACS

Code: Select all

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.");
		}
	}
DECORATE

Code: Select all

ACTOR RifleMag : Ammo
{
	Inventory.MaxAmount 99
	+INVENTORY.PERSISTENTPOWER
	+INVENTORY.INVBAR
	+IGNORESKILL
}
//Magazine Example

Reload:
			TNT1 A 0 A_JumpIfInventory("RifleMag", 0, "RifleReload")
			etc
			Goto Ready
RifleReload:
			OICW A 1 A_GiveInventory("RifleMag", 99)
			Goto Ready
ShotgunReload:
			~ (same syntax as above)
			Goto Ready
RocketReload:
			~ (same syntax as above)
			Goto Ready

Re: DECORATE Weapon Questions

by Blitzky » Wed Dec 06, 2017 7:50 pm

Here's my 'analysis':

Code: Select all

DECORATE
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

AltFire:
         PLSG A 1 ACS_NamedExecute("Cycler", 0, 1, 0, 0)  //Call 'Cycler' with a value of 1 for the first argument
         OICW A 1 A_Log("Mode Switched")
         Goto Ready
=========================================================
ACS
#library "cyclr"
#include "zcommon.acs"

script "Cycler" (int mode)	//Value of 1 is passed to 'mode' by the altfire state
{
   int init = 1;	//'init' is created and given a value of 1
   mode = init;	//'mode' is given the value of 'init'(1)
   
   if (CheckWeapon("OICW") == 1)  //Make sure the player is using the OICW
   {
      mode++;	//'mode' is incremented, now a value of 2
      
      if(mode == init)	//'mode' is 2, skip this part
      {
         TakeInventory("RocketMode", 1);
         GiveInventory("RifleMode", 1);
         Log(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
      }
      if(mode == 2)	//'mode' is 2, execute this
      {
         TakeInventory("RifleMode", 1); 
         GiveInventory("ShotgunMode", 1);
         Log(s:"10ga Shotgun Mode: ACTIVE.");
      }
      if(mode == 3)	//'mode' is 2, nothing beyond is executed
      {
         TakeInventory("ShotgunMode", 1);
         GiveInventory("RocketMode", 1);
         Log(s:"20mm Smart Rocket Mode: ACTIVE.");
      }
      if(mode == 4)
      { mode = init; }
   }
}
This is what I mentioned earlier. You defined 'mode' as an argument here, and pass it a value of 1 when altfire is used.
However, your script immediately gives it a value of 1 regardless by setting it equal to 'init'.
To remedy this without editing your script, you would need to write a few more lines in the altfire state that pass values of 1, 2, or 3, depending on which of the three dummy items the player is currently holding.
The 'init' value is redundant, as it is the same as giving mode a value of 1.

However, you can completely avoid the use of variables like this:

Code: Select all

#library "cyclr"
#include "zcommon.acs"
 
script "Cycler" (void)
{
   if (CheckWeapon("OICW") == 1) //Make sure the player is using the OICW
   {
      if(CheckInventory("RifleMode")) //Execute if the player has "RifleMode"
      {
         TakeInventory("RifleMode", 1); 
         GiveInventory("ShotgunMode", 1);
         Log(s:"10ga Shotgun Mode: ACTIVE.");
      }
	  
	  else if(CheckInventory("ShotgunMode")) //Execute if the player has "ShotgunMode"
      {
         TakeInventory("ShotgunMode", 1);
         GiveInventory("RocketMode", 1);
         Log(s:"20mm Smart Rocket Mode: ACTIVE.");
      }
	  
	  else if(CheckInventory("RocketMode"))	//Execute if the player has "RocketMode"
      {
         TakeInventory("RocketMode", 1);
         GiveInventory("RifleMode", 1);
         Log(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
      }  
   }
}

Re: DECORATE Weapon Questions

by Exosphere » Wed Dec 06, 2017 10:56 am

Blitzky wrote:I'll admit my knowledge of ACS is a bit limited, but...

Your variable 'mode' only exists within your script.

Every time you call this script, it checks to see if the player is holding the correct weapon, then increments mode by 1.
However, every time the script is called, it also sets 'mode' to be equal to 'init', which is 1.

Essentially, you're calling a script that assigns mode to 1, then increments it to 2 every time, meaning it's constantly trying to switch from rifle mode to shotgun mode.
Interesting. I'm also not as knowledgable in ACS, but still willing to learn. Do you have any suggestions on fixes I could change to make it work?

Top