Jump to content

afk killer for race


kevin11

Recommended Posts

whats wrong with this:S i get a error with says

bad argument @ eventhandler line 35 :S i tried some stuff out but didnt work :P

function funcInput ( key, keyState )
 
afkTime =45000*15
if ( keyState == "up" ) then
setTimer(afkgo,afkTime,1)
end
 
if ( keyState == "down" ) then
     afktimer = getTimers ( afkTime)
for timerKey, timerafk in ipairs(afktimer) do
killTimer ( timerafk )
end
end
 
end
 
function afkgo()
afkTime =45000*15
     afktimer = getTimers ( afkTime)
for timerKey, timerafk in ipairs(afktimer) do
killTimer ( timerafk )
end
outputChatBox ( "afk detector destroyed several cars" )
end
 
 
function bindTheKeys ()
outputChatBox("jupp")
bindKey ( "w", "down", funcInput )
bindKey ( "a", "up", funcInput )
bindKey ( "s ", "down", funcInput )
bindKey ( "d ", "up", funcInput )
 
end
addEventHandler( "onPlayerSpawn", getLocalPlayer, bindTheKeys )

Link to comment
whats wrong with this:S i get a error with says

bad argument @ eventhandler line 35 :S i tried some stuff out but didnt work :P

Err, you did getLocalPlayer, but its not finished off. Its getLocalPlayer().

Plus, I think its better you use getRootElement:

function funcInput ( key, keyState )
 
afkTime =45000*15
if ( keyState == "up" ) then
setTimer(afkgo,afkTime,1)
end
 
if ( keyState == "down" ) then
     afktimer = getTimers ( afkTime)
for timerKey, timerafk in ipairs(afktimer) do
killTimer ( timerafk )
end
end
 
end
 
function afkgo()
afkTime =45000*15
     afktimer = getTimers ( afkTime)
for timerKey, timerafk in ipairs(afktimer) do
killTimer ( timerafk )
end
outputChatBox ( "afk detector destroyed several cars" )
end
 
 
function bindTheKeys ()
outputChatBox("jupp")
bindKey ( "w", "down", funcInput )
bindKey ( "a", "up", funcInput )
bindKey ( "s ", "down", funcInput )
bindKey ( "d ", "up", funcInput )
 
end
addEventHandler( "onPlayerSpawn", getRootElement(), bindTheKeys )

Link to comment
whats wrong with this:S i get a error with says

bad argument @ eventhandler line 35 :S i tried some stuff out but didnt work :P

Err, you did getLocalPlayer, but its not finished off. Its getLocalPlayer().

Plus, I think its better you use getRootElement:

function funcInput ( key, keyState )
 
afkTime =45000*15
if ( keyState == "up" ) then
setTimer(afkgo,afkTime,1)
end
 
if ( keyState == "down" ) then
     afktimer = getTimers ( afkTime)
for timerKey, timerafk in ipairs(afktimer) do
killTimer ( timerafk )
end
end
 
end
 
function afkgo()
afkTime =45000*15
     afktimer = getTimers ( afkTime)
for timerKey, timerafk in ipairs(afktimer) do
killTimer ( timerafk )
end
outputChatBox ( "afk detector destroyed several cars" )
end
 
 
function bindTheKeys ()
outputChatBox("jupp")
bindKey ( "w", "down", funcInput )
bindKey ( "a", "up", funcInput )
bindKey ( "s ", "down", funcInput )
bindKey ( "d ", "up", funcInput )
 
end
addEventHandler( "onPlayerSpawn", getRootElement(), bindTheKeys )

not working and it gives no errors :S maybe there is something wrong with bindkeys

im gonna try something if it doesn t work i post it here

Link to comment

I see you bindthe keys WSAD, but (i think) there are players (like me xD) which use the arrows, in case of WSAD.

The MTA wiki says:

key: The key or control you wish to bind to the command. See key names for a list of possible keys and control names for a list of possible controls.

So you can use "vehicle_left" in case of "a", "accelerate" in case of "w"

this will work vor everybody :mrgreen:

Btw, if this is client-side, you better can use onClientResourceStart, not onPlayerSpawn, then you don't have to remove the handler if the player is wasted :']

Link to comment
I see you bindthe keys WSAD, but (i think) there are players (like me xD) which use the arrows, in case of WSAD.

The MTA wiki says:

key: The key or control you wish to bind to the command. See key names for a list of possible keys and control names for a list of possible controls.

So you can use "vehicle_left" in case of "a", "accelerate" in case of "w"

this will work vor everybody :mrgreen:

Btw, if this is client-side, you better can use onClientResourceStart, not onPlayerSpawn, then you don't have to remove the handler if the player is wasted :']

ooh i didnt think of that

Link to comment

ok i made a new one and it doesnt give errors but still no succes

afkTimer = 30000
 
function funcInput ( key, keyState )
if ( keyState == "up" ) then
if not isTimer(afktimer) then
     afktimer = setTimer(function() outputChatBox("afk") end,afkTime,1)
end
else
killTimer ( afktimer )
end
end
 
function bindTheKeys ()
bindKey ( "w", "both", funcInput )
bindKey ( "a ", "both", funcInput )
bindKey ( "s", "both", funcInput )
bindKey ( "d", "both", funcInput )
bindKey ( "arrow_l", "both", funcInput )
bindKey ( "arrow_r", "both", funcInput )
bindKey ( "arrow_u", "both", funcInput )
bindKey ( "arrow_d", "both", funcInput )
end
 
addEventHandler("onClientResourceStart",getRootElement(),bindTheKeys)

Link to comment

in line 6 you use afkTime, which does not exist.

but wait there is more, i will now teach you to find problems like this!

afkTimer = 30000
 
function funcInput ( key, keyState )
outputDebugString("key state change")
if ( keyState == "up" ) then
outputDebugString("state up")
if not isTimer(afktimer) then
outputDebugString("no timer existing")
     afktimer = setTimer(function() outputChatBox("afk") end,afkTime,1)
outputDebugString(tostring(afktimer))
end
else
killTimer ( afktimer )
end
end
 
function bindTheKeys ()
outputDebugString("resoruce start")
 
bindKey ( "w", "both", funcInput )
bindKey ( "a ", "both", funcInput )
bindKey ( "s", "both", funcInput )
bindKey ( "d", "both", funcInput )
bindKey ( "arrow_l", "both", funcInput )
bindKey ( "arrow_r", "both", funcInput )
bindKey ( "arrow_u", "both", funcInput )
bindKey ( "arrow_d", "both", funcInput )
end
 
addEventHandler("onClientResourceStart",getRootElement(),bindTheKeys)

see all those debug string outputs? they help you find problems. in this case you would see the following when testing:

resource start
key state change
bad argument @killTimer
key state change
state up
no timer existing
false

false? oh, seems like setTimer had some problems. now you should have no problem finding the problem, you use a afkTime variable, but you never define it, all you have is a afkTimer variable. voilà, problem found.

i'll also fix some other problems with your script

afkTime = 30000
 
function funcInput ( key, keyState )
if ( keyState == "up" ) then
if not isTimer(afktimer) then
     afktimer = setTimer(function() outputChatBox("afk") end,afkTime,1)
end
else
if isTimer( afktimer) then -- only try to kill the timer if there actually is a timer
killTimer ( afktimer )
end
end
end
 
function bindTheKeys ()
bindKey ( "w", "both", funcInput )
bindKey ( "a ", "both", funcInput )
bindKey ( "s", "both", funcInput )
bindKey ( "d", "both", funcInput )
bindKey ( "arrow_l", "both", funcInput )
bindKey ( "arrow_r", "both", funcInput )
bindKey ( "arrow_u", "both", funcInput )
bindKey ( "arrow_d", "both", funcInput )
end
 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),bindTheKeys) -- only trigger for the start of this resource

Link to comment
  • 1 month later...

You deserve a warning, my friend.

First of all, WHY are you TRIPLEposting, just because no one is answering you after some hours?

If you want his script so badly (I think that's what you want), then send him a PM.

I would really like to see a warning system to this forum.

Link to comment

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...