Jump to content

Recommended Posts

i want to add afk check to my nametag, but i dont know how :S i tried this, but doesn't working :S 

--server

function checkAFKPlayers() 
    for index, thePlayer in ipairs(getElementsByType("player")) do
        if (getPlayerIdleTime(thePlayer) > 300000) then
            AFKCheck = "AFK"  
            end 
    end 
end 
setTimer(checkAFKPlayers, 30000, 0)

--client (only the two line)

local AFKCheck = {}

dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " (" .. AFKState .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false )

how to make this working? :S /sorry for my bad english:c/

Link to comment

Do it on client-side, so it doesn't effect your server at all.
 

local nextCheckTime = 10000
local oX, oY, oZ = nil, nil, nil
function isAFK()
	local pX, pY, pZ = getElementPosition(localPlayer)
	if oX then
		if pX == oX and pY == oY and pZ == oZ then
			setElementData(localPlayer, "isAFK", true)
		elseif getElementData(localPlayer, "isAFK") then
			setElementData(localPlayer, "isAFK", false)
		end
	end
	oX, oY, oZ = pX, pY, pZ
end
setTimer(isAFK, nextCheckTime, 0)

Now you just have to add the clientRender to do the drawings for everyone.

  • Like 1
Link to comment
4 minutes ago, Patrik91 said:

Do it on client-side, so it doesn't effect your server at all.
 


local nextCheckTime = 10000
local oX, oY, oZ = nil, nil, nil
function isAFK()
	local pX, pY, pZ = getElementPosition(localPlayer)
	if oX then
		if pX == oX and pY == oY and pZ == oZ then
			setElementData(localPlayer, "isAFK", true)
		elseif getElementData(localPlayer, "isAFK") then
			setElementData(localPlayer, "isAFK", false)
		end
	end
	oX, oY, oZ = pX, pY, pZ
end
setTimer(isAFK, nextCheckTime, 0)

Now you just have to add the clientRender to do the drawings for everyone.

i added

                    dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " (" .. isAFK .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false )

but i got this error:

attempt to concatenate global 'isAFK' a function value :S 

  • Like 1
Link to comment

Can you send me a 10 line look into from before?

dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " (" .. isAFK .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false )

 

Link to comment

Try this:

local state = getElementData(player,"isAFK") and "AFK" or "Active"
dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " (" .. state .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false )

 

  • Like 1
Link to comment
3 minutes ago, Mr.Loki said:

Try this:


local state = getElementData(player,"isAFK") and "AFK" or "Active"
dxDrawColorText ("#00BAFF" .. getPlayerName(player) .. " (" .. state .. ")", sx-w, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), player ~= g_Me and textscale*NAMETAG_TEXTSIZE or (textscale*NAMETAG_TEXTSIZE)/1.5, srfont, "center", "bottom", false, false, false )

 

Thanks :D

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