Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
LittleInferno

Help with making reloading for a custom weapon

Recommended Posts

I was making a weapon, and I was going to make it like Hacx's Uzi, where you could fire half your ammunition and it would play a sequence of reloading frames. Or you could fire 2 bullets and it would do the same. How would I make it be able to do that without the gun fire looping or reloading after 4 shots?

Share this post


Link to post

You need a dummy inventory counter. Make a dummy inventory item with a certain maximum amount, like this:

actor dummy : inventory { inventory.maxamount 50 }
Then, each time the weapon shots, use A_GiveInventory to give 1 dummy to the player:
TNT1 A 0 A_GiveInventory("dummy",1)
Also, each time the weapon shots, use A_JumpIfInventory to check whether the player already has full amount of the dummy inventory, and if so, perform a jump to your custom reloading animation:
TNT1 A 0 A_JumpIfInventory("dummy",50,"Reload")
Finally, inside your Reload animation, don't forget to take all dummies from the player, so that the counter will start from 0 again:
TNT1 A 0 A_TakeInventory("dummy",50)
Take all 50 of them - don't worry, the number will never go to negative values. If you try to take more inventory from the player than how much he has, he will end up having 0 of this item.

Share this post


Link to post

Thanks. But apparently while trying to figure out where to implement that code (I'm no smarter than a coconut), I found a seemingly simpler way.

        Fire:
		UZGN B 4 BRIGHT A_FireCGun 
		BRHT A 2 BRIGHT A_FIRECGun 
		UZGN C 3 BRIGHT A_FireCGun 
		BRHT B 2 BRIGHT A_FireCGun
		UZGN A 0 A_ReFire // You know
		Goto Reload //Goes to reloading frames after you are done firing
	Reload:
		UZGN D 6
		UZGN E 6
		UZGN F 6
		UZGN G 6
		UZGN H 6
		Goto Ready
	}
}			
No more hurdles to go through now, Other than a reloading sound to use, better sprite positioning, and maybe a custom firing sound, which all I know how to do.

Also, a YouTube video: https://www.youtube.com/watch?v=mS6ziYtrIIU&feature=youtu.be

Share this post


Link to post

If you actually wanted it that simple, you could have looked at the code of Doom's Plasma Rifle. The "Reload" state is not even needed! :)

I was under an impression that you wanted the gun to automatically reload if the player would keep firing for too long time.

Share this post


Link to post

Haven't played Hacx, eh? Heh.

Fun fact: I take pictures of toy guns to use when I'm making a custom weapon because I have the drawing skills of a quadruple amputee.

Share this post


Link to post
LittleInferno said:

Haven't play Hacx, eh? Heh.

Actually, I did check out HacX 2.0 after reading your original post - and weapon 4 actually behaved exactly as I've assumed in ZDoom, with the counter! That made me assured that I understood what you were talking about, and so I've advised you as I did.

Share this post


Link to post

Oh, you were talking about 2.0's version. I was thinking of 1.2 & below, where you could fire all the bullets you wanted and it would still play reloading frames.

Share this post


Link to post

Well, as I said, that's how Doom's Plasmagun normally works. And technically, every Doom weapon that used A_Refire - any code after A_Refire is basically "Reload" performed when you stop firing.

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
Sign in to follow this  
×