Chaos Posted September 21, 2013 Share Posted September 21, 2013 (edited) hi, i have some bugs with this code 1.when the timer of mute is finished then when the player is reconnect he will return muted 2.i can't put space with reason 3.there is no outputchatbox when the timer is finished here is the script: local mutedSerials = { } function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then local target = getPlayerFromNamePart ( target ) if ( not isElement ( target ) ) then outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) return end local time = tonumber ( time ) if ( time and time >= 1 and not isPlayerMuted ( target ) ) then local milliseconds = math.floor ( time * 60000 ) outputChatBox ( getPlayerName ( target ) .." has been muted for ".. tostring ( time ) .." minutes (".. reason ..") .", root, 255, 0, 0 ) setPlayerMuted ( target, true ) setTimer ( setPlayerMuted, milliseconds, 1, target, false ) mutedSerials [ getPlayerSerial ( target ) ] = milliseconds else outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) end end end addCommandHandler ( "mmute", muteSomeone ) function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end function afterreconnect () local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] if ( milliseconds ) then setPlayerMuted ( source, true ) setTimer ( setPlayerMuted, milliseconds, 1, source, false ) else setPlayerMuted ( source, false ) end end addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) Edited September 21, 2013 by Guest Link to comment
EstrategiaGTA Posted September 21, 2013 Share Posted September 21, 2013 3.there is no outpatchatbox when the timer is finished Do you mean when the player is going to be unmuted? Link to comment
EstrategiaGTA Posted September 21, 2013 Share Posted September 21, 2013 OK, you use this for unmute: setTimer ( setPlayerMuted, milliseconds, 1, target, false ) Try adding this line below: setTimer ( outputChatBox, milliseconds, 1, "yourtexthere", getRootElement(), 255, 255, 255, true) Link to comment
Chaos Posted September 21, 2013 Author Share Posted September 21, 2013 yes thanks it works but the problem when the timer of mute is finished then when the player is reconnect he will return muted also i can't put space with reason Link to comment
Chaos Posted September 21, 2013 Author Share Posted September 21, 2013 i really need help pleaseee Link to comment
Castillo Posted September 21, 2013 Share Posted September 21, 2013 local mutedSerials = { } function muteSomeone ( player, cmd, target, time, ... ) local reason = table.concat ( { ... }, " " ) if ( target and reason and time ) then local target = getPlayerFromNamePart ( target ) if ( not isElement ( target ) ) then outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) return end local time = tonumber ( time ) if ( time and time >= 1 and not isPlayerMuted ( target ) ) then local milliseconds = math.floor ( time * 60000 ) outputChatBox ( getPlayerName ( target ) .." has been muted for ".. tostring ( time ) .." minutes (".. reason ..") .", root, 255, 0, 0 ) setPlayerMuted ( target, true ) local timer = setTimer ( unMute, milliseconds, 1, target ) mutedSerials [ getPlayerSerial ( target ) ] = { milliseconds, timer } else outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) end end end addCommandHandler ( "mmute", muteSomeone ) function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end function afterreconnect ( local serial = getPlayerSerial ( source ) local muted = mutedSerials [ serial ] if ( type ( muted ) == "table" ) then if ( muted [ 1 ] ) then setPlayerMuted ( source, true ) local timer = setTimer ( unMute, muted [ 1 ], 1, source ) mutedSerials [ serial ] [ 2 ] = timer return end end setPlayerMuted ( source, false ) end addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) addEventHandler ( "onPlayerQuit", root, function ( ) local serial = getPlayerSerial ( source ) local muted = mutedSerials [ serial ] if ( type ( muted ) == "table" ) then if isTimer ( muted [ 2 ] ) then killTimer ( muted [ 2 ] ) end end end ) function unMute ( thePlayer ) if isElement ( thePlayer ) then setPlayerMuted ( thePlayer, false ) mutedSerials [ getPlayerSerial ( thePlayer ) ] = nil outputChatBox ( "You have been unmuted.", thePlayer, 0, 255, 0 ) end end That should fix the 3 problems. Link to comment
Chaos Posted September 22, 2013 Author Share Posted September 22, 2013 works perfect thank you bro :3 but the time will starts from the beginning if the player reconnect if he muted ? Link to comment
Castillo Posted September 23, 2013 Share Posted September 23, 2013 That's right, try this to save time left: local mutedSerials = { } function muteSomeone ( player, cmd, target, time, ... ) local reason = table.concat ( { ... }, " " ) if ( target and reason and time ) then local target = getPlayerFromNamePart ( target ) if ( not isElement ( target ) ) then outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) return end local time = tonumber ( time ) if ( time and time >= 1 and not isPlayerMuted ( target ) ) then local milliseconds = math.floor ( time * 60000 ) outputChatBox ( getPlayerName ( target ) .." has been muted for ".. tostring ( time ) .." minutes (".. reason ..") .", root, 255, 0, 0 ) setPlayerMuted ( target, true ) local timer = setTimer ( unMute, milliseconds, 1, target ) mutedSerials [ getPlayerSerial ( target ) ] = { milliseconds, timer } else outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) end end end addCommandHandler ( "mmute", muteSomeone ) function getPlayerFromNamePart(name) if name then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player end end end return false end function afterreconnect ( local serial = getPlayerSerial ( source ) local muted = mutedSerials [ serial ] if ( type ( muted ) == "table" ) then if ( muted [ 1 ] ) then setPlayerMuted ( source, true ) local timer = setTimer ( unMute, muted [ 1 ], 1, source ) mutedSerials [ serial ] [ 2 ] = timer return end end setPlayerMuted ( source, false ) end addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) addEventHandler ( "onPlayerQuit", root, function ( ) local serial = getPlayerSerial ( source ) local muted = mutedSerials [ serial ] if ( type ( muted ) == "table" ) then if isTimer ( muted [ 2 ] ) then local timeLeft = getTimerDetails ( muted [ 2 ] ) killTimer ( muted [ 2 ] ) mutedSerials [ serial ] [ 1 ] = timeLeft end end end ) function unMute ( thePlayer ) if isElement ( thePlayer ) then setPlayerMuted ( thePlayer, false ) mutedSerials [ getPlayerSerial ( thePlayer ) ] = nil outputChatBox ( "You have been unmuted.", thePlayer, 0, 255, 0 ) 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