Jump to content

Afk image is not visible


h4x7o0r

Recommended Posts

I've search in the "community" to find out an afk system for race gamemode and i found the resource done by Dr. Crazy (https://community.multitheftauto.com/index.php?p= ... ls&id=1283).

The resource is working very well, only thing i wanna mention is that doesn't show the .png warning for player

Here is the client side :

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(), "race.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 ) 

I've also used debugscript 3 and no error are shown.

So, how can i fix this and how can i add a counter for seconds ?

eg. You are afk. You will be destroyed in 10 sec (9,8...)

Thank you guys.

Link to comment
  • 2 weeks later...
MaxAFKtime = 30 
warnTime = 20 
v = 0 
AFKtime = 0 
tCount = 10 
sx,sy = guiGetScreenSize() 
wEvent = false 
afkCounter = 1 
  
function rWarn() 
    dxDrawImage( sx/2 - 300, sy/2 - 100, 600, 200, "warn.png") 
    dxDrawText("You will be killed in "..tostring(tCount).." seconds",sx/2 - 255, sy/2 + 45,sx,sy,tocolor(255,0,0,255),1.01,"bankgothic") 
end 
  
function stopWarn() 
    if(wEvent) then 
        removeEventHandler("onClientRender", getRootElement(), rWarn) 
        wEvent = false 
    end 
end 
  
function imgHandler() 
    stopWarn() 
end 
addEventHandler("onClientPlayerWasted",getLocalPlayer(),imgHandler) 
  
function checkMain() 
    if isPedInVehicle ( getLocalPlayer() ) then 
        aTimeAdd() 
    end 
end 
  
function aTimeAdd() 
    AFKtime = AFKtime + 1 
    local isFinished = getElementData ( getLocalPlayer(), "dead") 
    if(isElementFrozen ( getPedOccupiedVehicle ( getLocalPlayer() )) and isFinished == false) then 
        aTimeClear() 
        return 
    end 
    local isNew = getElementData (getLocalPlayer(), "state") 
    if isNew == "waiting" or isNew == "dead" then 
        aTimeClear() 
        return 
    end 
    if getControlState("accelerate") or getControlState("vehicle_left") or getControlState("vehicle_right") or getControlState("brake_reverse") then 
        aTimeClear() 
        return 
    end 
    if(getPedOccupiedVehicle ( getLocalPlayer() ) ~= false) then 
        local player = getLocalPlayer() 
        if (AFKtime >= MaxAFKtime) then 
            if (afkCounter <= 4) then 
                triggerServerEvent ( "afkWarn", player, 1, afkCounter) 
                afkCounter = afkCounter+1 
                triggerServerEvent ( "afkSlap", player) 
                stopWarn() 
            elseif (afkCounter > 2) then 
                triggerServerEvent ( "afkWarn", player, 1, afkCounter) 
                triggerServerEvent ( "afkWarn", player, 2) 
                afkCounter = 1 
            end 
        elseif(AFKtime >= warnTime) then 
            tCount = tCount - 1 
            if(not wEvent) then 
                addEventHandler("onClientRender", getRootElement(), rWarn) 
                wEvent = true 
            end 
        end 
    end 
end 
setTimer ( checkMain, 1000, -1) 
  
  
function aTimeClear() 
    AFKtime = 0 
    tCount = 11 
    stopWarn() 
end 
  
bindKey("accelerate","down",aTimeClear) 
bindKey("vehicle_left","down",aTimeClear) 
bindKey("vehicle_right","down",aTimeClear) 
bindKey("brake_reverse","down",aTimeClear) 
  
  
  
  
function setKBA(thePlayer) 
    killedByAfk = 1 
end 
  
function getKBA(thePlayer) 
    if killedByAfk == 0 then 
        thePlayer = getLocalPlayer() 
        callServerFunction("earnMoney", thePlayer) 
    end 
end 
  
function deathReset() 
    if killedByAfk == 0 then 
        afkCounter = 1 
    else 
    end 
end 
addEventHandler("onClientPlayerWasted",getLocalPlayer(),deathReset) 
  
function resetKBA() 
    killedByAfk = 0 
end 
  
  
function callClientFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do arg[key] = tonumber(value) or value end 
    end 
    loadstring("return "..funcname)()(unpack(arg)) 
end 
addEvent("onServerCallsClientFunction", true) 
addEventHandler("onServerCallsClientFunction", resourceRoot, callClientFunction) 
  
  
function callServerFunction(funcname, ...) 
    local arg = { ... } 
    if (arg[1]) then 
        for key, value in next, arg do 
            if (type(value) == "number") then arg[key] = tostring(value) end 
        end 
    end 
    triggerServerEvent("onClientCallsServerFunction", resourceRoot , funcname, unpack(arg)) 
end 
  

Link to comment

Thank you very much man, it's working flawless now.

I've had a strange problem that showed me double outputChat text when someone have been boomed from the server. I resolved that problem by removing the following lines from server.lua :

                elseif(mtype == 2) then 
                    outputChatBox(messageColor.."* You are AFK and you will be killed after 10 seconds!", source, 255,100,100, true) 
                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...