Turbe$Z Posted November 10, 2016 Posted November 10, 2016 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 1
pa3ck Posted November 10, 2016 Posted November 10, 2016 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
Turbe$Z Posted November 10, 2016 Author Posted November 10, 2016 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 1
pa3ck Posted November 10, 2016 Posted November 10, 2016 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
pa3ck Posted November 11, 2016 Posted November 11, 2016 It has to be in the loop because he's looping through every player. If you scroll up a bit you will see how it was fixed.
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