gerlachmax123 Posted February 22, 2013 Posted February 22, 2013 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?
gokalpfirat Posted February 22, 2013 Posted February 22, 2013 Try this function bindKeys() if isfeuerwehr ( source ) then bindKey(source, "lctrl", "down", loeschen) end end addEventHandler("onPlayerJoin", getRootElement(), bindKeys)
gerlachmax123 Posted February 22, 2013 Author Posted February 22, 2013 No, that already works, but i like to press the button "lctrl" 5 seconds and not 1 second...
manve1 Posted February 22, 2013 Posted February 22, 2013 what do u mean 5seconds? like hold it down for 5 seconds?
gokalpfirat Posted February 22, 2013 Posted February 22, 2013 You must write the isfeuerwehr function and loeschen function too.
gerlachmax123 Posted February 22, 2013 Author Posted February 22, 2013 what do u mean 5seconds? like hold it down for 5 seconds? yes
gokalpfirat Posted February 22, 2013 Posted February 22, 2013 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?
manve1 Posted February 22, 2013 Posted February 22, 2013 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
gerlachmax123 Posted February 22, 2013 Author Posted February 22, 2013 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
manve1 Posted February 22, 2013 Posted February 22, 2013 What u do, is u get when a player presses the key, and holds for 5seconds, then u kill the timer and start the function
gerlachmax123 Posted February 22, 2013 Author Posted February 22, 2013 Difficult ^^ Thank you for your help
manve1 Posted February 22, 2013 Posted February 22, 2013 If you know what you're doing, then it shouldn't be that hard. You're Welcome tho
Anderl Posted February 22, 2013 Posted February 22, 2013 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..
Fury Posted February 23, 2013 Posted February 23, 2013 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 )
Anderl Posted February 23, 2013 Posted February 23, 2013 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now