Bilal135 Posted January 29, 2018 Share Posted January 29, 2018 I created a custom mute system, and when a player is muted, it's all good as he gets unmuted after the mute time has passed, but if he reconnects, he's no more muted and can still talk, whereas the script thinks he is muted and attempts to unmute an already unmuted player. I tried using setElementData and getElementData when a muted player quits and then joins before the mute time has passed, but it didn't work out so I've no idea now. (Not included in the code below). Have a look at the code. Any help regarding this will be appreciated. if reason == "1" then if isPlayerMuted(target) then return outputChatBox("Player is already muted.", player, 255, 0, 0) end setPlayerMuted(target, true) outputChatBox("* "..name.." has been muted by "..plrname.."!", root, 13, 107, 39, true) setTimer(function() setPlayerMuted(target, false) outputChatBox("* "..name.." has been unmuted by Console.", root, 13, 107, 39, true) end, 30000, 1) end Thanks. Link to comment
URBAN Posted January 29, 2018 Share Posted January 29, 2018 (edited) Use setAccountData to store data and when player logins check it Edited January 29, 2018 by URBAN Link to comment
Bilal135 Posted January 29, 2018 Author Share Posted January 29, 2018 (edited) if reason == "1" then if isPlayerMuted(target) then return outputChatBox("Player is already muted.", player, 255, 0, 0) end if not ( playeraccount ) and isGuestAccount ( playeraccount ) then return end setPlayerMuted(target, true) setAccountData(playeraccount, "mutedfor30secs", true) outputChatBox("* "..name.." has been muted by "..plrname.."!", root, 13, 107, 39, true) setTimer(function() local quitacc = getAccountData(playeraccount, "quit") if (quitacc) then return end setPlayerMuted(target, false) setAccountData(playeraccount, "mutedfor30secs", false) outputChatBox("* "..name.." has been unmuted by Console.", root, 13, 107, 39, true) end, 30000, 1) end function muteOnLogin(_, playeraccount) if not ( playeraccount ) and isGuestAccount ( playeraccount ) then return end local muted = getAccountData(playeraccount, "mutedfor30secs") if not (muted) then return end setPlayerMuted(source, true) outputChatBox("muted", root) setTimer(function() setPlayerMuted(source, false) outputChatBox("unmuted", root) setAccountData(playeraccount, "mutedfor30secs", false) end, 30000, 1) end addEventHandler("onPlayerLogin", root, muteOnLogin) addEventHandler("onPlayerQuit", root, function(_, playeraccount) if not muted then return end if not (playeraccount) and isGuestAccount(playeraccount) then return end local muted = getAccountData(playeraccount, "mutedfor30secs") setAccountData(playeraccount, "quit", true) end) Didn't work, am I doing something wrong here? It mutes the muted player if he reconnects but doesn't unmute, and "Player has been unmuted by console" appears before "unmuted". Edited January 29, 2018 by Bilal135 Link to comment
URBAN Posted January 29, 2018 Share Posted January 29, 2018 if reason == "1" then if isPlayerMuted(target) then return outputChatBox("Player is already muted.", player, 255, 0, 0) end if playeraccount then else return end if isGuestAccount(playeraccount) then return end setPlayerMuted(target, true) setAccountData(playeraccount, "mutedfor30secs", true) outputChatBox("* "..name.." has been muted by "..plrname.."!", root, 13, 107, 39, true) setTimer(setPlayerMuted,30*1000,1,target,false) setTimer(setAccountData,30*1000,1,playeraccount,"mutedfor30secs",false) setTimer(outputChatBox,30*1000,1,"unmuted",root) end function muteOnLogin(_, playeraccount) if playeraccount then else return end if isGuestAccount(playeraccount) then return end local muted = getAccountData(playeraccount, "mutedfor30secs") if muted then setPlayerMuted(source, true) outputChatBox("muted", root) setTimer(setPlayerMuted,30*1000,1,target,false) setTimer(setAccountData,30*1000,1,playeraccount,"mutedfor30secs",false) setTimer(outputChatBox,30*1000,1,"unmuted",root) end end addEventHandler("onPlayerLogin", root, muteOnLogin) -- addEventHandler("onPlayerQuit", root, -- function(_, playeraccount) -- if not muted then return end -- if not (playeraccount) and isGuestAccount(playeraccount) then return end -- local muted = getAccountData(playeraccount, "mutedfor30secs") -- setAccountData(playeraccount, "quit", true) -- end) -- dont need it u already stored mutedfor30secs Link to comment
Bilal135 Posted January 29, 2018 Author Share Posted January 29, 2018 Same problem persisting, muted player is muted if he reconnects, but doesn't get unmuted even after 'unmuted' message shows up. ('unmuted' message shows up twice as well). Link to comment
kieran Posted January 29, 2018 Share Posted January 29, 2018 (edited) I don't know if this will work, just modified urbans code to how I'd s --[[if reason == "1" then --So this code block isn't in a function? I assume it's pasted with no function, but if not, put it in a function... if isPlayerMuted(target) then outputChatBox("Player is already muted.", player, 255, 0, 0) end if playeraccount then if not isGuestAccount(playeraccount) then setPlayerMuted(target, true) setAccountData(playeraccount, "mutedfor30secs", true) outputChatBox("* "..name.." has been muted by "..plrname.."!", root, 13, 107, 39, true) setTimer(setPlayerMuted,30*1000,1,target,false) setTimer(setAccountData,30*1000,1,playeraccount,"mutedfor30secs",false) setTimer(outputChatBox,30*1000,1,"unmuted",root) end end end]] function muteOnLogin(_, playeraccount) if playeraccount then if not isGuestAccount(playeraccount) then local muted = getAccountData(playeraccount, "mutedfor30secs") if muted ~= false then setPlayerMuted(source, true) outputChatBox("muted", source) --You tried outputting message to root :/ try avoid this... setTimer(setPlayerMuted,30*1000,1,source,false) setTimer(outputChatBox,30*1000,1,"unmuted",source) end end end end addEventHandler("onPlayerLogin", root, muteOnLogin) addEventHandler("onPlayerQuit", root, function(_, playeraccount) if (playeraccount) and not isGuestAccount(playeraccount) then if isPlayerMuted(source) then setAccountData(playeraccount, "mutedfor30secs", true) end end end) To be honest... Too lazy to comment it all but basically you were using root, playeraccount, and all sorts of weird stuff when "source" would of done the job, every time you look on the wiki, look at what the source element is... When a player triggers a function by doing an action (logging in, quitting, entering a vehicle) you can use "source" as the source element is the player, the wiki tells you this Also I assume the code above muteOnLogin isn't just loose in your actual script like that, if it is, you should put it in a function or tell me what you want done with it, this might help if it's not in a function.... function muteThePlayer(player,_,target) if reason == "1" then if isPlayerMuted(target) then outputChatBox("Player is already muted.", player, 255, 0, 0) end if playeraccount then if not isGuestAccount(playeraccount) then setPlayerMuted(target, true) setAccountData(playeraccount, "mutedfor30secs", true) outputChatBox("* "..target.." has been muted by "..player.."!", source, 13, 107, 39, true) setTimer(setPlayerMuted,30*1000,1,target,false) setTimer(setAccountData,30*1000,1,target,"mutedfor30secs",false) setTimer(outputChatBox,30*1000,1,"unmuted",target) end end end end addCommandHandler("mute", muteThePlayer) You were doing this: "if playeraccount then else return end" This literally does NOTHING! Something should be after "then" even if it's another if, the fact you put and else in there is beyond me.... This code might not work, but I hope it helps somehow, make sure to /debugscript 3 when you login and tell us what it says also look at console for errors. Edited January 29, 2018 by kieran Link to comment
itHyperoX Posted January 29, 2018 Share Posted January 29, 2018 feel free to edit. --< [ /mute ] >-- local playerMuteTimer = {} function insertToPlayerAccount(player, data, value) return setAccountData(getPlayerAccount(player), data, value) end function getFromPlayerAccount(player, data) return getAccountData(getPlayerAccount(player), data) end --< [ Info ] >-- addCommandHandler("muteinfo", function(player,cmd) if isPlayerMuted(player) then outputChatBox(core:getSyntax("warning").." Némítva vagy még "..math.ceil(getTimerDetails(playerMuteTimer[player])/60000).." percig.", player, 255, 255, 255, true) else outputErrorMSG("Nem vagy némítva!", player) end end) --< [ Kilépés ] >-- addEventHandler("onPlayerQuit", root, function() if isTimer(playerMuteTimer[source]) then outputChatBox("#FB5555[Offline Némítás]:#00B4FF "..getPlayerName(source).."#FFFFFF némítva lett a rendszer által "..math.ceil(getTimerDetails(playerMuteTimer[source])/60000).." percre.", root, 255, 0, 0, true) insertToPlayerAccount(source, "account#muted", math.ceil(getTimerDetails(playerMuteTimer[source])/60000)) killTimer(playerMuteTimer[source]) end end) --< [ Bejelentkezés ] >-- addEventHandler("onPlayerLogin", root,function() local playerMuted = getFromPlayerAccount(source, "account#muted") if not playerMuted then return end if (playerMuted >= 0) then setPlayerMuted(source, true) setElementData(source, "char#muted", 1) playerMuteTimer[source] = setTimer(function() setPlayerMuted(source,false) outputChatBox("#FB5555[Némítás]:#00B4FF "..getPlayerName(source).."#FFFFFF némítása lejárt.", root, 255, 0, 0, true) insertToPlayerAccount(source, "account#muted", 0) removeElementData(source, "char#muted") end,playerMuted*60000,1) outputChatBox(core:getSyntax("warning").." Némítva vagy még "..math.ceil(getTimerDetails(playerMuteTimer[source])/60000).." percre.", source, 255, 255, 255, true) end end) Link to comment
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