Jump to content

Telling how long left click is held down


GravityWolf

Recommended Posts

Hello! I'm working on a melee/ranged weapon, but I want it so you only have to use left click, as I am using dual wielding. So I'm going to try to set it up so if you hold down left click for about 1 second and let go, it shoots an entity. (Don't worry, I don't need help with that :P) So here's my code so far to stop the swing:

 

if (weaponAbility == "chakram") {
            	
            	if (player.isSwingInProgress) {
            	
            	player.isSwingInProgress = false;
            
            	}
            	
            }

 

This is in onUpdate, just by the way. So, anyone have any ideas? Thanks!

Link to comment
Share on other sites

Seems a bit... Sketchy.

 

But anyway. What I would do is make a TickHandler for client ( or is it server in this instance? :/ ) that would take a Boolean from the item that is called, something like: isThisItemLeftClickingOrNot. Then do a check in the handler to see if it is, and then add 1 onto a counter. Then, if the counter is over 20 ticks ( I believe that is one second ) wait, or keep adding, until the variable is false again. Then in the else statement, do another check to see if the counter is greater than 20 ( or however many ticks a second is ).

 

Example:

// TickHandler stuff...
// in whatever method it is
if ( player.getHeldItem ().getItem ().itemId == YourMod.YourItem.itemId ) {
    if ( YourMod.YourItem.getIsThisItemLeftClickingOrNot )
        counter++;
    else {
        if ( counter >= 20 ) {
            // RELEASE THE ENTITY! Maybe... This should be server side  Ignore the client side above 
        }
    }
}
// More TickHandler stuff..

 

So yeah.. Something along those lines. You could also make the tickhandler set a Boolean in the item and check it using the left click function to release the entity... I am not sure which is cleaner. I would assume doing it from the TickHandler would be a bit quicker.

 

Hope this helps :D

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

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.