SkatCh Posted September 11, 2014 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 Failure is simply an opportunity to begin again more intelligently - Henry Ford
Moderators IIYAMA Posted September 11, 2014 Moderators 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. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
SkatCh Posted September 11, 2014 Author 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) Failure is simply an opportunity to begin again more intelligently - Henry Ford
Moderators IIYAMA Posted September 11, 2014 Moderators 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. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
SkatCh Posted September 11, 2014 Author 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 . Failure is simply an opportunity to begin again more intelligently - Henry Ford
Anubhav Posted September 11, 2014 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 See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
Moderators IIYAMA Posted September 11, 2014 Moderators 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 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
SkatCh Posted September 12, 2014 Author Posted September 12, 2014 Sorry didn't work . Failure is simply an opportunity to begin again more intelligently - Henry Ford
SkatCh Posted September 12, 2014 Author Posted September 12, 2014 any help. Failure is simply an opportunity to begin again more intelligently - Henry Ford
Moderators IIYAMA Posted September 12, 2014 Moderators 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. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
SkatCh Posted September 12, 2014 Author 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) Failure is simply an opportunity to begin again more intelligently - Henry Ford
Moderators IIYAMA Posted September 12, 2014 Moderators 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 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Anubhav Posted September 12, 2014 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) See my some resources: Skin shop: https://community.multitheftauto.com/in ... ls&id=8008 Note script: https://community.multitheftauto.com/in ... ls&id=8009 Rules Panel: https://community.multitheftauto.com/in ... ls&id=8246 Random Money: https://community.multitheftauto.com/in ... ls&id=8718
SkatCh Posted September 12, 2014 Author Posted September 12, 2014 thx bro for ur help but didn't work . Failure is simply an opportunity to begin again more intelligently - Henry Ford
SkatCh Posted September 12, 2014 Author Posted September 12, 2014 any help ?? Failure is simply an opportunity to begin again more intelligently - Henry Ford
Saml1er Posted September 12, 2014 Posted September 12, 2014 local quiter = function () if isTimer(unmuteTimer[source) then killTimer(unmuteTimer[source]) unmuteTimer[source] = nil end end addEventHandler("onPlayerQuit", root, quiter)
SkatCh Posted September 12, 2014 Author Posted September 12, 2014 Didn't work , please i need help. Failure is simply an opportunity to begin again more intelligently - Henry Ford
SkatCh Posted September 12, 2014 Author Posted September 12, 2014 any help. Failure is simply an opportunity to begin again more intelligently - Henry Ford
SkatCh Posted September 13, 2014 Author Posted September 13, 2014 ?? Failure is simply an opportunity to begin again more intelligently - Henry Ford
SkatCh Posted September 13, 2014 Author 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 Failure is simply an opportunity to begin again more intelligently - Henry Ford
Saml1er Posted September 13, 2014 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)
lcd1232 Posted September 13, 2014 Posted September 13, 2014 u must send parametr player in timer [lua]setTimer(function, 1000, 0, player)
SkatCh Posted September 13, 2014 Author Posted September 13, 2014 didn't work Failure is simply an opportunity to begin again more intelligently - Henry Ford
Saml1er Posted September 13, 2014 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)
Recommended Posts