Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • 0
furyweb

Shotgun Weapon with Reload

Question

So going off Gunlabs Tutorial : 

 

http://gunlabs.blogspot.com/2012/06/tutorial-new-ammo-types-and-weapons.html

 

I am trying to create a simple shotgun that fires as normal but when reload is pressed (R) its reloads the weapon like a shotgun does. Ive got all the animations sorted its just not happening for me. Here is my code if anyone can help. Also I may put an alt fire in, but for now the fire and reload would be fine.

 

Shotgun is 7 bullets max loaded. Side note im trying to do the 1 bullet at a time reload so it loops till I get the full 7 bullets loaded.

 

Code:

Actor Shotty : Weapon replaces shotgun
{
	Weapon.SelectionOrder 1900
	Inventory.Pickupmessage "Picked up Shotty!"
	Weapon.AmmoType1 "NewShottyLoaded"
	Weapon.AmmoUse1 1
	Weapon.AmmoGive 0
	Weapon.AmmoType2 "Shell"
	Weapon.AmmoGive2 14
	Weapon.SlotNumber 3
	+Weapon.Ammo_Optional
	States
	{
	Ready:
		HAND A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		Loop
	Deselect:
		HAND A 1 A_Lower
		Loop
	Select:
		HAND A 1 A_Raise
		Loop
	Fire:
		TNT1 A 1 A_JumpIfNoAmmo("Reload")
		TNT1 A 1 A_PlaySound("weapons/shotgun/shoot")
		MPN1 AB 2 bright A_FireBullets (4, 4, -1, 6) 
		MPN1 CDEDC 1
		MPN1 F 8
		MPN1 F 1 A_ReFire  
		Goto Ready
	Reload:
		MPN1 ABCDEF 2
		MPN1 F 0 A_JumpIfInventory("NewShottyLoaded", 14, 2)
		MPN1 F 0 A_JumpIfInventory("ShottyAmmo", 1, "ReloadWork")
		MPN1 F 1 
		Goto Ready
	ReloadWork:
		SGR1 ABCDEF 2 
	ReloadLoop:
		TNT1 A 0 A_TakeInventory("ShottyAmmo", 1)
		TNT1 A 0 A_GiveInventory("NewShottyLoaded", 1) 
		TNT1 A 0 A_JumpIfInventory("NewShottyLoaded", 7, "ReloadFinish")
		TNT1 A 0 A_JumpIfInventory("ShottyAmmo", 1, "ReloadLoop")
		Goto ReloadFinish
	ReloadFinish:
		SGR2 ABC 3
		SGR2 D 2 A_PlaySound("weapons/shotgun/insert")
		SGR2 E 2
		SGR1 FDCBA 2
		Goto Ready
	Spawn:
		SGPU A -1
		Stop
	}
}

ACTOR Action_Reload : CustomInventory
{
    Inventory.Amount 1
    Inventory.MaxAmount 1
    -INVBAR
    States
    {
    Use:
        TNT1 A 0 A_GiveInventory("IsReloading",1)
        Fail
    }
}

ACTOR Action_ReloadCancel : CustomInventory
{
    Inventory.Amount 1
    Inventory.MaxAmount 1
    -INVBAR
    States
    {
    Use:
        TNT1 A 0 A_TakeInventory("IsReloading",1)
        Fail
    }
}

ACTOR IsReloading : Inventory
{
    Inventory.Amount 1
    Inventory.MaxAmount 1
    -INVBAR
}

ACTOR ShottyAmmo : Ammo replaces shells
{
 Inventory.Amount 14
 Inventory.MaxAmount 56
 Ammo.BackpackAmount 14
 Ammo.BackpackMaxAmount 112 
 Inventory.Icon "SHELA0"
 Inventory.PickupMessage "Picked up some Shotty ammo."
 States
 {
 Spawn:
  SHEL A -1
  Stop
 }
}

ACTOR ShottyAmmoSmall : ShottyAmmo
{
 Inventory.Amount 7
 Inventory.PickupMessage "Picked up a bit of Shotty ammo."
 Inventory.PickupSound "Beretta/Drop"
 +DROPPED
 States
 {
 Spawn:
   SHEL A -1
  Stop
 }
}

ACTOR NewShottyLoaded : Ammo
{
 Inventory.MaxAmount 14
 +IGNORESKILL
}

 

Share this post


Link to post

9 answers to this question

Recommended Posts

  • 0
Actor Reloading : Inventory
{
	inventory.maxamount 1
}

ACTOR MyShotgunAmmo : Ammo
{
    Inventory.Amount 7
    Inventory.MaxAmount 7
    Ammo.BackpackAmount 0
    Ammo.BackpackMaxAmount 7
}

ACTOR MyShotgun : Shotgun replaces Shotgun
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoType1 "Shell"
	Weapon.AmmoType2 "MyShotgunAmmo"
	States
	{
	Ready:
		SGUN A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		Loop
	Deselect:
		SGUN A 1 A_Lower
		Loop
	Select:
		SGUN A 1 A_Raise
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"ReloadFinish")
		TNT1 A 0 A_JumpIfInventory("MyShotgunAmmo",1,1)
        Goto NoAmmo
		SGUN B 3 //1st firing frame
		SGUN B 0 A_FireBullets (5.5, 5.5, 7, 5, "BulletPuff")
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_TakeInventory("MyShotgunAmmo",1)
		//more firing frames
		//cocking frames
		SGUN A 4
		Goto Ready
	NoAmmo:
		SGUN A 15 //play empty gun clicking sound or something
		Goto Ready
	Reload:
		TNT1 A 0 A_JumpIfInventory("Shell",1,1)
		Goto Ready
		TNT1 A 0 A_JumpIfInventory("MyShotgunAmmo",7,"Ready")
		SGUN A 8 //ready to reload frames
		TNT1 A 0 A_GiveInventory("Reloading",1)
	ReloadRepeat:
		TNT1 A 0 A_JumpIfInventory("Shell", 1, 1)
		Goto ReloadFinish
		TNT1 A 0 A_JumpIfInventory("MyShotgunAmmo", 7, "ReloadFinish")
		TNT1 A 0 A_WeaponReady
		SGUN A 8 //insert shell frames
		TNT1 A 0 A_TakeInventory("Shell",1)
		SGUN R 4 A_GiveInventory("MyShotgunAmmo",1)
		SGUN A 16
		Loop
	ReloadFinish:
		TNT1 A 0 A_TakeInventory("Reloading",1)
		SGUN A 8 //cocking frames
		Goto Ready
	}
}

 

Share this post


Link to post
  • 0

Oh wow thank you so much, you even included comments (which is a big help for me).

 

Again thank you so much, will give it a crack :D.

Share this post


Link to post
  • 0

K tried it, works pretty much spot and looks amazing, only problem is when I pick the weapon up it wont fire unless I reload it from pick up. Is this meant to be like that, cause I was thinking pick it up either clip full or it start loading up automatic.

Share this post


Link to post
  • 0

I forgot, you have to give the player 7 MyShotgunAmmo, either as a StartItem in the PlayerClass declaration, via ACS in an ENTER script (although that would be called each time a map is loaded, so you'd have to declare a seperate "GotFirsttimeAmmo" item so you only get the 7 ammo once), or in some other way.

Share this post


Link to post
  • 0
12 hours ago, Cherno said:

I forgot, you have to give the player 7 MyShotgunAmmo, either as a StartItem in the PlayerClass declaration, via ACS in an ENTER script (although that would be called each time a map is loaded, so you'd have to declare a seperate "GotFirsttimeAmmo" item so you only get the 7 ammo once), or in some other way.

You might be able to give the 7 MyShotgunAmmo in the Pickup state of the weapon. I can't guarantee it will work because weapons might not have a Pickup state like Inventory items, but it simple enough to be worth a try.

 

EDIT: Or, how about Weapon.AmmoGive2 7 in the code for the weapon?

Edited by Empyre

Share this post


Link to post
  • 0
1 hour ago, Empyre said:

You might be able to give the 7 MyShotgunAmmo in the Pickup state of the weapon. I can't guarantee it will work because weapons might not have a Pickup state like Inventory items, but it simple enough to be worth a try.

 

EDIT: Or, how about Weapon.AmmoGive2 7 in the code for the weapon?

The first solution might work but I'm not sure either if the Weapon class has a Pickup state. It would also mean that a JumpIfInventory condition is needed so the ammo only gets added if not shotgun is yet carried, otherwise the shotgun would magically reload each time another one is picked up, not just the first one. The second solution wouldn't be desirable for the aforementioned reason, at least IMHO.

Share this post


Link to post
  • 0
2 hours ago, Empyre said:

You might be able to give the 7 MyShotgunAmmo in the Pickup state of the weapon. I can't guarantee it will work because weapons might not have a Pickup state like Inventory items, but it simple enough to be worth a try.

 

EDIT: Or, how about Weapon.AmmoGive2 7 in the code for the weapon?

 

Weapon.AmmoGive2 7 works a charm :D. Thank you!

Share this post


Link to post
  • 0
3 hours ago, Cherno said:

The first solution might work but I'm not sure either if the Weapon class has a Pickup state. It would also mean that a JumpIfInventory condition is needed so the ammo only gets added if not shotgun is yet carried, otherwise the shotgun would magically reload each time another one is picked up, not just the first one. The second solution wouldn't be desirable for the aforementioned reason, at least IMHO.

I didn't think of that. I am used to the Weapons Stay flag being on.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×