AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how can i know when player stops presssing a button? (https://forums.alliedmods.net/showthread.php?t=245821)

Shlomi 08-07-2014 11:40

how can i know when player stops presssing a button?
 
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?

Decak 08-07-2014 15:22

Re: how can i know when player stops presssing a button?
 
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
}


Flick3rR 08-07-2014 15:33

Re: how can i know when player stops presssing a button?
 
PHP Code:

(button == IN_USE

->
PHP Code:

(button IN_USE


fysiks 08-07-2014 18:16

Re: how can i know when player stops presssing a button?
 
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.

Backstabnoob 08-07-2014 20:52

Re: how can i know when player stops presssing a button?
 
It works exactly the way he's doing it, hooking +command and -command.

Shlomi 08-08-2014 08:45

Re: how can i know when player stops presssing a button?
 
Quote:

Originally Posted by Decak (Post 2180518)
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 (Post 2180528)
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 (Post 2180709)
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.

hornet 08-08-2014 08:54

Re: how can i know when player stops presssing a button?
 
Quote:

Originally Posted by Shlomi (Post 2180949)
but it seems like this command isn't sent to the server.

It should be fine. Post the code your using.


All times are GMT -4. The time now is 13:04.

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