Jump to content

Problem with a script


hahec

Recommended Posts

Hello MTA. I'm new here. I have a problem with my script. I got it long time ago (dunno from where) and i didn't used it but now i found it like fun script to be working on my server. It's about killing an player who isn't moving. I know some basics in Lua scripting btw. Seems like something isn't working fine. I start the script (no errors). I camp and after a while i got warning "you will be killed in 10,9,8,7...". But when the countdown finishes nothing happens. Maybe you know the problem.

Ty.

Script:

MaxAFKtime = 25 
warnTime = 15 
v = 0 
AFKtime = 0 
tCount = 11 
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,186,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 
                triggerServerEvent ( "afkKick", player , player) 
            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 

meta.xml:

"idiotek" type="script" name="Anti-AFK"  version="1.0.0" /> 
 "warn.png" /> 
 

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