do keep a key pressed?

Started by Luis_Labarca, Oct 31, 2016, 05:11 AM

Previous topic - Next topic

Luis_Labarca

is there any way of knowing if any player holding a key pressed? for example that I keep pressed the key h for 30 seconds and tell me a message? If you can or not?

and if you can with this function I could tell as works is that put
function GUI::KeyPressed()
{

}
and I get nothing

Thanks already ;)
My server RP
IP: 51.222.28.159:8194

Thijn

Untested, but should give an idea.

g_Time_Key_Pressed <- array(100, 0);

function onScriptLoad()
{
enter <- BindKey( true, 0x0D, 0, 0 );  // The Key Code of enter is 0x0D . we will use bindkey function to set the key. And it is required.
}

function onKeyDown( player, key )
{
if ( key == enter )
{
g_Time_Key_Pressed[ player.ID ] = time();
}
}
function onKeyUp( player, key )
{
    if ( key == enter )
    {
        if ( g_Time_Key_Pressed[ player.ID ] != 0 && (time() - g_Time_Key_Pressed[ player.ID ]) >= 30 )
        {
        // Do something funky
        } else {
        // Didn't hold for 30 seconds.
        }
    }
}

Luis_Labarca

Quote from: Thijn on Oct 31, 2016, 07:04 AMUntested, but should give an idea.
:Dgreat friend thank you ;) ;D
My server RP
IP: 51.222.28.159:8194