SkatCh Posted September 11, 2014 Share Posted September 11, 2014 (edited) guys please i need some help here i create a mute system but i have some problems when the player reconnect i got some warnings: function decreaseMutedTime ( player, time ) if not ( isElement ( player ) ) then return; end unmuteTimer[player] = setTimer ( function () local timeLeft = tonumber ( getElementData ( player, "mt" ) ); ---- this line if ( timeLeft == 0 ) then killTimer(unmuteTimer[player]) outputDebugString ( "0 sec left" ); if ( getElementData ( player, "mute" ) ) then outputDebugString ( "is muted" ); setPlayerMuted ( player, false ); setElementData ( player, "mt", 0 ); setElementData ( player, "mute", false ); outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); unmuteTimer[player] = nil; end else if ( getElementData ( player, "mute" ) ) then -------------- and this line setElementData ( player, "mt", timeLeft - 1 ); end end end, 1000, -1 ); end Bad Argument @ 'getElementData' Expected Element at agument one 1. any help Edited September 14, 2014 by Guest Link to comment
Moderators IIYAMA Posted September 11, 2014 Moderators Share Posted September 11, 2014 inside the timer block should be a element check. (isElement(player)) If he isn't an element, the timer should be killed and the table should be cleared. Link to comment
SkatCh Posted September 11, 2014 Author Share Posted September 11, 2014 bro it happen just when the player reconnect i already create a save system to check the player mute time : function checkMuteOnLogout(account) if (not isPlayerMuted(source)) then return end local mutedTime = getElementData(source, "mt") or 0 if (tonumber(mutedTime > 1)) then setAccountData(account, "mt", tonumber(mutedTime)) end end addEventHandler("onPlayerLogout", root, checkMuteOnLogout) Link to comment
Moderators IIYAMA Posted September 11, 2014 Moderators Share Posted September 11, 2014 It seems you aren't reading my post correctly. I am not talking about the mute time, I am hell talking about the player element it self, while leaving an invalid player element is still in the system. onPlayerQuit would work better. Players should not be able to logout if you want your system to work correct. Link to comment
SkatCh Posted September 11, 2014 Author Share Posted September 11, 2014 It seems you aren't reading my post correctly. I am not talking about the mute time, I am hell talking about the player element it self, while leaving an invalid player element is still in the system. sorry bro i don't undrestand this can you help me to fix it i'm sorry if i aste ur time . Link to comment
Anubhav Posted September 11, 2014 Share Posted September 11, 2014 function decreaseMutedTime ( player, time ) if isElement ( player ) == false then return end unmuteTimer[player] = setTimer ( function () local timeLeft = tonumber ( getElementData ( player, "mt" ) ); ---- this line if ( timeLeft == 0 ) then killTimer(unmuteTimer[player]) outputDebugString ( "0 sec left" ); if ( getElementData ( player, "mute" ) ) then outputDebugString ( "is muted" ); setPlayerMuted ( player, false ); setElementData ( player, "mt", 0 ); setElementData ( player, "mute", false ); outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); unmuteTimer[player] = nil; end else if ( getElementData ( player, "mute" ) ) then -------------- and this line setElementData ( player, "mt", timeLeft - 1 ); end end end, 1000, -1 ); end Link to comment
Moderators IIYAMA Posted September 11, 2014 Moderators Share Posted September 11, 2014 It seems you aren't reading my post correctly. I am not talking about the mute time, I am hell talking about the player element it self, while leaving an invalid player element is still in the system. sorry bro i don't undrestand this can you help me to fix it i'm sorry if i aste ur time . I have no time to write the whole thing bro. But I will recommend you to use 1 timer and getTickCount(). With every timer execution you loop through the whole table and compare the time now with the future time. unmuteTimer[player]=getTickCount()+10000 -- time now + 10 seconds. local timeNow = getTickCount() for player, futureTime in pairs(unmuteTimer) do if isElemenr(player) then if timeNow > futureTime then unmuteTimer[player] = nil setPlayerMuted ( player, false ) end else unmuteTimer[player] = nil end end Link to comment
SkatCh Posted September 12, 2014 Author Share Posted September 12, 2014 Sorry didn't work . Link to comment
Moderators IIYAMA Posted September 12, 2014 Moderators Share Posted September 12, 2014 If you don't finish it, of course it will not work... Is this your code? Because you give me the feeling it isn't, since you don't try anything. Link to comment
SkatCh Posted September 12, 2014 Author Share Posted September 12, 2014 bro i try it also i create an other thing but didn't work i don't now why when the player quit the game this warning appear i can fix it by my self but i don't know what's the problem check this ; function decreaseMutedTime(player, time) if (not isElement(player) or not time) then return end local function decreaseTime() local o = tonumber(getElementData(player, "mt")) or 0 local time = o - 1 setElementData(player, "mt", getElementData(player, "mt") - 1) if (time <= 1 and isPlayerMuted(player)) then local time = nil setElementData(player, "mt", false) outputChatBox("You have been unmuted ", player, 255, 255, 0) setPlayerMuted(player, false) setElementData(player, "muteinfo", false) if (isTimer(unmuteTimer[player])) then killTimer(unmuteTimer[player]) end end end unmuteTimer[player] = setTimer(decreaseTime, 1000, tonumber(getElementData(player, "mt"))) end -- onPlayerLogout function checkMuteOnLogout(account) if (not isPlayerMuted(source)) then return end local mutedTime = getElementData(source, "mt") or 0 if (tonumber(mutedTime > 1)) then setAccountData(account, "mt", tonumber(mutedTime)) end end addEventHandler("onPlayerLogout", root, checkMuteOnLogout) and i create this onPlayerLogin function checkMuteOnLogin(account) local mutedTime = getAccountData(account, "mt") or 0 if (tonumber(mutedTime > 1)) then setPlayerMuted(source, true) decreaseMutedTime(source, mutedTime) end end addEventHandler("onPlayerLogin", root, checkMuteOnLogin) Link to comment
Moderators IIYAMA Posted September 12, 2014 Moderators Share Posted September 12, 2014 (edited) as I told you before, it is because you don't kill that timer when the player leaves. Nor the table get cleaned. Edited September 12, 2014 by Guest Link to comment
Anubhav Posted September 12, 2014 Share Posted September 12, 2014 function checkMuteOnLogout(account) if (not isPlayerMuted(source)) then return end local mutedTime = getElementData(source, "mt") or 0 if (tonumber(mutedTime > 1)) then setAccountData(account, "mt", tonumber(mutedTime)) if isTimer(unmuteTimer[source) then killTimer(unmuteTimer[source]) end end end addEventHandler("onPlayerLogout", root, checkMuteOnLogout) Link to comment
SkatCh Posted September 12, 2014 Author Share Posted September 12, 2014 thx bro for ur help but didn't work . Link to comment
Saml1er Posted September 12, 2014 Share Posted September 12, 2014 local quiter = function () if isTimer(unmuteTimer[source) then killTimer(unmuteTimer[source]) unmuteTimer[source] = nil end end addEventHandler("onPlayerQuit", root, quiter) Link to comment
SkatCh Posted September 12, 2014 Author Share Posted September 12, 2014 Didn't work , please i need help. Link to comment
Saml1er Posted September 13, 2014 Share Posted September 13, 2014 What's the problem? Link to comment
SkatCh Posted September 13, 2014 Author Share Posted September 13, 2014 every thing is working fine but when the muted player reconnect i got this warning Bad Argument @ 'getElementData' Expected Element at agument 1. function decreaseMutedTime ( player, time ) if not ( isElement ( player ) ) then return; end unmuteTimer[player] = setTimer ( function () local timeLeft = tonumber ( getElementData ( player, "mt" ) ); ---- this line if ( timeLeft == 0 ) then killTimer(unmuteTimer[player]) outputDebugString ( "0 sec left" ); if ( getElementData ( player, "mute" ) ) then outputDebugString ( "is muted" ); setPlayerMuted ( player, false ); setElementData ( player, "mt", 0 ); setElementData ( player, "mute", false ); outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); unmuteTimer[player] = nil; end else if ( getElementData ( player, "mute" ) ) then -------------- and this line setElementData ( player, "mt", timeLeft - 1 ); end end end, 1000, -1 ); end Link to comment
Saml1er Posted September 13, 2014 Share Posted September 13, 2014 every thing is working fine but when the muted player reconnect i got this warningBad Argument @ 'getElementData' Expected Element at agument 1. function decreaseMutedTime ( player, time ) if not ( isElement ( player ) ) then return; end unmuteTimer[player] = setTimer ( function () local timeLeft = tonumber ( getElementData ( player, "mt" ) ); ---- this line if ( timeLeft == 0 ) then killTimer(unmuteTimer[player]) outputDebugString ( "0 sec left" ); if ( getElementData ( player, "mute" ) ) then outputDebugString ( "is muted" ); setPlayerMuted ( player, false ); setElementData ( player, "mt", 0 ); setElementData ( player, "mute", false ); outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); unmuteTimer[player] = nil; end else if ( getElementData ( player, "mute" ) ) then -------------- and this line setElementData ( player, "mt", timeLeft - 1 ); end end end, 1000, -1 ); end I actually copied this code from Anubav and I just found a typo there. Try this. local quiter = function () if isTimer(unmuteTimer[source]) then killTimer(unmuteTimer[source]) unmuteTimer[source] = nil end end addEventHandler("onPlayerQuit", root, quiter) Link to comment
lcd1232 Posted September 13, 2014 Share Posted September 13, 2014 u must send parametr player in timer [lua]setTimer(function, 1000, 0, player) Link to comment
Saml1er Posted September 13, 2014 Share Posted September 13, 2014 didn't work unmuteTimer[player] = setTimer ( function (player) local timeLeft = tonumber ( getElementData ( player, "mt" ) ); ---- this line if ( timeLeft == 0 ) then killTimer(unmuteTimer[player]) outputDebugString ( "0 sec left" ); if ( getElementData ( player, "mute" ) ) then outputDebugString ( "is muted" ); setPlayerMuted ( player, false ); setElementData ( player, "mt", 0 ); setElementData ( player, "mute", false ); outputChatBox ( "Your time of being muted has expired.", player, 0, 255, 0 ); outputChatBox ( getPlayerName ( player ) .."'s mute has expired", root, 0, 255, 0 ); unmuteTimer[player] = nil; end else if ( getElementData ( player, "mute" ) ) then -------------- and this line setElementData ( player, "mt", timeLeft - 1 ); end end end, 1000, -1, player ); You must also add this: local quiter = function () if isTimer(unmuteTimer[source]) then killTimer(unmuteTimer[source]) unmuteTimer[source] = nil end end addEventHandler("onPlayerQuit", root, quiter) Link to comment
Recommended Posts