Raised This Month: $ Target: $400
 0% 

how can i know when player stops presssing a button?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shlomi
Junior Member
Join Date: Oct 2013
Old 08-07-2014 , 11:40   how can i know when player stops presssing a button?
Reply With Quote #1

lets say i want to make a specific command, that does something until the player stops pressing the button.
how can i do that?
( i'm not talking about commands like JUMP, DUCK, ATTACK, and all that, i know i can catch that with RegisterHam, but i want to make a command of my own that the player will bind and when he stops pressing the button the action will stop. )
i tried to do something like that:
Code:
public plugin_init( ) {
	register_clcmd( "+command", "DoStuff" );
	register_clcmd( "-command", "Stop" );
}
but it seems to not work.
help?
Shlomi is offline
Decak
Senior Member
Join Date: Sep 2012
Old 08-07-2014 , 15:22   Re: how can i know when player stops presssing a button?
Reply With Quote #2

When player press E he gets +2 hp example:

Code:
#include <amxmodx>

public plugin_init() {
  register_plugin(...)
  register_forward(FM_PlayerPrethink, "prethink")
}

public prethink(id) {
  new button = pev(id, pev_button)
  if(button == IN_USE) {
  set_user_health(id, get_user_health(id)+2)
}
  return PLUGIN_CONTINUE
}

Last edited by Decak; 08-07-2014 at 15:23.
Decak is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-07-2014 , 15:33   Re: how can i know when player stops presssing a button?
Reply With Quote #3

PHP Code:
(button == IN_USE
->
PHP Code:
(button IN_USE
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-07-2014 , 18:16   Re: how can i know when player stops presssing a button?
Reply With Quote #4

Please don't post code that you don't know how it works. Also, prethink is not what you would want to use here. You would want to use cmdstart if you want to use the "USE" button.

IIRC, it is possible to use +/- commands but I can't remember how to implement then. You should search around because I know there are some topics about it.
__________________

Last edited by fysiks; 08-07-2014 at 18:19.
fysiks is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-07-2014 , 20:52   Re: how can i know when player stops presssing a button?
Reply With Quote #5

It works exactly the way he's doing it, hooking +command and -command.
Backstabnoob is offline
Shlomi
Junior Member
Join Date: Oct 2013
Old 08-08-2014 , 08:45   Re: how can i know when player stops presssing a button?
Reply With Quote #6

Quote:
Originally Posted by Decak View Post
When player press E he gets +2 hp example:

Code:
#include <amxmodx>

public plugin_init() {
  register_plugin(...)
  register_forward(FM_PlayerPrethink, "prethink")
}

public prethink(id) {
  new button = pev(id, pev_button)
  if(button == IN_USE) {
  set_user_health(id, get_user_health(id)+2)
}
  return PLUGIN_CONTINUE
}
Quote:
Originally Posted by Flick3rR View Post
PHP Code:
(button == IN_USE
->
PHP Code:
(button IN_USE
i know that,
i was talking about making my own command.
Quote:
Originally Posted by Backstabnoob View Post
It works exactly the way he's doing it, hooking +command and -command.
but it seems like this command isn't sent to the server.
Shlomi is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 08-08-2014 , 08:54   Re: how can i know when player stops presssing a button?
Reply With Quote #7

Quote:
Originally Posted by Shlomi View Post
but it seems like this command isn't sent to the server.
It should be fine. Post the code your using.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Reply


Thread Tools
Display Modes

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 13:04.


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