AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to bind a key to a function (https://forums.alliedmods.net/showthread.php?t=147692)

Pantheon 01-12-2011 13:30

How to bind a key to a function
 
How do you do this?

I want it to be like in SH where you bind keys to power1 etc.

DarkGod 01-12-2011 13:33

Re: How to bind a key to a function
 
Code:
register_clcmd("+bind", "FuncHolding") register_clcmd("-bind", "FuncReleased")

Pantheon 01-12-2011 18:49

Re: How to bind a key to a function
 
Quote:

Originally Posted by DarkGod (Post 1392137)
Code:
register_clcmd("+bind", "FuncHolding") register_clcmd("-bind", "FuncReleased")

Could you explain usage on that command? Ingame and in code.

DarkGod 01-12-2011 20:19

Re: How to bind a key to a function
 
... That's nothing specific.

When you hold down the key you have bound to +bind the function "FuncHolding" is called. When you release the key the function "FuncReleased" is called.

Pantheon 01-12-2011 21:22

Re: How to bind a key to a function
 
Quote:

Originally Posted by DarkGod (Post 1392389)
... That's nothing specific.

When you hold down the key you have bound to +bind the function "FuncHolding" is called. When you release the key the function "FuncReleased" is called.

PHP Code:

#include <amxmodx>

public plugin_init() {
    
register_clcmd("+bind""FuncHolding")
    
register_clcmd("-bind""FuncReleased")
}

public 
FuncHolding() 
    
client_print(0print_chat"Holding down key..")

public 
FuncReleased() 
    
client_print(0print_chat"Key released.."

So in theory, this would work?

Exolent[jNr] 01-12-2011 21:54

Re: How to bind a key to a function
 
Yes. However, that method does not work for detecting existing commands such as +jump or +use.


All times are GMT -4. The time now is 01:56.

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