Jump to content

Anti AFK


XxRomxX

Recommended Posts

En la wiki, hay un script, justo lo que queres.

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) 
            kickPlayer(thePlayer, "Idle for 5 minutes") -- Kick the idle player 
        end 
    end 
end 
setTimer(checkAFKPlayers, 30000, 0) -- Timer to execute every 30 seconds, checking for idlers 

https://wiki.multitheftauto.com/wiki/GetPlayerIdleTime

Link to comment

Server

--***********************************-- 
--***********************************-- 
--           Anti AFK System         -- 
--            By Al3grab             -- 
--            Server Side            -- 
--***********************************-- 
--***********************************-- 
  
----------- CHANGEABLE 
AFK_TIME = 1 -- the time that if the player didn't moved he will be AFK , in minutes . 
AFK_TIMES = 5 -- afk times before the player get kicked . 
SHOW,AFK_MSG = true -- show the afk message [true or false 
msgs = true -- show messages on chat box ? 
----------- 
  
function onResourceStart() 
    -- 
    outputDebugString("Anti-AFK By Al3grab | Started") 
    -- 
    startCheck() 
end 
addEventHandler("onResourceStart",resourceRoot,onResourceStart) 
  
function startCheck() 
    checkTimer = setTimer ( function() 
        for i,m in ipairs ( getElementsByType("player") ) do 
            local idle = getPlayerIdleTime(m) 
            if tonumber(idle) >= AFK_TIME * 60 * 1000  then 
                if not isPlayerAfk(m) then 
                    -- the player is afk 
                    triggerEvent("onPlayerAfk",m,m,idle) 
                end 
            else 
                local afk = isPlayerAfk(m) 
                if ( afk == true ) then 
                    -- the player was afk and now he is back ! 
                    triggerEvent("onPlayerAfkBack",m,m) 
                end 
            end 
        end 
    end , 1000 , 0 ) 
end 
  
addEvent("onPlayerAfk",true) 
addEventHandler("onPlayerAfk",root,function ( Player , Time ) 
    ------ 
    if SHOW then 
        if ( tostring ( AFK_MSG ) ) then 
            showAfkMessage(Player,true) 
        end 
    end 
    ------ 
    setPlayerAfk(Player,true) 
    ------ 
     
end ) 
  
addEvent("onPlayerAfkBack",true) 
addEventHandler("onPlayerAfkBack",root,function ( Player  ) 
    setPlayerAfk(source,false) 
    ------ 
    showAfkMessage(source,false) 
    ------ 
end ) 
  
  
function isPlayerAfk(Player) 
    local afk = getElementData(Player,"State-AFK") or false 
    return afk 
end 
  
function setPlayerAfk(Player,state) 
    setElementData(Player,"State-AFK",state or false) 
end 
  
function showAfkMessage(Player,state) 
        if state == true then ev = "YouAreAFK" else ev = "YouAreNotAFK" end 
        triggerClientEvent(Player,tostring(ev) or "YouAreAFK",Player) 
end 
  
function onAfkEnd(Player) 
    Player = Player or source 
    -- 
    setElementData(Player,"AFKtime",getElementData(Player,"AFKtime") + 1 ) 
    local afkTimes = getElementData(Player,"AFKtime") 
    if ( afkTimes and afkTimes >= AFK_TIMES ) then 
        kickPlayer(Player,"You Have Been Afk For : "..tonumber(AFK_TIME).." Minutes") 
        if msgs then    outputChatBox("** #FFFF00"..getPlayerName(Player).."#FFFF00 Has Been kicked for being afk ["..afkTimes.."]",root,255,0,0,true)  end 
    else 
        killPed(Player) 
        if msgs then    outputChatBox("** #FFFF00"..getPlayerName(Player).."#FFFF00 Has Been slapped for being afk ["..afkTimes.."]",root,255,0,0,true) end 
         
    end 
end 
addEvent("KillAFK",true) 
addEventHandler("KillAFK",root,onAfkEnd) 

client

--***********************************-- 
--***********************************-- 
--      Anti AFK System For War      -- 
--            By Al3grab             -- 
--            Client Side            -- 
--***********************************-- 
--***********************************-- 
-------------- CHANGEABLE 
NumToCount = 20 -- the number to count before the player get killed / kicked 
MSGtoShow = "You Are Afk" -- the Message to show 
CountSpeed = 1500 -- less number will be faster. 
-------------- UNCHANGEABLE 
rRoot = getResourceRootElement(getThisResource()) -- Resource Root ,, 
setElementData(getLocalPlayer(),"AFKtime",0) -- Rest AFK Times For Player 
setElementData(localPlayer,"State-AFK",false) 
--- DX --- 
sw, sh = guiGetScreenSize() -- Get The Screen Size 
x,y = sw/2,sh/2 -- Using Math to Set The Text in center 
  
addEvent("YouAreAFK",true) -- AFK Message Event 
addEventHandler("YouAreAFK",root, -- AFK Message Event Handler 
function() -- AFK Message Function 
    function You() -- AFK Message Function 
  
    dxDrawText(  MSGtoShow, x-700,y-497,sw,sh,tocolor ( 0, 0, 0, 255 ), 4, "pricedown","center", "center", false, false, false)-- AFK Message Shaddow 
    dxDrawText( MSGtoShow, x-700,y-500,sw,sh,tocolor ( 255, 255, 0, 255 ), 4, "pricedown","center", "center", false, false, false)-- AFK Message 
  
    end -- END of AFK Message Function 
addEventHandler ( "onClientRender",root,You) -- AFK Message Event Handler 
Count() -- Kill Player Counting Trigger 
end ) 
  
function Count()-- Counting 
-- Count -- 
        local n = NumToCount -- Count Number 
        local count = ""..n.."" -- Count Number 
        local x,y = sw/2,sh/2 -- Center Text 
  
        function txt() 
            dxDrawText(" You Will Be Killed After "..count.." Seconds", x-700,y-292,sw,sh,tocolor ( 0, 0, 0, 255 ), 1, "pricedown","center", "center", false, false, false) -- Counting DX 
            dxDrawText(" You Will Be Killed After "..count.." Seconds", x-700,y-295,sw,sh,tocolor ( 255, 0, 0, 255 ), 1, "pricedown","center", "center", false, false, false)-- Counting DX 
             
            dxDrawText(" Move To Cancel", x-700,y-241,sw,sh,tocolor ( 0, 0, 0, 255 ), 1, "pricedown","center", "center", false, false, false)-- Text DX 
            dxDrawText(" Move To Cancel", x-700,y-243,sw,sh,tocolor ( 255, 0, 0, 255 ), 1, "pricedown","center", "center", false, false, false)-- Text DX 
        end 
         
        addEventHandler ( "onClientRender" , root ,txt)-- Adding DX Event Handler 
         
    timer = setTimer ( -- Count  
            function()-- Count  
                n = n - 1 -- Count  
                count = ""..n.."" -- Count  
                playSoundFrontEnd ( 20 )-- Play Sound On Count  
            if n == 0 then -- on Count END 
                    triggerServerEvent ("KillAFK", getLocalPlayer()) -- Triggers Killing Function 
                    playSoundFrontEnd ( 101 ) -- Play SOund on Count END 
                    removeEventHandler ( "onClientRender" , root ,txt) -- Remove DX Text's After Count END 
                    removeEventHandler ( "onClientRender",root,You)-- Remove DX Text's After Count END 
                end 
            end 
        , CountSpeed , NumToCount ) -- End Of Count Timer 
         
--- Count--- 
end  
  
addEvent("YouAreNotAFK",true) -- Removing Message Event 
addEventHandler("YouAreNotAFK",root,-- Removing Message Event 
function()-- Removing Message Function 
removeEventHandler ( "onClientRender",root,You)-- Removing Message 1 
removeEventHandler ( "onClientRender" , root ,txt)-- Removing Message 2 
    if isTimer(timer) then 
        killTimer(timer)-- Killing The Timer 
    end 
end ) -- END of Removing Message Event 
  
--- DX ---   
  

  • Like 1
Link to comment

Creo que seria asi

server

--***********************************-- 
--***********************************-- 
--           Anti AFK System         -- 
--            By Al3grab             -- 
--            Server Side            -- 
--***********************************-- 
--***********************************-- 
  
----------- CHANGEABLE 
AFK_TIME = 1 -- the time that if the player didn't moved he will be AFK , in minutes . 
AFK_TIMES = 5 -- afk times before the player get kicked . 
SHOW,AFK_MSG = true -- show the afk message [true or false 
msgs = true -- show messages on chat box ? 
----------- 
  
function onResourceStart() 
    -- 
    outputDebugString("Anti-AFK By Al3grab | Started") 
    -- 
    startCheck() 
end 
addEventHandler("onResourceStart",resourceRoot,onResourceStart) 
  
function startCheck() 
    checkTimer = setTimer ( function() 
        for i,m in ipairs ( getElementsByType("player") ) do 
            local idle = getPlayerIdleTime(m) 
            if tonumber(idle) >= AFK_TIME * 60 * 1000  then 
                if not isPlayerAfk(m) then 
                    -- the player is afk 
                    triggerEvent("onPlayerAfk",m,m,idle) 
                end 
            else 
                local afk = isPlayerAfk(m) 
                if ( afk == true ) then 
                    -- the player was afk and now he is back ! 
                    triggerEvent("onPlayerAfkBack",m,m) 
                end 
            end 
        end 
    end , 1000 , 0 ) 
end 
  
addEvent("onPlayerAfk",true) 
addEventHandler("onPlayerAfk",root,function ( Player , Time ) 
    ------ 
    if SHOW then 
        if ( tostring ( AFK_MSG ) ) then 
            showAfkMessage(Player,true) 
        end 
    end 
    ------ 
    setPlayerAfk(Player,true) 
    ------ 
    
end ) 
  
addEvent("onPlayerAfkBack",true) 
addEventHandler("onPlayerAfkBack",root,function ( Player  ) 
    setPlayerAfk(source,false) 
    ------ 
    showAfkMessage(source,false) 
    ------ 
end ) 
  
  
function isPlayerAfk(Player) 
    local afk = getElementData(Player,"State-AFK") or false 
    return afk 
end 
  
function setPlayerAfk(Player,state) 
    setElementData(Player,"State-AFK",state or false) 
end 
  
function showAfkMessage(Player,state) 
        if state == true then ev = "YouAreAFK" else ev = "YouAreNotAFK" end 
        triggerClientEvent(Player,tostring(ev) or "YouAreAFK",Player) 
end 
  
function onAfkEnd(Player) 
    Player = Player or source 
    -- 
    setElementData(Player,"AFKtime",getElementData(Player,"AFKtime") + 1 ) 
    local afkTimes = getElementData(Player,"AFKtime") 
    if ( afkTimes and afkTimes >= AFK_TIMES ) then 
        kickPlayer(Player,"You Have Been Afk For : "..tonumber(AFK_TIME).." Minutes") 
        if msgs then    outputChatBox("** #FFFF00"..getPlayerName(Player).."#FFFF00 Has Been kicked for being afk ["..afkTimes.."]",root,255,0,0,true)  end 
    end 
end 
addEvent("KillAFK",true) 
addEventHandler("KillAFK",root,onAfkEnd) 

Link to comment
  • Recently Browsing   0 members

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