ColtCabana Posted March 21, 2012 Share Posted March 21, 2012 (edited) Hello, i have a anti-afk script with counting and kicking after 5 rounds but it not works. Could u help me and maybe fix it? --server local raceState = "" local enableMessages = true local messageColor = "#FF5555" function afkMsg(mtype,afkCount) if(mtype == 1) then outputChatBox("#FF6600* #FFFFFF".. getPlayerName(source).. "#FF6600 has been killed by the #FFFFFFAFK killer#FF6600 #FF6600[#ABCDEF"..afkCount.."/3#FF6600]",getRootElement(),255,255,255,true) elseif(mtype == 2) then outputChatBox("#FF6600* #FFFFFF".. getPlayerName(source).. "#FF6600 has been kicked for staying #FFFFFFAFK#FF6600 for 3 rounds!",getRootElement(),255,255,255,true) end end addEvent( "afkWarn", true ) addEventHandler( "afkWarn", getRootElement(), afkMsg) function afkKill() local thePlayer = source callClientFunction(thePlayer,"setKBA",thePlayer) setElementHealth(source, 0) end addEvent( "afkSlap", true ) addEventHandler( "afkSlap", getRootElement(), afkKill) function changeRaceState(newStateName) raceState = newStateName end addEvent("onRaceStateChanging", true) addEventHandler( "onRaceStateChanging", getRootElement(), changeRaceState) function afkKick(player) kickPlayer(player,"AFK") end addEvent( "afkKick", true) addEventHandler( "afkKick", getRootElement(), afkKick) 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 ------------- -- AFK killer ------------- 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, "img/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(isVehicleFrozen ( getPedOccupiedVehicle ( getLocalPlayer() )) and isFinished == false) then aTimeClear() end local isNew = getElementData (getLocalPlayer(), "state") if isNew == "waiting" or isNew == "dead" then aTimeClear() end if(getPedOccupiedVehicle ( getLocalPlayer() ) ~= false) then local player = getLocalPlayer() if(AFKtime >= MaxAFKtime) then if (afkCounter > 1) 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 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 ) 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 = 0 else end end addEventHandler("onClientPlayerWasted",getLocalPlayer(),deathReset) function resetKBA() killedByAfk = 0 end Thanks in advance. Edited March 21, 2012 by Guest Link to comment
Moderators IIYAMA Posted March 21, 2012 Moderators Share Posted March 21, 2012 I can't see the bug. Write: /debugscript 3 -- for finding your error. Mind: this script needs admin rights for kicking a player. First check what is wrong with the script, bevore you are going to say it is broken. Link to comment
ColtCabana Posted March 21, 2012 Author Share Posted March 21, 2012 I forgot about posting a error which debugscript gives. Here u are: ERROR: afktimer/c.lua:49 attempt to compare number with nil Link to comment
Moderators IIYAMA Posted March 21, 2012 Moderators Share Posted March 21, 2012 I don't think this is everything we need. afkCounter -- it does not have something that makes it higher than 1. What is the count of "afkcounter". If something does not have a count it will be a "nill". So: local afkCounter = 0 -- it will start at zero. Unless you make sure it is more complete. I can't fix something, when I am not sure if it is the right place, were it is broken. But try: local afkCounter = 0 -- write above the script... it will set the count to zero when the script starts. If your other part of the script will count up it will be nice. Link to comment
TwiX! Posted March 22, 2012 Share Posted March 22, 2012 ------------- -- AFK killer ------------- 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, "img/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(isVehicleFrozen ( getPedOccupiedVehicle ( getLocalPlayer() )) and isFinished == false) then aTimeClear() end local isNew = getElementData (getLocalPlayer(), "state") if isNew == "waiting" or isNew == "dead" then aTimeClear() end if(getPedOccupiedVehicle ( getLocalPlayer() ) ~= false) then local player = getLocalPlayer() if(AFKtime >= MaxAFKtime) then if (afkCounter <= 2) 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 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 ) 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 = 0 else end end addEventHandler("onClientPlayerWasted",getLocalPlayer(),deathReset) function resetKBA() killedByAfk = 0 end Link to comment
ColtCabana Posted March 22, 2012 Author Share Posted March 22, 2012 Same error but i found another ones: [2012-03-22 00:03:21] ERROR: [gamemodes]/[race]/[addons]/afktimer/s.lua:18: attempt to call global 'callClientFunction' (a nil value) [2012-03-22 00:03:21] ERROR: [gamemodes]/[race]/[addons]/afktimer/s.lua:7: attempt to concatenate local 'afkCount' (a nil value) Link to comment
TwiX! Posted March 22, 2012 Share Posted March 22, 2012 client ------------- -- AFK killer ------------- 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, "img/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(isVehicleFrozen ( getPedOccupiedVehicle ( getLocalPlayer() )) and isFinished == false) then aTimeClear() end local isNew = getElementData (getLocalPlayer(), "state") if isNew == "waiting" or isNew == "dead" then aTimeClear() end if(getPedOccupiedVehicle ( getLocalPlayer() ) ~= false) then local player = getLocalPlayer() if(AFKtime >= MaxAFKtime) then if (afkCounter <= 2) 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 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 ) function setKBA(thePlayer) killedByAfk = 1 end function deathReset() if killedByAfk == 0 then afkCounter = 0 end end addEventHandler("onClientPlayerWasted",getLocalPlayer(),deathReset) function resetKBA() killedByAfk = 0 end ------------------------------------------ -- Calling function from the client's side ------------------------------------------ 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) ----------------------- -- Call server function ----------------------- 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 Server local raceState = "" local enableMessages = true local messageColor = "#FF5555" function afkMsg(mtype,afkCounter) if(mtype == 1) then outputChatBox("#FF6600* #FFFFFF".. getPlayerName(source).. "#FF6600 has been killed by the #FFFFFFAFK killer#FF6600 #FF6600[#ABCDEF"..afkCounter.."/3#FF6600]",getRootElement(),255,255,255,true) elseif(mtype == 2) then outputChatBox("#FF6600* #FFFFFF".. getPlayerName(source).. "#FF6600 has been kicked for staying #FFFFFFAFK#FF6600 for 3 rounds!",getRootElement(),255,255,255,true) end end addEvent( "afkWarn", true ) addEventHandler( "afkWarn", getRootElement(), afkMsg) function afkKill() local thePlayer = source callClientFunction(thePlayer,"setKBA",thePlayer) setElementHealth(source, 0) end addEvent( "afkSlap", true ) addEventHandler( "afkSlap", getRootElement(), afkKill) function changeRaceState(newStateName) raceState = newStateName end addEvent("onRaceStateChanging", true) addEventHandler( "onRaceStateChanging", getRootElement(), changeRaceState) function afkKick(player) kickPlayer(player,"AFK") end addEvent( "afkKick", true) addEventHandler( "afkKick", getRootElement(), afkKick) 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) ------------------------------------------- -- Calling functions from the client's side ------------------------------------------- function callServerFunction(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("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) ----------------------- -- Call client function ----------------------- function callClientFunction(client, 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 -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) end Why u stolen nextreme script? Link to comment
ColtCabana Posted March 22, 2012 Author Share Posted March 22, 2012 I didn't stole nothing, just someone sent me that. Link to comment
TwiX! Posted March 23, 2012 Share Posted March 23, 2012 I didn't stole nothing, just someone sent me that. someone? lolz, pls close the topic Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now