Jump to content

Bindkey timer


gerlachmax123

Recommended Posts

Posted
function bindKeys() 
    if isfeuerwehr ( player ) then 
        bindKey(source, "lctrl", "down", "loeschen") 
    end 
end 
addEventHandler("onPlayerJoin", root, bindKeys) 

How i can change it, that you must press lctrl 5 seconds?

Posted

Try this

  
function bindKeys() 
    if isfeuerwehr ( source ) then 
        bindKey(source, "lctrl", "down", loeschen) 
    end 
end  
addEventHandler("onPlayerJoin", getRootElement(), bindKeys) 

Posted
what do u mean 5seconds? like hold it down for 5 seconds?

yes

No you dont want to say this I think because of you are making a rocket script for race? And when car shots rocket you want it to wait 5 second?

Posted
what do u mean 5seconds? like hold it down for 5 seconds?

yes

get when a player presses down the key.

then output to chat that he needs to hold the key for 5seconds.

after that, setTimer for 5 seconds, and if the player lets go off the key before timer runs out, cancel the timer and output it to the player

Posted
what do u mean 5seconds? like hold it down for 5 seconds?

yes

No you dont want to say this I think because of you are making a rocket script for race? And when car shots rocket you want it to wait 5 second?

I want to start a function after i hold the button 5 seconds :)

Posted
what do u mean 5seconds? like hold it down for 5 seconds?

yes

get when a player presses down the key.

then output to chat that he needs to hold the key for 5seconds.

after that, setTimer for 5 seconds, and if the player lets go off the key before timer runs out, cancel the timer and output it to the player

Still wondering why would you use timers for that..

Posted

another way;

client:

press = 0 
function loeschen() 
    if getKeyState("lctrl") then 
            addEventHandler ( "onClientRender", root, zaa) 
    end 
end 
bindKey("lctrl", "down", loeschen) 
function zaa() 
    press = press + 1 
    if press == 5000 then 
        triggerServerEvent ( "doMyFunction", getLocalPlayer() ) 
        press = 0 
    end  
end 

server:

function greetingHandler ( ) 
    -- your code goes here 
end 
addEvent( "doMyFunction", true ) 
addEventHandler( "doMyFunction", getRootElement(), greetingHandler ) 

Posted

No.. That won't work properly.

Use bindKey and getTickCount:

local ticks = {} 
  
function BindKeyToPlayer() 
    if ( eventName == "onPlayerJoin" ) then 
        bindKey ( source, "lctrl", "both", Loeschen ); 
    else 
        for index, value in ipairs ( getElementsByType "player" ) do 
            bindKey ( value, "lctrl", "both", Loeschen ); 
        end 
    end 
end 
addEventHandler ( "onPlayerJoin", root, BindKeyToPlayer ); 
addEventHandler ( "onResourceStart", root, BindKeyToPlayer ); 
  
function Loeschen ( _player, _key, _state ) 
    if ( _state == "up" ) then 
        if ( ticks[_player] ) then 
            local newTick = getTickCount(); 
            if ( ( ticks[_player] - newTick ) < 5000 ) then 
                ticks[_player] = false; 
            end 
        end 
    elseif ( _state == "down" ) then 
        ticks[_player] = getTickCount(); 
        while ( true ) do 
            local newTick = getTickCount(); 
            if ( ( ticks[_player] - newTick ) == 5000 ) then 
                --put your code here 
                break 
            end 
        end 
    end 
end 

I'm not sure if there is any error in my code, I didn't debug it because I don't have MTA San Andreas installed.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...