Trying to make a Shotgun using A_FireProjectile?

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!)
Post Reply
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Trying to make a Shotgun using A_FireProjectile?

Post by Graaicko »

So I am trying to create a shotgun with a spread using A_FireProjectile. Can't seem how to more than one projectile it fires. My weapoins are using tracer projectiles.

Here is the weapon code:

Code: Select all

ACTOR Spas12 : Weapon replaces Shotgun  5533
{
//$Category Weapons
Tag "SPAS-12"
Weapon.Slotnumber 3
Weapon.Selectionorder 1
Weapon.Ammotype1 "SpasLoaded"
Weapon.Ammotype2 "308Magazine"
Weapon.Ammouse 1
Weapon.Ammouse2 0
Weapon.Ammogive1 0
Weapon.Ammogive2 8
Weapon.BobStyle Smooth
Weapon.BobSpeed 2
Weapon.BobRangeX 0.5
Weapon.BobRangeY 0.7
Weapon.Kickback 115
Obituary "%o was shot by %k's SPAS-12."
Scale 0.4
Decal "BulletChip"
AttackSound "M14FIRE"
Inventory.Pickupmessage "SPAS-12"
Inventory.PickupSound "SPASPU"
+Weapon.Ammo_Optional
+NOAUTOFIRE
+NOEXTREMEDEATH
+COUNTITEM
States
{
Ready:
SPAS B 1 A_WeaponReady(WRF_ALLOWRELOAD)
loop		
Select:
SPAS B 1 Offset (-90,69)
SPAS B 1 Offset (-70,60)
SPAS B 1 Offset (-55,52)
SPAS B 1 Offset (-35,45)
SPAS B 1 Offset (-15,39)
SPAS B 1 Offset (-1,35)
SelectRaise:
SPAS B 1 A_Raise
loop		
Deselect:
SPAS B 1 Offset (-1,35)
SPAS B 1 Offset (-15,39)
SPAS B 1 Offset (-35,45)
SPAS B 1 Offset (-55,52)
SPAS B 1 Offset (-70,60)
SPAS B 1 Offset (-90,69)
SPAS B 1 Offset (-105,89)
SPAS B 1 Offset (-125,102)
SPAS B 1 Offset (-155,108)
SPAS B 1 Offset (-155,150)
DeselectRaise:
SPAS B 0 Offset (-1,0)
SPAS B 1 A_Lower
loop	
Fire:
SPAS B 0 A_JumpIfNoAmmo("Reload")
SPAS C 0 A_Quake(2, 2, 0, 1)
SPAS C 0 A_StartSound("SPASFIRE", CHAN_WEAPON)
SPAS C 2 Bright A_FireProjectile("PelletPracer", FRandom(-0.52, 0.52), true, 0, 0, 7, FRandom(-1, 0.55))
SPAS C 0 A_spawnitemex ("308Casing", 40, 20, 20, random(4,6), random(4,8), random(4,9), 0)
SPAS C 0 A_FireCustomMissile("GunSmokeSpawner",0,0,0,5)
SPAS D 2 Bright A_SetPitch(pitch-0.5)
SPAS E 2 A_SetPitch(pitch-0.25)
SPAS F 2 A_SetPitch(pitch+0.25)
SPAS F 0 A_SetPitch(pitch+0.5)
Goto Ready
Reload:
SPAS B 0 A_JumpIfInventory("SpasLoaded", 8, 2)
SPAS B 0 A_JumpIfInventory("308Magazine", 1, "ReloadWork")
SPAS B 1
Goto Ready
ReloadWork:
SPAS B 1 Offset(0,38) A_PlaySound("M1RELOAD", CHAN_5)
SPAS B 1 Offset(0,44)
SPAS B 1 Offset(0,56)
SPAS B 1 Offset(-2,60)
SPAS B 1 Offset(-4,72)
SPAS B 1 Offset(-7,80)
SPAS B 1 Offset(-10,82)
SPAS B 15 Offset(-11,84)
ReloadLoop:
TNT1 A 0 A_TakeInventory("308Magazine", 1)
TNT1 A 0 A_GiveInventory("SpasLoaded", 1)
TNT1 A 0 A_JumpIfInventory("SpasLoaded", 8, "ReloadFinish")
TNT1 A 0 A_JumpIfInventory("308Magazine", 1, "ReloadLoop")
Goto ReloadFinish
ReloadFinish:
SPAS B 1 Offset(-10,84)
SPAS B 1 Offset(-10,90)
SPAS B 1 Offset(-10,98)
SPAS B 1 Offset(-10,110)
SPAS B 1 Offset(-10,98)
SPAS B 1 Offset(-10,88)
SPAS B 1 Offset(-10,78)
SPAS B 1 Offset(-10,74)
SPAS B 1 Offset(-10,70)
SPAS B 1 Offset(-9,68)
SPAS B 1 Offset(-8,60)
SPAS B 1 Offset(-7,54)
SPAS B 1 Offset(-5,48)
SPAS B 1 Offset(-3,42)
SPAS B 1 Offset(-1,36)
SPAS B 1 Offset(0,32)
Goto Ready
Spawn:
SPAS A -1 
Stop
}
}

ACTOR SpasLoaded : Ammo
{
Inventory.MaxAmount 8
+IGNORESKILL
}
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Trying to make a Shotgun using A_FireProjectile?

Post by wildweasel »

The simple answer for you is to run A_FireProjectile multiple times. The old-school way to do this would be to have a line that looks like this:

Code: Select all

SHOT AAAAAAAA 0 A_FireProjectile("OuchMyButt")
and then add as many A frames to that line as you want there to be pellets in the shot. I'm sure there's a nicer way to do that with anonymous functions and a FOR loop, but it's not something I've experimented with before, so I wouldn't be much help on that one.

Oh, by the way: if you're using the "old-school" method, either make sure your A_FireProjectile line is set to NOT use ammo (through its flags), OR set your weapon's AmmoUse to 0 and have a separate line of code take the ammo manually.
User avatar
Graaicko
Posts: 534
Joined: Tue Jun 17, 2014 11:22 pm
Graphics Processor: nVidia (Legacy GZDoom)

Re: Trying to make a Shotgun using A_FireProjectile?

Post by Graaicko »

wildweasel wrote:Oh, by the way: if you're using the "old-school" method, either make sure your A_FireProjectile line is set to NOT use ammo (through its flags), OR set your weapon's AmmoUse to 0 and have a separate line of code take the ammo manually.
How would I do that? Can't seem to find anything about code taking ammo. :/
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Re: Trying to make a Shotgun using A_FireProjectile?

Post by wildweasel »

Graaicko wrote:
wildweasel wrote:Oh, by the way: if you're using the "old-school" method, either make sure your A_FireProjectile line is set to NOT use ammo (through its flags), OR set your weapon's AmmoUse to 0 and have a separate line of code take the ammo manually.
How would I do that? Can't seem to find anything about code taking ammo. :/
ZDoom Wiki wrote:A_FireProjectile (string missiletype, [angle angle], [bool useammo], [float spawnofs_xy], [int spawnheight], [int flags], [float pitch])
From the ZDoom Wiki page on [wiki]A_FireProjectile[/wiki], emphasis mine. It is the third argument, the one right after its angle. If it's set to 0, the shot does not consume ammo. If it's set to 1, it does, for every occurrence of it on that line.
Post Reply

Return to “Scripting”