Jump to content

How to make a weapon [gun] fire faster than default speed?


HappleAcks

Recommended Posts

Just add a variable in your item class called tickssincefired, and every tick increase it by one, and if it = 4 then fire a bullet and set it to 0. This is basic logic. -_-

The reason you don't do that is because that variable will be the same for every single instance of the Item, making it incompatible in multiplayer for sure, and possibly in single player as well if you have two or more of the item in question.

ย 

@OP Your code is close, but when you right click, you forgot to set the time at which it was fired, meaning that every click will allow it to fire as world time > 0 is always true ;)

ย 

Add this to your right-click method after determining that you should fire a shot:

stack.getTagCompound().setLong("lastShotTime", world.getWorldTime() + delay);
// where 'delay' is an integer equal to the number of ticks you want to delay between shots

ย 

That should now prevent you from spamming right click to fire quickly, while still allowing you to hold right-click and fire continuously while the item is in use.

I hate to necro this, but I recently discovered an issue where if you hold down the fire button, it'll keep on firing until you switch weapons even if you let go of holding down fire.

Link to comment
Share on other sites

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements




×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.