Jump to content

[Solved] AFK system


3B00DG4MER

Recommended Posts

Hello,I made New System AFK

IT's Work without Bugs

But it doesn't get to Dimension 1

Server :

function checkAFKPlayers() 
    for index, thePlayer in ipairs(getElementsByType("player"))do -- Loop all online players 
        if (getPlayerIdleTime(thePlayer) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes) 
            setElementDimension ( thePlayer, 1 )  
            outputChatBox("AFk Check") 
            end 
    end 
end 
setTimer(checkAFKPlayers, 30000, 0) -- Timer to execute every 30 seconds, checking for idlers 

Edited by Guest
Link to comment
  
function DimensionP (player, dimension) 
if isPedInVehicle (player) then 
local veh = getPedOccupiedVehicle (player) 
setElementDimension ( player, dimension ) 
setElementDimension ( veh, dimension ) 
else 
setElementDimension ( player, dimension ) 
end 
return true 
end 
  
function checkAFKPlayers() 
    for index, thePlayer in ipairs(getElementsByType("player"))do -- Loop all online players 
        if (getPlayerIdleTime(thePlayer) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes) 
            DimensionP ( thePlayer, 1 )  
            outputChatBox("AFk Check") 
            end 
    end 
end 
setTimer(checkAFKPlayers, 30000, 0)  

Link to comment
      
    function DimensionP (player, dimension) 
    if isPedInVehicle (player) then 
    local veh = getPedOccupiedVehicle (player) 
    setElementDimension ( player, dimension ) 
    setElementDimension ( veh, dimension ) 
    else 
    setElementDimension ( player, dimension ) 
    end 
    return true 
    end 
      
    function checkAFKPlayers() 
        for index, thePlayer in ipairs(getElementsByType("player"))do -- Loop all online players 
            if (getPlayerIdleTime(thePlayer) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes) 
                DimensionP ( thePlayer, 1 ) 
                outputChatBox("AFk Check") 
            elseif ( getElementDimension ( thePlayer) == 1 ) and (getPlayerIdleTime(thePlayer) < 300000) then 
             setElementDimension ( thePlayer, 0) 
              end 
        end 
    end 
    setTimer(checkAFKPlayers, 30000, 0)  

Link to comment
function checkAFKPlayers() 
    for index, source in ipairs(getElementsByType("player"))do -- Loop all online players 
        if (getPlayerIdleTime(source) > 300000) then -- Player hasn't moved for 300,000ms (5 minutes) 
            DimensionP ( source, 1 ) 
            outputChatBox("AFk Check") 
            elseif ( getElementDimension ( source) == 1 ) and (getPlayerIdleTime(source) < 300000) then 
            setElementDimension ( source, 0) 
        end 
    end 
end 
setTimer(checkAFKPlayers, 30000, 0) 

Try this, you haven't defined "thePlayer" either, but I replaced thePlayer with source which should get the local player. Not tested

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