Jump to content

afk system for BaseMode help me


IIIIlllllIII

Recommended Posts

hi

i make afk system for basemode

and the code not working

pleez fix it

server

  
  
local BaseModeState = "" 
local enableMessages = true 
local messageColor = "#FF5555" 
  
function afkMsg(mtype) 
    if(getResourceState ( getResourceFromName("BaseMode") ) == "running") then 
        local isFinished = call(getResourceFromName("BaseMode"), "isPlayerFinished", source) 
        if(not isFinished and BaseModeState == "Running") then 
            if(enableMessages) then 
                if(mtype == 1) then 
                    outputChatBox(messageColor.."* "..getPlayerName(source)..messageColor.." has been killed by Anti-AFK.", getRootElement(), 255,100,100, true) 
                elseif(mtype == 2) then 
                    outputChatBox(messageColor.."* You are AFK and you will be killed after 1 Minute!", source, 255,100,100, true) 
                end 
            end 
        end 
    end 
end 
  
addEvent( "afkWarn", true ) 
addEventHandler( "afkWarn", getRootElement(), afkMsg) 
  
function afkKill() 
    if(getResourceState ( getResourceFromName("BaseMode") ) == "running") then 
        local isFinished = call(getResourceFromName("BaseMode"), "isPlayerFinished", source) 
        if(not isFinished and BaseModeState == "Running") then 
            setElementHealth(source, 0) 
        end 
    end 
end 
  
addEvent( "afkSlap", true ) 
addEventHandler( "afkSlap", getRootElement(), afkKill) 
  
function changeBaseModeState(newStateName) 
    BaseModeState = newStateName 
end 
  
addEvent("onBaseModeStateChanging", true) 
addEventHandler( "onBaseModeStateChanging", getRootElement(), changeBaseModeState) 
  
function clientLoaded() 
    local msgenable  = get( "msgenable" ) 
    local msgcol     = get( "msgcolor" ) 
    if(msgenable) then 
        if(msgenable == "true") then 
            enableMessages = true 
        else 
            enableMessages = false 
        end 
        if(msgcol) then 
            messageColor = msgcol 
        end 
    end 
    local maxtime    = get( "maxafktime" ) 
    local wtime      = get( "warnTime" ) 
    triggerClientEvent ( "onSettingsReady", getRootElement(), maxtime, wtime) 
end 
  
addEvent("onClientLoaded", true) 
addEventHandler( "onClientLoaded", getRootElement(), clientLoaded) 
  

client

  
  
local MaxAFKtime = 30 
local warnTime = 20 
local v = 0 
local AFKtime = 0 
local sx,sy = guiGetScreenSize()  
local wEvent = false 
  
function rWarn() 
    dxDrawImage( sx/2 - 300, sy/2 - 100, 600, 200, 'warn.png' ) 
end 
  
function stopWarn() 
    if(wEvent) then 
        removeEventHandler("onClientRender", getRootElement(), rWarn)  
        wEvent = false 
    end 
end 
  
function checkMain() 
   if isPedInVehicle ( getLocalPlayer() ) then 
    v = getElementVelocity ( getPedOccupiedVehicle ( getLocalPlayer() ) ) 
    if(v == 0) then 
        aTimeAdd() 
    else 
        aTimeClear() 
    end 
   end 
end 
  
function aTimeAdd() 
    AFKtime = AFKtime + 0.1 
    local isFinished = getElementData ( getLocalPlayer(), "BaseMode.finished") 
    if(isVehicleFrozen ( getPedOccupiedVehicle ( getLocalPlayer() )) and isFinished == false) then 
        aTimeClear() 
    end 
    if(AFKtime >= MaxAFKtime) then 
        AFKtime = 0 
        triggerServerEvent ( "afkSlap", getLocalPlayer()) 
        stopWarn() 
        triggerServerEvent ( "afkWarn", getLocalPlayer(), 1) 
    elseif(AFKtime == warnTime) then 
        triggerServerEvent ( "afkWarn", getLocalPlayer(), 2) 
        if(not wEvent) then 
            addEventHandler("onClientRender", getRootElement(), rWarn) 
            wEvent = true 
        end 
    end 
end 
  
function aTimeClear() 
        AFKtime = 0 
end 
  
setTimer ( checkMain, 100, -1) 
  
function onClientLoaded(res) 
    triggerServerEvent("onClientLoaded",getLocalPlayer()) 
end 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),onClientLoaded) 
  
function loadSettings(maxtime, wtime ) 
    MaxAFKtime = tonumber(maxtime) 
    warnTime = tonumber(wtime) 
end 
addEvent( "onSettingsReady", true ) 
addEventHandler( "onSettingsReady", getRootElement(), loadSettings ) 
  
  

pleeez fix it not working with me i test it

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