Raised This Month: $32 Target: $400
 8% 

Solved Detect firing for x seconds?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sekac
Senior Member
Join Date: Nov 2016
Old 05-12-2018 , 13:37   Detect firing for x seconds?
Reply With Quote #1

How can I call a function after a user has been firing from a gun for more than 2 seconds? The timer should reset when the player lets go of mouse 1.

Last edited by sekac; 05-12-2018 at 16:22.
sekac is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-12-2018 , 15:15   Re: Detect firing for x seconds?
Reply With Quote #2

Probably need to detect the IN_ATTACK button and calculate how long it is active. If more than 2 seconds, call your function. There are several threads around here that show how to check when IN_ATTACK is pressed and released.
__________________
fysiks is offline
sekac
Senior Member
Join Date: Nov 2016
Old 05-12-2018 , 15:19   Re: Detect firing for x seconds?
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Probably need to detect the IN_ATTACK button and calculate how long it is active. If more than 2 seconds, call your function. There are several threads around here that show how to check when IN_ATTACK is pressed and released.
I think I will set a task when a player starts holding IN_ATTACK and remove the task when he releases it. That way I don't have to calculate how long the user has been holding the attack key.
sekac is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-12-2018 , 15:23   Re: Detect firing for x seconds?
Reply With Quote #4

Do you want it to continually call your function after the user has been holding the key for longer than 2 seconds, or only call it once, then repeat the whole process after the user releases the button and starts holding it again?
__________________

Last edited by klippy; 05-12-2018 at 15:24.
klippy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-12-2018 , 15:49   Re: Detect firing for x seconds?
Reply With Quote #5

Hook cmdstart check if user pressing attack and its old button, then execute the function you wanted depends on the gametime.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
sekac
Senior Member
Join Date: Nov 2016
Old 05-12-2018 , 16:22   Re: Detect firing for x seconds?
Reply With Quote #6

Quote:
Originally Posted by KliPPy View Post
Do you want it to continually call your function after the user has been holding the key for longer than 2 seconds, or only call it once, then repeat the whole process after the user releases the button and starts holding it again?
Just once. Solved.
sekac is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-12-2018 , 17:43   Re: Detect firing for x seconds?
Reply With Quote #7

Quote:
Originally Posted by sekac View Post
Just once. Solved.
In that case you should post the solution, for the benefit of the community.
__________________
klippy is offline
sekac
Senior Member
Join Date: Nov 2016
Old 05-12-2018 , 18:21   Re: Detect firing for x seconds?
Reply With Quote #8

Quote:
Originally Posted by KliPPy View Post
In that case you should post the solution, for the benefit of the community.
Sure!

PHP Code:
new buttons pev(idpev_button);
new 
oldbuttons pev(idpev_oldbuttons);

if(
buttons IN_ATTACK)
{
    
// Executed when you start holding IN_ATTACK
    
set_task(2.0"function"id); // Here you can set the amount of seconds you need to hold IN_ATTACK
}

if( 
oldbuttons IN_ATTACK && !( buttons IN_ATTACK ) )
{
    
// Executed when you release IN_ATTACK
    
remove_task(id);
    
boolean[id] = false;
}

public function(
id) {
    
boolean[id] = true// This boolean will only be true while holding IN_ATTACK for 2 seconds
}

// Then you can use that boolean in your code. 
Here is what I have done with it: Negev from CS:GO
sekac is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 05-12-2018 , 18:24   Re: Detect firing for x seconds?
Reply With Quote #9

There is abetter way you can use and what forward you used to check the attack?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 05-12-2018 at 18:24.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
sekac
Senior Member
Join Date: Nov 2016
Old 05-12-2018 , 18:35   Re: Detect firing for x seconds?
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
There is abetter way you can use and what forward you used to check the attack?
There probably is but I found this very simple to use. I used FM_PlayerPreThink, probably not the best either.
sekac is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:14.


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