Jump to content

Why flood outputchatbox? How to fix this?


Turbe$Z

Recommended Posts

function checkAFKPlayers()
    for index, source in ipairs(getElementsByType("player")) do
        if (getPlayerIdleTime(source) > 1000) then 
            setElementDimension ( source, 50)
			setElementAlpha(source, 50)
			outputChatBox("#004B00[DDC - Afk] #FFffFFNem mozogtál 2 percig, afk módba léptél! Kikapcsoláshoz mozdulj meg!", root, 255,000,000, true)
	elseif isElementMoving(source) then
	       setElementAlpha(source, 255)
           setElementDimension ( source, 0)
		   outputChatBox("#004B00[DDC - Afk] #FFffFFKiléptél az afk módból!", root, 255,000,000, true)
        end
    end
end
setTimer(checkAFKPlayers, 1000, 0)

function isElementMoving ( theElement )
    if isElement ( theElement ) then                    
        local x, y, z = getElementVelocity( theElement ) 
        return x ~= 0 or y ~= 0 or z ~= 0                
    end
 
    return false
end

how to fix this? i want once outputChatbox :S

  • Like 1
Link to comment

You need to save the last state of the player, try this:

local idleState = {}

function checkAFKPlayers()
    for index, source in ipairs(getElementsByType("player")) do
        if (getPlayerIdleTime(source) > 1000) and not idleState[source] or idleState[source] == "active" then 
			idleState[source] = "idle"
       		setElementDimension ( source, 50)
			setElementAlpha(source, 50)
			outputChatBox("#004B00[DDC - Afk] #FFffFFNem mozogtál 2 percig, afk módba léptél! Kikapcsoláshoz mozdulj meg!", source, 255,000,000, true)
		elseif isElementMoving(source) or getPlayerIdleTime(source) < 1000 and not idleState[source] or idleState[source] == "idle" then
			idleState[source] = "active"
			setElementAlpha(source, 255)
			setElementDimension ( source, 0)
			outputChatBox("#004B00[DDC - Afk] #FFffFFKiléptél az afk módból!", source, 255,000,000, true)
        end
    end
end
setTimer(checkAFKPlayers, 1000, 0)

function isElementMoving ( theElement )
    if isElement ( theElement ) then                    
        local x, y, z = getElementVelocity( theElement ) 
        return x ~= 0 or y ~= 0 or z ~= 0                
    end
 
    return false
end

 

Link to comment
4 minutes ago, pa3ck said:

You need to save the last state of the player, try this:


local idleState = {}

function checkAFKPlayers()
    for index, source in ipairs(getElementsByType("player")) do
        if (getPlayerIdleTime(source) > 1000) and not idleState[source] or idleState[source] == "active" then 
			idleState[source] = "idle"
       		setElementDimension ( source, 50)
			setElementAlpha(source, 50)
			outputChatBox("#004B00[DDC - Afk] #FFffFFNem mozogtál 2 percig, afk módba léptél! Kikapcsoláshoz mozdulj meg!", source, 255,000,000, true)
		elseif isElementMoving(source) or getPlayerIdleTime(source) < 1000 and not idleState[source] or idleState[source] == "idle" then
			idleState[source] = "active"
			setElementAlpha(source, 255)
			setElementDimension ( source, 0)
			outputChatBox("#004B00[DDC - Afk] #FFffFFKiléptél az afk módból!", source, 255,000,000, true)
        end
    end
end
setTimer(checkAFKPlayers, 1000, 0)

function isElementMoving ( theElement )
    if isElement ( theElement ) then                    
        local x, y, z = getElementVelocity( theElement ) 
        return x ~= 0 or y ~= 0 or z ~= 0                
    end
 
    return false
end

 

it's working, but this change dim every one second, instead of elementmoving

  • Like 1
Link to comment

Not sure how getPlayerIdleTime works, I don't know if you use binds / move camera that will re-initialize it, but if you are happy enough with only being AFK if the player hasn't moved, then change line 10 to this:

elseif isElementMoving(source) and not idleState[source] or idleState[source] == "idle" then

 

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