Double Mouse Tap Script

Hello. I need help in making a simple script that would recognize if the player has double tapped the mouse or not. If the player double tapped the mouse ( you know, double click - time between taps less than 0.2 ), then do something. Thanks

// This is inside a think function, clientside.


 if input.IsMouseDown (MOUSE_LEFT) then

                        if not doubletap then doubletap = false end
              
		      if "SomeDoubleTapFunctionThatReturnsTrueorFalse()" then
                            doubletap = true
                       else
                            doubletap = false
                       end

			if doubletap == true then
				local traceinfo = { }
				traceinfo.x =  MouseWorld().x
				traceinfo.y =  MouseWorld().y
				traceinfo.z =  MouseWorld().z
				RunConsoleCommand ("SetMovingToCoords",traceinfo.x,traceinfo.y,traceinfo.z)
			end
			
		end 

You don’t know much lua do you?

	        if 'DoubleTap()' then

That makes no sense at all. First you made it a string by adding quotations, but on top of that was DoubleTap even a function at all?

There is this function but its only if you are using GUI, which I really can’t tell if you are.

That, my friend is just an example so you know what to do.

I’m not using GUI.

Then maybe this belongs in requests but I’ll help you out anyways.

Doesn’t work. Holding the mouse button counts as numerous double-presses

Try this:


function input.IsMouseDown(mousebutton)
	if mousebutton == MOUSE_LEFT then
		if not LastRun then LastRun = 30 end
		if LastRun < CurTime() + 3 then 
			doubletap = true
			// Is double tap
		end
		if LastRun < CurTime() + 0.2 then
			// It's been held down
			doubletap = false
		end
		
		if doubletap == true then
			local traceinfo = { }
			traceinfo.x =  MouseWorld().x
			traceinfo.y =  MouseWorld().y
			traceinfo.z =  MouseWorld().z
			RunConsoleCommand ("SetMovingToCoords",traceinfo.x,traceinfo.y)
		end
	end
end


Edit: Oh yeah, input normally needs to be called in a think function. Forgot about that xD

What I am doing is probably overriding the function… don’t have the time to test it though

Forgot a ‘then’ on line 2, but other than that it should do the trick. :v:

Code used : http://pastebin.com/d376d1936 // Returning false. I am calling this function from a think function, clientside.

EDIT: You can close the topic, thanks for the help anyway, but i’ve worked it out >.<.