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/

Share this post


Link to post

I think you should do a custom made idle timer, and not the in-built function for it.

Share this post


Link to post
17 minutes ago, Patrik91 said:

I think you should do a custom made idle timer, and not the in-built function for it.

O.o How? :S

Share this post


Link to post

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

Share this post


Link to post
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 

Share this post


Link to post

Do you have a nametag system?

Share this post


Link to post

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 )

 

Share this post


Link to post

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

Share this post


Link to post
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

Share this post


Link to post

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.