AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect +USE key (https://forums.alliedmods.net/showthread.php?t=63016)

travo 11-09-2007 19:04

Detect +USE key
 
is there a way to detect if the +USE "e" key is press in the plugin_init()?

what i want to do is, have a function called if anyone press the use key. Is there are way to do this in the init with an event or do i have to do it through client_PreThink?

It is only used to trigger my function so i dont need to know if its held and it isnt going to be pressed over and over, so i dont want it to be check excessively.

thanks

remix.cc 11-10-2007 05:03

Re: Detect +USE key
 
PHP Code:

get_user_button(id)&IN_USE {
        
//code
    


maybe this will help...

Alka 11-10-2007 05:39

Re: Detect +USE key
 
plugin_init() is called when the plugin is initiallyzed, so no players on server then ! lol...

Orangutanz 11-10-2007 09:58

Re: Detect +USE key
 
Quote:

Originally Posted by travo (Post 551274)
is there a way to detect if the +USE "e" key is press in the plugin_init()?

what i want to do is, have a function called if anyone press the use key. Is there are way to do this in the init with an event or do i have to do it through client_PreThink?

It is only used to trigger my function so i dont need to know if its held and it isnt going to be pressed over and over, so i dont want it to be check excessively.

thanks

You need to hook:
register_forward( FM_CmdStart, "CmdStart" )
Code:
public CmdStart( const id, const uc_handle, random_seed ) {     if ( !is_user_alive( id ) )         return FMRES_IGNORED     static buttons     buttons = get_uc( uc_handle, UC_Buttons )     if ( buttons & IN_USE )         // Do something here         buttons &= ~IN_USE // Block them from using perhaps?     set_uc( uc_handle, UC_Buttons, buttons ) // Update buttons then supercede     return FMRES_SUPERCEDE }
The above method activates when a user actually presses a button and other things.

travo 11-10-2007 11:58

Re: Detect +USE key
 
ohhh, thanks Orangutanz, exactly what i needed

Styles 11-10-2007 18:43

Re: Detect +USE key
 
k now, big question
FM_PreThink Vs. FM_CmdStart

Whats the diff? You can use both right? But when does FM_CmdStart get called compaired to PreThink ( All the time before you do something )

Alka 11-10-2007 18:56

Re: Detect +USE key
 
Fm_CmdStart is called when a command is issued by player.
PreThink is called on every player frame, that means MANY times per second.

Code:

UserCmd Constants

 // Interpolation time on client
        UC_LerpMsec,                // short
        // Duration in ms of command
        UC_Msec,                // byte
        // Command view angles
        UC_ViewAngles,                // float array[3]
       
        // Intended velocities
        // Forward velocity
        UC_ForwardMove,                // float
        // Sideways velocity
        UC_SideMove,                // float
        // Upward velocity
        UC_UpMove,                // float
        // Light level at spot where we are standing
        UC_LightLevel,                // byte
        // Attack buttons
        UC_Buttons,                // unsigned short
        // Impulse command issued
        UC_Impulse,                // byte
        // Current weapon id
        UC_WeaponSelect,        // byte
       
        // Experimental player impact stuff
        UC_ImpactIndex,                // int
        UC_ImpactPosition        // float array[3]


Styles 11-10-2007 19:14

Re: Detect +USE key
 
wow so my shove mod uses bad practices.. I should update this to FM_CmdStart

Thanks

PM 11-11-2007 05:21

Re: Detect +USE key
 
Quote:

Originally Posted by styles (Post 551550)
wow so my shove mod uses bad practices.. I should update this to FM_CmdStart

Thanks

Historically, it's been good practice back when people first used the buttons entvar because a FM_CmdStart forward didn't even exist then. :)

Alka 11-11-2007 05:27

Re: Detect +USE key
 
Quote:

Originally Posted by PM (Post 551666)
Historically, it's been good practice back when people first used the buttons entvar because a FM_CmdStart forward didn't even exist then. :)

o.O, prehistoric era! hi PM :-)


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

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