Jump to content

help please


Fory

Recommended Posts

      

        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

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

;)

  • Thanks 1
Link to comment

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

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

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