AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   clcmd, and keypress. (https://forums.alliedmods.net/showthread.php?t=57851)

Rolnaaba 07-12-2007 20:52

clcmd, and keypress.
 
how can I register a clcmd and get when it is pressed AND when it is released? I can make people bind the comand, but how will i get when they press AND release that bound key?
Code:
register_clcmd("comand", "handle");   public handle(id) {       //this is when pressed }   //how do i detect release?

Deviance 07-12-2007 20:58

Re: clcmd, and keypress.
 
Code:
register_clcmd("+key", "key_press") register_clcmd("-key", "key_release") public key_press(id) {         // The key is pressed } public key_release(id) {         // The key is released }

Rolnaaba 07-12-2007 21:01

Re: clcmd, and keypress.
 
the engine automatically detects the +/- and acts accordingly?

Deviance 07-12-2007 21:06

Re: clcmd, and keypress.
 
Quote:

Originally Posted by Rolnaaba (Post 502699)
the engine automatically detects the +/- and acts accordingly?

Yes.

draft 07-13-2007 12:14

Re: clcmd, and keypress.
 
Quote:

register_clcmd("+attack", "check_first_shot")
register_clcmd("status", "check_first_shot")
register_clcmd("-attack", "stop_check")


public check_first_shot(player)
{
client_print(0, print_chat, "Test")
}
I've made simple code but when i make a shot or write in console status there is no message "Test".

toazron1 07-13-2007 12:44

Re: clcmd, and keypress.
 
You can not catch duck walk or attack using that type of register, you need to do something like this


This is off the top of my head but you get the idea... (not at my house right now)
Code:


public client_prethink(id) {
        if (get_user_buttons(id) & IN_ATTACK) {
            server_print("ATTACKED")
        }
}


draft 07-13-2007 13:25

Re: clcmd, and keypress.
 
Quote:

Originally Posted by toazron1 (Post 502930)
Code:


public client_prethink(id) {
        if (get_user_buttons(id) & IN_ATTACK) {
            server_print("ATTACKED")
        }
}


Thanks, i got it but can u explain two things in your code?
1) What is client prethink? Is it something that is always executing instead of setting task of function? I've found only one explanation that it is "Forward" and nothing else.
2) IN_ATTACK - what is that?
Sorry, if i'm too silly :|

Rolnaaba 07-13-2007 13:46

Re: clcmd, and keypress.
 
1) client_prethink is a forward (engine?) that is called before every frame.
2) IN_ATTACk is the ID of the button they are pressing, which is +attack.

fakemeta way:
Code:
#include <amxmodx> #include <fakemeta> //... register_forward(FM_PlayerPreThink, "fwdPlayerPreThink"); //... public fwdPlayerPreThink(ent) {     if(pev(id, pev_button) & IN_ATTACK) {         client_print(id, print_chat, "YOUR ATTACKING!!")     } }

draft 07-13-2007 14:21

Re: clcmd, and keypress.
 
Doesn't work. Compiles but i don't see "YOUR ATTACKING!!"

Rolnaaba 07-13-2007 16:23

Re: clcmd, and keypress.
 
try FM_PlayerPostThink, and if that dont work, i guess maybe PostThink and pev_oldbutton or something cant remember....


All times are GMT -4. The time now is 21:29.

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