Jump to content

AFK System


Recommended Posts

So.. I have afk system which previously worked, but now it doesn't working.. Debug says "ERROR: Panel-F7\_client.lua:95: attempt to compare nil with number".. Mistake is in "if getTickCount() - lastaction >= idletime then" , but what I did wrong?

client:

local idletime 
local lastaction 
  
function clientAction() 
    lastaction = getTickCount() 
    if getElementData(getLocalPlayer(),"preidlename") then 
        triggerServerEvent("onIdleReturn",getLocalPlayer(),getElementData(getLocalPlayer(),"preidlename")) 
    end 
    setElementData(getLocalPlayer(),"preidlename",false,true) 
end 
addEventHandler("onClientCursorMove",getRootElement(),clientAction) 
bindKey("fire","both",clientAction) 
bindKey("next_weapon","both",clientAction) 
bindKey("previous_weapon","both",clientAction) 
bindKey("forwards","both",clientAction) 
bindKey("backwards","both",clientAction) 
bindKey("left","both",clientAction) 
bindKey("right","both",clientAction) 
bindKey("zoom_in","both",clientAction) 
bindKey("zoom_out","both",clientAction) 
bindKey("change_camera","both",clientAction) 
bindKey("jump","both",clientAction) 
bindKey("sprint","both",clientAction) 
bindKey("look_behind","both",clientAction) 
bindKey("crouch","both",clientAction) 
bindKey("action","both",clientAction) 
bindKey("walk","both",clientAction) 
bindKey("aim_weapon","both",clientAction) 
bindKey("conversation_yes","both",clientAction) 
bindKey("conversation_no","both",clientAction) 
bindKey("group_control_forwards","both",clientAction) 
bindKey("group_control_back","both",clientAction) 
bindKey("enter_exit","both",clientAction) 
bindKey("vehicle_fire","both",clientAction) 
bindKey("vehicle_secondary_fire","both",clientAction) 
bindKey("vehicle_left","both",clientAction) 
bindKey("vehicle_right","both",clientAction) 
bindKey("steer_forward","both",clientAction) 
bindKey("steer_back","both",clientAction) 
bindKey("accelerate","both",clientAction) 
bindKey("brake_reverse","both",clientAction) 
bindKey("radio_next","both",clientAction) 
bindKey("radio_previous","both",clientAction) 
bindKey("radio_user_track_skip","both",clientAction) 
bindKey("horn","both",clientAction) 
bindKey("sub_mission","both",clientAction) 
bindKey("handbrake","both",clientAction) 
bindKey("vehicle_look_left","both",clientAction) 
bindKey("vehicle_look_right","both",clientAction) 
bindKey("vehicle_look_behind","both",clientAction) 
bindKey("vehicle_mouse_look","both",clientAction) 
bindKey("special_control_left","both",clientAction) 
bindKey("special_control_right","both",clientAction) 
bindKey("special_control_down","both",clientAction) 
bindKey("special_control_up","both",clientAction) 
bindKey("enter_passenger","both",clientAction) 
bindKey("playerlist","both",clientAction) 
bindKey("screenshot","both",clientAction) 
bindKey("chatbox","both",clientAction) 
bindKey("radar","both",clientAction) 
bindKey("radar_zoom_in","both",clientAction) 
bindKey("radar_zoom_out","both",clientAction) 
bindKey("radar_move_north","both",clientAction) 
bindKey("radar_move_south","both",clientAction) 
bindKey("radar_move_east","both",clientAction) 
bindKey("radar_move_west","both",clientAction) 
bindKey("radar_attach","both",clientAction) 
  
function startIdleCount() 
    triggerServerEvent("onClientRequestIdleTime",getLocalPlayer()) 
    lastaction = getTickCount() 
end 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),startIdleCount) 
  
function saveIdleTime(kicktime) 
    idletime = kicktime 
    addEventHandler("onClientRender",getRootElement(),checkIdle) 
end 
addEvent("onServerReturnIdleTime",true) 
addEventHandler("onServerReturnIdleTime",getRootElement(),saveIdleTime) 
  
function checkIdle() 
    if getAnalogControlState("accelerate") > 0 
    or getAnalogControlState("brake_reverse") > 0 
    or getAnalogControlState("vehicle_left") > 0 
    or getAnalogControlState("vehicle_right") > 0 
    or getAnalogControlState("steer_forward") > 0 
    or getAnalogControlState("steer_back") > 0 
    or getAnalogControlState("forwards") > 0 
    or getAnalogControlState("backwards") > 0 
    or getAnalogControlState("left") > 0 
    or getAnalogControlState("right") > 0 then 
        lastaction = getTickCount() 
    end 
    if getTickCount() - lastaction >= idletime then 
        if getCameraTarget() == getLocalPlayer() or getCameraTarget() == getPedOccupiedVehicle(getLocalPlayer()) then 
            triggerServerEvent("onIdleKick",getLocalPlayer()) 
            lastaction = getTickCount() 
            --removeEventHandler("onClientRender",getRootElement(),checkIdle) 
        else 
            lastaction = getTickCount() 
        end 
    end 
end 

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