AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Can you detect mouse click time.. (https://forums.alliedmods.net/showthread.php?t=40319)

swobj 06-26-2006 01:45

Can you detect mouse click time..
 
Well the title probably sounds funny, but is there a way to detect how long you hold down your mouse click. For example if your mouse click is "+attack" and you hold it down, is there a way to detect how long you hold the mouse click before you release it and return the value? Thanks much for you help.

v3x 06-26-2006 02:25

Re: Can you detect mouse click time..
 
Moving this to Scripting Help from Support/Help.

Peli 06-26-2006 02:41

Re: Can you detect mouse click time..
 
Maybe... if you started a countdown from the +attack action, but I don't know if there is any action that represents the mouse un-clicking... So I guess not...

Lee 06-26-2006 03:11

Re: Can you detect mouse click time..
 
-attack ;)

v3x 06-26-2006 03:21

Re: Can you detect mouse click time..
 
Well if you want to calculate it in seconds I would do something like this:
Code:
Code:
#include <amxmodx> #include <engine> new g_iSecs[33]; public client_putinserver(id) {     g_iSecs[id] = 0;     if(!task_exists(id))         set_task(1.0 , "count" , id , _ , _ , "b"); } public count(id) {     if(!is_user_alive(id))     {         g_iSecs[id] = 0;         return;     }     if(get_user_button(id) & IN_ATTACK)         g_iSecs[id]++;     else if(!(get_user_button(id) & IN_ATTACK) && g_iSecs[id])     {         client_print(id , print_chat , "* You held the attack button for %d second%s" , g_iSecs[id] , (g_iSecs[id] == 1) ? "" : "s");         g_iSecs[id] = 0;     } }


Hawk552 06-26-2006 08:57

Re: Can you detect mouse click time..
 
Quote:

Originally Posted by v3x
Well if you want to calculate it in seconds I would do something like this:
Code:
Code:
#include <amxmodx> #include <engine> new g_iSecs[33];

public client_putinserver(id) { g_iSecs[id] = 0;

if(!task_exists(id)) set_task(1.0 , "count" , id , _ , _ , "b");
} public count(id) { if(!is_user_alive(id)) { g_iSecs[id] = 0;
return;
} if(get_user_button(id) & IN_ATTACK) g_iSecs[id]++;
else if(!(get_user_button(id) & IN_ATTACK) && g_iSecs[id]) { client_print(id , print_chat , "* You held the attack button for %d second%s" , g_iSecs[id] , (g_iSecs[id] == 1) ? "" : "s");
g_iSecs[id] = 0;
} }




It are being memory leakish, add client_disconnect and remove_task(id)

VEN 06-26-2006 14:37

Re: Can you detect mouse click time..
 
set_task(1.0, ... makes this method potentially not able to detect mouse clicks between "count" function calls.

v3x 06-27-2006 23:54

Re: Can you detect mouse click time..
 
What about looping at 0.1 second intervals then doing secs = time[id] * 10?


All times are GMT -4. The time now is 08:09.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.