DECORATE Weapon Questions II (SOLVED)

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

DECORATE Weapon Questions II (SOLVED)

Post by Exosphere »

Hello again Forums,

I have been working on a small weapons pack over the past few months, but have encountered some problems that haven't been solved even after staying up hours into the night and slamming my head against my computer without getting any better results.

1. I have a lightning gun-like weapon, based on Reelism's Thunderbolt (with Kinise's permission), that recharges ammo when the primary fire is released or the ammo reaches 0 after firing. However, I have been plauged by two particular bugs: A. Even though the current recharging method works (Having a A_GiveInventory("Battery", 1) in the Ready state), when the ammo reaches zero, the looping fire sound continues to play, the weapon deselects itself, and I am unable to select it again. B. The end sound doesn't play when Primary fire is released.

2. The assualt rifle weapon has been giving me the most touble. The main attributes I have been attempting to create are having the ability to cycle through the three modes, rifle-shotgun-rocket. The second is having two different ammo types (one for the rifle, the other for the shotgun and rocket) and correctly using their respective ammo pools. The ammo would be reloaded using magazines, but essentially be infinite. While cycling through the fire modes are successful through the use of an ACS script, the weapon cannot be reloaded and the shotgun mode takes ammo from the primary ammo as well as the secondary ammo, despite being specified not to do so.


NOTE: I know this is a little late to ask, but please don't steal this and redistribute it as your own work, if for any reason you are compelled to do so.
Here is the Assualt rifle code with the ACS Cycler

Code: Select all

		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
			
		//------------------------------
		//	Rifle Mode
		//------------------------------
		RifleFire:
			HARA A 1 A_FireBullets(2.5, 2.5, 1, 0, "BulletPuff", FBF_USEAMMO, 8192, "ARBullet", 8, 0)
			HARA A 1 A_TakeInventory("RifleMag", 1)
			HARA A 1 A_JumpIfNoAmmo("Reload")
			HARA A 1 A_Refire
			Goto Ready
		
		//-----------------------
		//	Shotgun Mode
		//-----------------------
		ShotgunFire:
			HARA A 1 A_PlaySound("weapons/shtgn", CHAN_WEAPON)
			//HARA A 5 A_FireBullets(2.5, 2.5, 7, 0, "BulletPuff", FBF_USEAMMO, 8192, "Pellet", 8, 0)
			TNT1 A 0 A_TakeInventory("OmniShot", 1)
			TNT1 A 0 A_JumpIfNoAmmo("Reload")
			Goto Ready
			
		//---------------------------------
		//	Rocket Launcher Mode
		//---------------------------------
		RocketFire:
			HARA A 1 A_Print("Malfuction")
			Goto Ready
		
		Reload:
			HARA A 1 A_JumpIfInventory("RifleMag", 0, "RifleReload")
			HARA A 1 A_JumpIfInventory("OmniShot", 0, "UnderslungReload")
			Goto Ready
			
		RifleReload:
			HARA A 1 A_GiveInventory("RifleMag", 50)
			Goto Ready
			
		UnderslungReload:
			HARA A 1 A_GiveInventory("OmniShot", 8)
			Goto Ready
		
		//Swap Modes
		AltFire:
			OICW A 1 ACS_NamedExecute("OICWCycler", 0, 0, 0, 0)
			TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO, 50.0)
			Goto Ready
	}

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:"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:"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:"Rocket Mode: ACTIVE.");
		}
Any help would be greatly appreciated

NOTE: I know this is a little late to ask, but please don't steal this and redistribute it as your own work, if for any reason you are compelled to do so.
Last edited by Exosphere on Fri Mar 09, 2018 10:01 am, edited 3 times in total.
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

I used "A_StopSound" in the beginning of "Ready" -state to stop soundlooping. For the end sound, take a look at the i'm posting. It's probably not the best way to deal with, but it works for me.

Code: Select all

  Fire:
  	TNT1 A 0 A_StopSound(5)
	TNT1 A 0 A_PlaySound("smg/fireloop", 5, 1, 1) //Loop sound is played on channel 5
    SMG1 A 0 A_JumpIfNoAmmo("Ready")
    Goto FireLoop
  FireLoop:
    SMG1 B 1 Offset(3,35) 
	{
		A_FireBullets(5, 4, 1, random(4, 6), BulletImpact);
		A_GunFlash;
	}
	TNT1 A 0 A_JumpIf(GetCVar(tm_gunflash), 2)
	TNT1 A 0 A_SetBlend("Orange", 0.03, 5)
	TNT1 A 0 A_SpawnItemEx("Smoke2", 14, 10, 37, frandom(0.0, 0.2), frandom(0.0, 0.2), frandom(0.3, 0.6)) 
    SMG1 C 1 Bright Offset(2,34)
    SMG1 C 1 Bright Offset(1,33)
	TNT1 A 0 A_JumpIfNoAmmo("Ready")
    SMG1 D 1 Offset(3,35) 
	{
		A_FireBullets(5, 4, 1, random(4, 6), BulletImpact);
		A_GunFlash;
	}
	TNT1 A 0 A_JumpIf(GetCVar(tm_gunflash), 2)
	TNT1 A 0 A_SetBlend("Orange", 0.03, 5)
	TNT1 A 0 A_SpawnItemEx("Smoke2", 14, 10, 37, frandom(0.0, 0.2), frandom(0.0, 0.2), frandom(0.3, 0.6))
    SMG1 C 1 Bright Offset(2,34)
    SMG1 C 1 Bright Offset(1,33)
    SMG1 A 1 A_ReFire("FireLoop") //When the fire button is held, it jumps back to beginning of this state, and once released it plays the fire end sound
	TNT1 A 0 A_PlaySound("smg/fireend", 6)
    	TNT1 A 0 A_StopSound(5) // Stops the loop sound
    Goto Ready
Edit: For the shotgun and rl mode using primary ammo, it's probably because of the flag "FBF_USEAMMO". Try removing any flags from "A_FireBullets" for SG and RL mode.

Edit2: While i was on my way to work, i remembered that you also need A_StopSound for the "Lower" -state and to make the weapon selectable when it's empty, it needs "WEAPON.AMMO_OPTIONAL" -flag. If weApon doesn't use ammo when firing just add A_TakeInventory to it's firing state.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:I used "A_StopSound" in the beginning of "Ready" -state to stop soundlooping. For the end sound, take a look at the i'm posting. It's probably not the best way to deal with, but it works for me.

Code: Select all

  Fire:
  	TNT1 A 0 A_StopSound(5)
	TNT1 A 0 A_PlaySound("smg/fireloop", 5, 1, 1) //Loop sound is played on channel 5
    SMG1 A 0 A_JumpIfNoAmmo("Ready")
    Goto FireLoop
  FireLoop:
    SMG1 B 1 Offset(3,35) 
	{
		A_FireBullets(5, 4, 1, random(4, 6), BulletImpact);
		A_GunFlash;
	}
	TNT1 A 0 A_JumpIf(GetCVar(tm_gunflash), 2)
	TNT1 A 0 A_SetBlend("Orange", 0.03, 5)
	TNT1 A 0 A_SpawnItemEx("Smoke2", 14, 10, 37, frandom(0.0, 0.2), frandom(0.0, 0.2), frandom(0.3, 0.6)) 
    SMG1 C 1 Bright Offset(2,34)
    SMG1 C 1 Bright Offset(1,33)
	TNT1 A 0 A_JumpIfNoAmmo("Ready")
    SMG1 D 1 Offset(3,35) 
	{
		A_FireBullets(5, 4, 1, random(4, 6), BulletImpact);
		A_GunFlash;
	}
	TNT1 A 0 A_JumpIf(GetCVar(tm_gunflash), 2)
	TNT1 A 0 A_SetBlend("Orange", 0.03, 5)
	TNT1 A 0 A_SpawnItemEx("Smoke2", 14, 10, 37, frandom(0.0, 0.2), frandom(0.0, 0.2), frandom(0.3, 0.6))
    SMG1 C 1 Bright Offset(2,34)
    SMG1 C 1 Bright Offset(1,33)
    SMG1 A 1 A_ReFire("FireLoop") //When the fire button is held, it jumps back to beginning of this state, and once released it plays the fire end sound
	TNT1 A 0 A_PlaySound("smg/fireend", 6)
    	TNT1 A 0 A_StopSound(5) // Stops the loop sound
    Goto Ready
Edit: For the shotgun and rl mode using primary ammo, it's probably because of the flag "FBF_USEAMMO". Try removing any flags from "A_FireBullets" for SG and RL mode.

Edit2: While i was on my way to work, i remembered that you also need A_StopSound for the "Lower" -state and to make the weapon selectable when it's empty, it needs "WEAPON.AMMO_OPTIONAL" -flag. If weApon doesn't use ammo when firing just add A_TakeInventory to it's firing state.
With your tips, I was able to finally get the sound working properly (I hope). However, after the battery is out of ammo, the gun will still fire. Any ideas on how I could have it so that the gun would stop firing even if the primary fire is still being pressed? (I did attempt to include a state (with A_JumpIfInventory) that would print a message when the ammo hits zero, but it never triggers and the weapon keeps firing.)

Also, I chanced the A_FIREBULLETS in the assault rifle to the A_FIREPROJECTILE. Although, removing FBF_USEAMMO (when it still used A_FireBullets) from the Fire states in the assualt rifle did not help. Any other ideas?
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

Have you used A_JumpIfNoAmmo("statename") for Lightning Gun before it fires the projectile/beam/whatever? If that doesn't work can you post the code so i could take a look at it?

For the Assault Rifle: since you are using A_FireProjectile, have you set it to take any ammo. It's the third value (bool useammo, i don't know what these things are called).
Sorry, i can't help much with the AR as i'm out of ideas.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:Have you used A_JumpIfNoAmmo("statename") for Lightning Gun before it fires the projectile/beam/whatever? If that doesn't work can you post the code so i could take a look at it?

For the Assault Rifle: since you are using A_FireProjectile, have you set it to take any ammo. It's the third value (bool useammo, i don't know what these things are called).
Sorry, i can't help much with the AR as i'm out of ideas.
Here is the releavent code for the lightning gun

Code: Select all

ACTOR PrototypeBattery : Ammo
{
	Inventory.Amount 1
	Inventory.MaxAmount 20
	+IGNORESKILL
}

ACTOR LG : Weapon //Beam "Lightning" Gun
{
	Weapon.AmmoType1 "PrototypeBattery"
	Weapon.AmmoUse1 1

	Scale 1.0
	
	States
	{
		Spawn:
			ZEWM A -1
			stop
		Ready:
			ZEVA A 0 A_StopSound(6)
			TNT1 A 0 A_GiveInventory("PrototypeBattery", 1)
			ZEVA A 1 A_WeaponReady
			goto Ready+1
		Deselect:
			ZEVA A 0 A_StopSound(6)
			ZEVA A 0 A_Lower
			ZEVA A 1 A_Lower
			goto Deselect+2
		Select:
			ZEVA A 0 A_StopSound(6)
			ZEVA A 0 A_Raise
			ZEVA A 1 A_Raise
			goto Select+2
		Fire:
			ZEVA A 2
			ZEVA A 0 A_PlaySound("weapons/beam_on", 7)
		Hold:
			ZEVA A 0 Bright A_RailAttack(12,0,0,"none","00 0a 80",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
			TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
			ZEVA A 0 A_PlaySound("weapons/beam_run", 6, 1, 1)
			ZEVA A 0 A_TakeInventory("PrototypeBattery", 1)
			ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","ff ff ff",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
			TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
			ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","00 0a 80",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
			TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
			ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","ff ff ff",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
			TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
			ZEVA A 0 A_GunFlash
			ZEVA A 0 A_ReFire("Hold")
			ZEVA A 0 A_StopSound(7)
			ZEVA A 0 A_PlaySound("weapons/beam_off", CHAN_AUTO, 1)
			Goto Ready
	}
}
Also, don't worry about the AR, I might have found a suitable work around for the time being. btw Thanks for helping out.
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

I think i managed to fix the LG, it doesn't fire anymore when out of ammo. Read the code and the comments i'm posting.

Code: Select all

ACTOR LG : Weapon //Beam "Lightning" Gun
{
   Weapon.AmmoType1 "PrototypeBattery"
   Weapon.AmmoUse1 1
  +WEAPON.AMMO_OPTIONAL		//Required so that you can still select the weapon when it's out of ammo
    Scale 1.0
   
   States
   {
      Spawn:
         ZEWM A -1
         stop
      Ready:
         ZEVA A 0 A_StopSound(6)
         ZEVA A 1 A_WeaponReady	//I swapped places with this and the A_GiveInventory
         TNT1 A 0 A_GiveInventory("PrototypeBattery", 1) //this frame has no duration, so it always got 1 ammo everytime it went to Ready state and thats why it kept firing
         goto Ready+1
      Deselect:
         ZEVA A 0 A_StopSound(6)
         ZEVA A 0 A_Lower
         ZEVA A 1 A_Lower
         goto Deselect+2
      Select:
         ZEVA A 0 A_StopSound(6)
         ZEVA A 0 A_Raise
         ZEVA A 1 A_Raise
         goto Select+2
      Fire:
         ZEVA A 2 A_JumpIfNoAmmo("Empty")	//jump to the new state "Empty"
         ZEVA A 0 A_PlaySound("weapons/beam_on", 7)
      Hold:
         ZEVA A 0 A_JumpIfNoAmmo("Empty")	//jump to the new state "Empty"
         ZEVA A 0 Bright A_RailAttack(12,0,0,"none","00 0a 80",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA A 0 A_PlaySound("weapons/beam_run", 6, 1, 1)
         ZEVA A 0 A_TakeInventory("PrototypeBattery", 1) //you already had this, but this takes ammo even when you have +WEAPON.AMMO_OPTIONAL -flag
         ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","ff ff ff",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","00 0a 80",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","ff ff ff",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA A 0 A_GunFlash
         ZEVA A 0 A_ReFire("Hold")
         ZEVA A 0 A_StopSound(7)
         ZEVA A 0 A_PlaySound("weapons/beam_off", CHAN_AUTO, 1)
         Goto Ready
	Empty:		//i created new state where the gun jumps to when it runs out of ammo
	 ZEVA A 1	//gun doesn't recharge any ammo, when you hold the fire button
	 Goto Ready	//when you release it goes to ready state
   }
}
Think the "Empty" state as a some sort of cooldown.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:I think i managed to fix the LG, it doesn't fire anymore when out of ammo. Read the code and the comments i'm posting.

Code: Select all

ACTOR LG : Weapon //Beam "Lightning" Gun
{
   Weapon.AmmoType1 "PrototypeBattery"
   Weapon.AmmoUse1 1
  +WEAPON.AMMO_OPTIONAL		//Required so that you can still select the weapon when it's out of ammo
    Scale 1.0
   
   States
   {
      Spawn:
         ZEWM A -1
         stop
      Ready:
         ZEVA A 0 A_StopSound(6)
         ZEVA A 1 A_WeaponReady	//I swapped places with this and the A_GiveInventory
         TNT1 A 0 A_GiveInventory("PrototypeBattery", 1) //this frame has no duration, so it always got 1 ammo everytime it went to Ready state and thats why it kept firing
         goto Ready+1
      Deselect:
         ZEVA A 0 A_StopSound(6)
         ZEVA A 0 A_Lower
         ZEVA A 1 A_Lower
         goto Deselect+2
      Select:
         ZEVA A 0 A_StopSound(6)
         ZEVA A 0 A_Raise
         ZEVA A 1 A_Raise
         goto Select+2
      Fire:
         ZEVA A 2 A_JumpIfNoAmmo("Empty")	//jump to the new state "Empty"
         ZEVA A 0 A_PlaySound("weapons/beam_on", 7)
      Hold:
         ZEVA A 0 A_JumpIfNoAmmo("Empty")	//jump to the new state "Empty"
         ZEVA A 0 Bright A_RailAttack(12,0,0,"none","00 0a 80",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA A 0 A_PlaySound("weapons/beam_run", 6, 1, 1)
         ZEVA A 0 A_TakeInventory("PrototypeBattery", 1) //you already had this, but this takes ammo even when you have +WEAPON.AMMO_OPTIONAL -flag
         ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","ff ff ff",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","00 0a 80",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA AAA 1 Bright A_RailAttack(12,0,0,"none","ff ff ff",RGF_FULLBRIGHT|RGF_SILENT,2,"none",0,0,0,1,0,-2)
         TNT1 A 0 Radius_Quake(3, 2, 0, 1, 0)
         ZEVA A 0 A_GunFlash
         ZEVA A 0 A_ReFire("Hold")
         ZEVA A 0 A_StopSound(7)
         ZEVA A 0 A_PlaySound("weapons/beam_off", CHAN_AUTO, 1)
         Goto Ready
	Empty:		//i created new state where the gun jumps to when it runs out of ammo
	 ZEVA A 1	//gun doesn't recharge any ammo, when you hold the fire button
	 Goto Ready	//when you release it goes to ready state
   }
}
Think the "Empty" state as a some sort of cooldown.
That pretty much did the trick. It now stops firing, even when the primary fire is still being held down. (It just occured to me that I had actually experimented with a similar cooldown state that you implemeneted, but deleted it after it wasnt working properly.) While this is definetly a big improvment, I noticed that the "beam_off" wouldn't play, so I changed the "Empty" state to this.

Code: Select all

ZEVA A 0 A_StopSound(6)
			ZEVA A 0 A_PlaySound("weapons/beam_off", CHAN_AUTO, 1)
			ZEVA A 1
			Goto Ready

No other code was changed. It does work partially (the sound is duplicate and skips), but I wanted your input on it and how I can improve it. Thoughts?
ALSO,
Do you know of any methods of using A_FireProjectile to fire multiple projectiles at once? I vaguely remember a trick that involved having multiple frames in the projectile line, but I can't specifically remember it.

Code: Select all

//EXAMPLE
XXXX AAAAAAAAA 0 A_FireProjectile("BFGShot")
Again, thoughts?
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

The example you posted about firing multiple projectiles at once should work, but if you want them to be fired at different angles you have to use multiple frames and actions for that OR randomize the angle.
For the first method, you have two ways (maybe more but i don't remember any other) to do it:

Code: Select all

XXXX A 0 A_FireProjectile("BFGShot") //this is the simplier way to do it
XXXX A 0 A_FireProjectile("BFGShot", -25)
XXXX A 0 A_FireProjectile("BFGShot", 25) //with this method you fire 3 proj. towards center and a little bit left and right
And here is another way, by using Anonymous functions you can execute multiple actions during one frame, very useful trick.

Code: Select all

XXXX A 0 //certain keywords like "Offset" and "Bright" can be used in this, don't put any actions.
{  //Anonymous function is started and ended with braces/brackets i don't exactly know what these are called in english. All actions you want execute at the same time goes inside this
A_FireProjectile("BFGShot"); //every action NEEDS to end in a semicolon
A_FireProjectile("BFGShot", -25);
A_FireProjectile("BFGShot", 25);
} 
*rest of the decorate code goes here normally
And then you can randomize the launch angle:

Code: Select all

XXXX AAAAAA 0 A_FireProjectile("BFGShot",frandom(-3.0, 3.0) //first number is minimum and the next is maximum value for the randomization
I kinda didn't understand the issue you were having with the sounds. Is the "beam_off" played duplicate or something else? It might be because it jumps to the cooldown state everytime since it's out of ammo.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:The example you posted about firing multiple projectiles at once should work, but if you want them to be fired at different angles you have to use multiple frames and actions for that OR randomize the angle.
For the first method, you have two ways (maybe more but i don't remember any other) to do it:

Code: Select all

XXXX A 0 A_FireProjectile("BFGShot") //this is the simplier way to do it
XXXX A 0 A_FireProjectile("BFGShot", -25)
XXXX A 0 A_FireProjectile("BFGShot", 25) //with this method you fire 3 proj. towards center and a little bit left and right
And here is another way, by using Anonymous functions you can execute multiple actions during one frame, very useful trick.

Code: Select all

XXXX A 0 //certain keywords like "Offset" and "Bright" can be used in this, don't put any actions.
{  //Anonymous function is started and ended with braces/brackets i don't exactly know what these are called in english. All actions you want execute at the same time goes inside this
A_FireProjectile("BFGShot"); //every action NEEDS to end in a semicolon
A_FireProjectile("BFGShot", -25);
A_FireProjectile("BFGShot", 25);
} 
*rest of the decorate code goes here normally
And then you can randomize the launch angle:

Code: Select all

XXXX AAAAAA 0 A_FireProjectile("BFGShot",frandom(-3.0, 3.0) //first number is minimum and the next is maximum value for the randomization
I kinda didn't understand the issue you were having with the sounds. Is the "beam_off" played duplicate or something else? It might be because it jumps to the cooldown state everytime since it's out of ammo.
For the multi-projectile: Awesome. Thank ya for the info. Actually experimented with anonymous fuctions before.

For the beam_off sound: Its a little hard to explain what exactly is going on, but whats happening is *it appears that the beam_off sound being played at the end of the Hold and Empty is being played simultaineously and, while the fire button is still being held, the beam_off is looping from the beginning of the sound and never stopping, like a music track skipping on a CD player*.

That is, essentially, the problem that I am experiencing.
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

Do you still have the problem? Have you tried using different sound channels for "beam_off" sound? Remember to check that you don't have the looping applied to the beam_off sound.
If it still doesn't work, sorry, i'm out of ideas and can't help with it.
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:Do you still have the problem? Have you tried using different sound channels for "beam_off" sound? Remember to check that you don't have the looping applied to the beam_off sound.
If it still doesn't work, sorry, i'm out of ideas and can't help with it
I’ve decided to put the sound part on hold for now to work on the other weapons. I decided to rework on the assault rifle, and to remove the use of ACS in the weapon as the current method isnt working correctly and might be the cause of my problems (the problem being that the weapon still fires even if the magazine is empty.) Would you by any chance have any suggestions on how to make that happen? (I was thinking about using anonymous functions, but i’m not sure.)

Another thing I’ve been working on is having a weapon that doesnt harm enemies, but actually makes them friendly to the player. I’ve seen this done in LegenDoom, but not sure how to implement it. Any idea on how this could work?
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

Another thing I’ve been working on is having a weapon that doesnt harm enemies, but actually makes them friendly to the player. I’ve seen this done in LegenDoom, but not sure how to implement it. Any idea on how this could work?
I'm not 100% sure on how this could be implemented but i would add a new damagetype (lets call it "MindControl") for the projectile that turns enemies friendly.
Then you need to edit monster actors so that they have a custom pain state (Pain.MindControl), and when the monster enters this state A_ChangeFlag with flagname "FRIENDLY" gets called.
You could also add custom painchances for all monsters, so that larger monsters are harder to "mindcontrol" and smaller ones are easier.

Could you post the new AR's code, so i could try looking for a way to fix it?
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:
Another thing I’ve been working on is having a weapon that doesnt harm enemies, but actually makes them friendly to the player. I’ve seen this done in LegenDoom, but not sure how to implement it. Any idea on how this could work?
I'm not 100% sure on how this could be implemented but i would add a new damagetype (lets call it "MindControl") for the projectile that turns enemies friendly.
Then you need to edit monster actors so that they have a custom pain state (Pain.MindControl), and when the monster enters this state A_ChangeFlag with flagname "FRIENDLY" gets called.
You could also add custom painchances for all monsters, so that larger monsters are harder to "mindcontrol" and smaller ones are easier.

Could you post the new AR's code, so i could try looking for a way to fix it?
Most of the AR code has remained relatively the same.

Code: Select all


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

ACTOR Magazine : Ammo
{
	Inventory.Amount 100
	Inventory.MaxAmount 100
	+IGNORESKILL
}

States
{
Fire:
			HARA A 0 A_JumpIfInventory("RifleMode", 1, "RifleFire")
			HARA A 0 A_JumpIfInventory("ShotgunMode", 1, "ShotgunFire")
			HARA A 0 A_JumpIfInventory("RocketMode", 1, "RocketFire")
			Goto Ready

RifleFire:
			HARA A 1 A_PlaySound()
			HARA A 1 A_FireProjectile()
			HARA A 1 A_TakeInventory("Magazine", 1)
			HARA A 1 A_Refire
			HARA A 1 A_JumpIfInventory("Magazine", 0, "Reload")
			Goto Ready

ShotgunFire:
			HARA A 10 A_PlaySound()
			HARA AAAAAAA 0 A_FireProjectile()
			HARA A 1 A_TakeInventory("Magazine", 10)
			HARA A 1 A_JumpIfInventory("Magazine", 0, "Reload")
			Goto Ready

RocketFire:
			HARA A 20 A_PlaySound()
			HARA A 0 A_FireProjectile()
			HARA A 1 A_TakeInventory("Magazine", 20)
			HARA A 1 A_JumpIfInventory("Magazine", 0, "Reload")
			Goto Ready

Reload:
			HARA A 1 A_GiveInventory("Magazine", 100)
			Goto Ready

AltFire: //This swaps the modes
			HARA A 1 ACS_NamedExecute("Cycler", 0, 0, 0, 0)
			TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO, 50.0)
			Goto Ready
}
The cycler code has remained the same, see above in the beginning post.

Regarding the non-lethal weapon, the weapon would essentially damage them as normal, like any other weapon, but instead of dying, enemies would become player friendly.
User avatar
TensorMatrix
Posts: 41
Joined: Wed Mar 29, 2017 7:05 am

Re: DECORATE Weapon Questions II

Post by TensorMatrix »

I think i got it, i'll post the whole code i wrote so you'll want check and adjust things to your liking:

Code: Select all

ACTOR AR : Weapon
{
	Weapon.AmmoUse1 1
	Weapon.Ammotype1 "Magazine"
States
{
Ready:
	HARA A 1 A_WeaponReady
	Loop
Deselect:
	HARA A 1 A_Lower
	TNT1 AA 0 A_Lower
	Loop
Select:
	HARA A 1 A_Raise
	TNT1 AA 0 A_Raise
	Loop
Fire:
	HARA A 0 A_JumpIfInventory("RifleMode", 1, "RifleFire")
	HARA A 0 A_JumpIfInventory("ShotgunMode", 1, "ShotgunFire")
	HARA A 0 A_JumpIfInventory("RocketMode", 1, "RocketFire")
	TNT1 A 0 A_GiveInventory("RifleMode", 1) //i added this incase player doesn't have "RifleMode", comment it out if it causes issues
	Goto Ready	
RifleFire:
	HARA A 0 
	HARA A 1 A_PlaySound()
	HARA A 1 A_FireProjectile("Rocket") //i used Rocket as an placeholder, you probably want swap it out
//	HARA A 1 A_TakeInventory("Magazine", 1) //since the weapon has Ammouse property- so lets not use this
	HARA A 1 A_JumpIfNoAmmo("Reload") //always use A_JumpIfNoAmmo when you run out of ammo, not A_JumpIfInventory
	HARA A 1 A_Refire
	Goto Ready
ShotgunFire:
	TNT1 A 0 A_JumpIf(CountInv(Magazine) <=9, "Reload") //use A_JumpIf to check for ammo, if less than 10 -> reload
	HARA A 10 A_PlaySound()
	HARA AAAAAAA 0 A_FireProjectile("Rocket", random(-5, 5), 0) //ammouse for this line set to 0 because we will...
	HARA A 1 A_TakeInventory("Magazine", 10) //...use A_TakeInventory to choose how much ammo it will use
	Goto Ready
RocketFire:
	TNT1 A 0 A_JumpIf(CountInv(Magazine) <=19, "Reload") //same as the above, just different values
	HARA A 20 A_PlaySound()
	HARA A 0 A_FireProjectile("Rocket", 0, 0)
	HARA A 1 A_TakeInventory("Magazine", 20)
	Goto Ready
Reload:
	HARA A 20 //added some delay to see the reload
	TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO)
	HARA A 1 A_GiveInventory("Magazine", 100)
	Goto Ready
AltFire: //This swaps the modes
	HARA A 1	//i converted this to decorate so no ACS needed!
	TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO)
	HARA A 0 A_JumpIfInventory("RifleMode", 1, "SwapToShotgun")
	HARA A 0 A_JumpIfInventory("ShotgunMode", 1, "SwapToRocket")
	HARA A 0 A_JumpIfInventory("RocketMode", 1, "SwapToRifle")
	Goto Ready
SwapToRifle:
	TNT1 A 0 A_Print("Rifle mode!")
	TNT1 A 0 A_TakeInventory("RocketMode", 1)
	TNT1 A 0 A_GiveInventory("RifleMode", 1)
	HARA A 10
	Goto Ready
SwapToShotgun:
	TNT1 A 0 A_Print("Shotgun mode!")
	TNT1 A 0 A_TakeInventory("RifleMode", 1)
	TNT1 A 0 A_GiveInventory("ShotgunMode", 1)
	HARA A 10
	Goto Ready
SwapToRocket:
	TNT1 A 0 A_Print("Rocket mode!")
	TNT1 A 0 A_TakeInventory("ShotgunMode", 1)
	TNT1 A 0 A_GiveInventory("RocketMode", 1)
	HARA A 10
	Goto Ready
Spawn:
	PIST A -1
	Stop
}
}
User avatar
Exosphere
Posts: 168
Joined: Sun Jun 11, 2017 11:42 am
Location: New England, US

Re: DECORATE Weapon Questions II

Post by Exosphere »

TensorMatrix wrote:I think i got it, i'll post the whole code i wrote so you'll want check and adjust things to your liking:

Code: Select all

ACTOR AR : Weapon
{
	Weapon.AmmoUse1 1
	Weapon.Ammotype1 "Magazine"
States
{
Ready:
	HARA A 1 A_WeaponReady
	Loop
Deselect:
	HARA A 1 A_Lower
	TNT1 AA 0 A_Lower
	Loop
Select:
	HARA A 1 A_Raise
	TNT1 AA 0 A_Raise
	Loop
Fire:
	HARA A 0 A_JumpIfInventory("RifleMode", 1, "RifleFire")
	HARA A 0 A_JumpIfInventory("ShotgunMode", 1, "ShotgunFire")
	HARA A 0 A_JumpIfInventory("RocketMode", 1, "RocketFire")
	TNT1 A 0 A_GiveInventory("RifleMode", 1) //i added this incase player doesn't have "RifleMode", comment it out if it causes issues
	Goto Ready	
RifleFire:
	HARA A 0 
	HARA A 1 A_PlaySound()
	HARA A 1 A_FireProjectile("Rocket") //i used Rocket as an placeholder, you probably want swap it out
//	HARA A 1 A_TakeInventory("Magazine", 1) //since the weapon has Ammouse property- so lets not use this
	HARA A 1 A_JumpIfNoAmmo("Reload") //always use A_JumpIfNoAmmo when you run out of ammo, not A_JumpIfInventory
	HARA A 1 A_Refire
	Goto Ready
ShotgunFire:
	TNT1 A 0 A_JumpIf(CountInv(Magazine) <=9, "Reload") //use A_JumpIf to check for ammo, if less than 10 -> reload
	HARA A 10 A_PlaySound()
	HARA AAAAAAA 0 A_FireProjectile("Rocket", random(-5, 5), 0) //ammouse for this line set to 0 because we will...
	HARA A 1 A_TakeInventory("Magazine", 10) //...use A_TakeInventory to choose how much ammo it will use
	Goto Ready
RocketFire:
	TNT1 A 0 A_JumpIf(CountInv(Magazine) <=19, "Reload") //same as the above, just different values
	HARA A 20 A_PlaySound()
	HARA A 0 A_FireProjectile("Rocket", 0, 0)
	HARA A 1 A_TakeInventory("Magazine", 20)
	Goto Ready
Reload:
	HARA A 20 //added some delay to see the reload
	TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO)
	HARA A 1 A_GiveInventory("Magazine", 100)
	Goto Ready
AltFire: //This swaps the modes
	HARA A 1	//i converted this to decorate so no ACS needed!
	TNT1 A 0 A_PlaySound("weapons/shotgr", CHAN_AUTO)
	HARA A 0 A_JumpIfInventory("RifleMode", 1, "SwapToShotgun")
	HARA A 0 A_JumpIfInventory("ShotgunMode", 1, "SwapToRocket")
	HARA A 0 A_JumpIfInventory("RocketMode", 1, "SwapToRifle")
	Goto Ready
SwapToRifle:
	TNT1 A 0 A_Print("Rifle mode!")
	TNT1 A 0 A_TakeInventory("RocketMode", 1)
	TNT1 A 0 A_GiveInventory("RifleMode", 1)
	HARA A 10
	Goto Ready
SwapToShotgun:
	TNT1 A 0 A_Print("Shotgun mode!")
	TNT1 A 0 A_TakeInventory("RifleMode", 1)
	TNT1 A 0 A_GiveInventory("ShotgunMode", 1)
	HARA A 10
	Goto Ready
SwapToRocket:
	TNT1 A 0 A_Print("Rocket mode!")
	TNT1 A 0 A_TakeInventory("ShotgunMode", 1)
	TNT1 A 0 A_GiveInventory("RocketMode", 1)
	HARA A 10
	Goto Ready
Spawn:
	PIST A -1
	Stop
}
}
That did it! Thank you so much for helping me with this!

Return to “Scripting”