Fory Posted May 2, 2021 Share Posted May 2, 2021 setTimer(function() if getElementData(getLocalPlayer(),"afk") == false then setElementData (getLocalPlayer(),"afk",true) outputChatBox("#d75959[Admin AFK]:#32b3ef " .. getLocalPlayer() .. "#ffffff 5 perce AFK dutyban.", getRootElement(), 255, 255, 255, true) end end, 10, 1) Line 4:: [ERROR]: afkC.lua:88: attempt to concatenate a userdata value. Link to comment
Tekken Posted May 2, 2021 Share Posted May 2, 2021 Instead of outputChatBox("#d75959[Admin AFK]:#32b3ef " .. getLocalPlayer() .. "#ffffff 5 perce AFK dutyban.", getRootElement(), 255, 255, 255, true) Use: outputChatBox("#d75959[Admin AFK]:#32b3ef " .. getPlayerName(getLocalPlayer()) .. "#ffffff 5 perce AFK dutyban.", getRootElement(), 255, 255, 255, true 1 Link to comment
Fory Posted May 2, 2021 Author Share Posted May 2, 2021 [Error]: afkC.lua:2: attempt to call global 'getLocalPlayer' (a nil value) [Error]: afkC.lua:2: attempt to call global 'getLocalPlayer' (a nil value) Line 2. 2 hours ago, Fory said: if getElementData(getLocalPlayer(),"afk") == false then getLocalPlayer() Link to comment
Fory Posted May 2, 2021 Author Share Posted May 2, 2021 the trouble is I set it up for 5 minutes and even writes if the player is not AFK Link to comment
Tekken Posted May 2, 2021 Share Posted May 2, 2021 Is this in server side or client side? 1 Link to comment
Fory Posted May 2, 2021 Author Share Posted May 2, 2021 Client because that AFK system is built into a client. Link to comment
Tekken Posted May 2, 2021 Share Posted May 2, 2021 Then you should start the timer when client streams in and not before, a simple if check should do such as if isElement(getLocalPlayer()) then 1 Link to comment
Fory Posted May 2, 2021 Author Share Posted May 2, 2021 and then where is isElement (getLocalPlayer ()) then where do I paste it? Link to comment
Tekken Posted May 3, 2021 Share Posted May 3, 2021 Just after this setTimer(function() 1 Link to comment
Fory Posted May 3, 2021 Author Share Posted May 3, 2021 Now it doesn't write out a choke, it only writes to AFK when there's no AFK in the player. Link to comment
Fory Posted May 3, 2021 Author Share Posted May 3, 2021 local lastClick = getTickCount() addEventHandler ("onClientRender",getRootElement(), function () local cTick = getTickCount () if cTick-lastClick >= 600000 then if getElementData(getLocalPlayer(),"afk") == false then local hp = getElementHealth (getLocalPlayer()) if hp > 0 then setElementData (getLocalPlayer(),"afk",true) end end end end ) addEventHandler( "onClientRestore", getLocalPlayer(), function () lastClick = getTickCount () setElementData (getLocalPlayer(),"afk",false) end ) addEventHandler( "onClientMinimize", getRootElement(), function () setElementData (getLocalPlayer(),"afk",true) end ) addEventHandler( "onClientCursorMove", getRootElement( ), function ( x, y ) lastClick = getTickCount () if getElementData(getLocalPlayer(),"afk") == true then setElementData (getLocalPlayer(),"afk",false) end end ) addEventHandler("onClientKey", getRootElement(), function () lastClick = getTickCount () if getElementData(getLocalPlayer(),"afk") == true then setElementData (getLocalPlayer(),"afk",false) end end ) setTimer(function() if isElement(getLocalPlayer()) then if getElementData(getLocalPlayer(),"afk") == false then setElementData (getLocalPlayer(),"afk",true) outputChatBox("#d75959[Admin AFK]:#32b3ef " .. getPlayerName(getLocalPlayer()) .. "#ffffff 1 perce AFK dutyban.", thePlayer, 255, 255, true) end end end, 60000, 1) This whole afk system, which is down there we did now add. Link to comment
Tekken Posted May 4, 2021 Share Posted May 4, 2021 I've made you an simple AFK system based on your code: --Client local lasTimeOnKeyboard = getTickCount(); local timeoutAFK = 5; --How much minutes to make him AFK ? local isClientAFK = false; function toggleClientAFK(toggle) if isClientAFK ~= toggle then isClientAFK = toggle; triggerServerEvent("toggleAFKStat", localPlayer, toggle); end end addEventHandler("onClientRender", root, function() if (getTickCount() - lasTimeOnKeyboard) >= (timeoutAFK * 60000) then if not isClientAFK and getElementHealth(localPlayer) > 0 then toggleClientAFK(true); end end end); addEventHandler("onClientKey", root, function() lasTimeOnKeyboard = getTickCount(); toggleClientAFK(false); end); addEventHandler("onClientCursorMove", root, function() lasTimeOnKeyboard = getTickCount(); toggleClientAFK(false); end) addEventHandler("onClientRestore", root, function() lasTimeOnKeyboard = getTickCount(); toggleClientAFK(false); end) addEventHandler("onClientMinimize", root, function() toggleClientAFK(true); end); --Server addEvent("toggleAFKStat", true); local isPlayerAFK = {}; addEventHandler("toggleAFKStat", root, function(toggle) if toggle then if not isPlayerAFK[client] then isPlayerAFK[client] = true; outputChatBox(getPlayerName(client).." is now AFK!", root, 255, 0, 0, true); end else if isPlayerAFK[client] then isPlayerAFK[client] = false; outputChatBox(getPlayerName(client).." is no more AFK!", root, 0, 255, 0, true); end end end); NOTE that it contains both Client and Server! And BTW you can't use outputChatBox on client to output on root element! 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