Chaos Posted August 23, 2013 Share Posted August 23, 2013 hi, im trying to make mute command but the problem is with time when i mute someone 4 min he will be muted for 24000 minutes function muteSomeone(player, cmd, target, reason, time) if (target and reason and time) then local target = getPlayerFromName(target) if (not isElement(target)) then outputChatBox("There is no player with this name", player, 255, 255, 0) return end if (tonumber(time) and tonumber(time) >= 1 and not isPlayerMuted(target)) then local minutes = math.floor(time * 60 * 1000) outputChatBox(getPlayerName(target).." has been muted for "..tostring(minutes).." minutes ("..reason..") .", root,255, 0, 0) setPlayerMuted(target, true) else outputChatBox("Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0) end end end addCommandHandler("mmute", muteSomeone) Link to comment
fmj02 Posted August 23, 2013 Share Posted August 23, 2013 He will be muted for ever because there's no timer in your code executing function which is responsible for unmute, outputChatBox displays 24 minutes because variable minutes contains this value. Currently it works like that: 4*60*1000 so minutes is equal to 240000 right now - your 4 minutes in milliseconds, so if you want to display it as minutes you've got to divide it by 1000 and then by 60. outputChatBox(getPlayerName(target).." has been muted for "..tostring(((minutes/1000)/60))).." minutes ("..reason..") .", root,255, 0, 0) Except this you should use setTimer to actually get it working. setTimer Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 like this ? setTimer(setPlayerMuted(muted, false), time*60*1000, 1) Link to comment
fmj02 Posted August 24, 2013 Share Posted August 24, 2013 like this ? setTimer(setPlayerMuted(muted, false), time*60*1000, 1) Use your minutes variable, for this reason it's created... isn't it? [...] local minutes = math.floor(time * 60 * 1000) outputChatBox(getPlayerName(target).." has been muted for "..tostring(((minutes/1000)/60)).." minutes ("..reason..") .", root,255, 0, 0) setPlayerMuted(target, true) setTimer(setPlayerMuted, minutes, 1, target, false) [...] Best regards. Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then local target = getPlayerFromName ( 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 ) else outputChatBox ( "Syntax: /mmute player reason time and player cannot be muted", player, 255, 255, 0 ) end end end addCommandHandler ( "mmute", muteSomeone ) Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 well it's working but how can i save the time when some player reconnect? Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 You can store the serials of each player on a table and the time he's muted for, then when they join, check if the serial is on that table. Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 can you simplify more or show me an example Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 --Global: local mutedSerials = { } --When you mute: mutedSerials [ getPlayerSerial ( target ) ] = milliseconds --When join: local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] if ( milliseconds ) then -- You mute him again. end Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 is that true ? local mutedSerials = { } function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then local target = getPlayerFromName ( 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 afterreconnect (target) local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] if ( milliseconds ) then outputChatBox ( getPlayerName ( target ) .." has been muted by Console", root, 255, 0, 0 ) setPlayerMuted ( target, true ) end end addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 Remove that "target" from "afterreconnect" function name, and replace it with 'source' on the setPlayerMuted/getPlayerName functions. You also forgot a ")" to close the event handler. Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 local mutedSerials = { } function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then local target = getPlayerFromName ( 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 afterreconnect (source) local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] if ( milliseconds ) then setPlayerMuted ( source, true ) end end addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) not working when i reconnect and i will get unmuted when reconnect Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 function afterreconnect (source) Remove "source" from there. Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 thanks it's working but when i reconnect the mute will still forever Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 Because you forgot about the setTimer part. Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 local mutedSerials = { } function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then local target = getPlayerFromName ( 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 afterreconnect () local milliseconds = mutedSerials [ getPlayerSerial ( source ) ] if ( milliseconds ) then setTimer ( setPlayerMuted, milliseconds, 1, source, false )] end end addEventHandler ( "onPlayerJoin", getRootElement(), afterreconnect ) true ? Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 Now you removed the line that mutes the player... also, why is there a bracket at the end of setTimer? Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 thank you soildsnake14 but i have last question how to mute a player with just part of his name example : /mmute Ch insult 1 Instead of /mmute Chaos insult 1 like admin panel with kick Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 https://wiki.multitheftauto.com/wiki/Ge ... omNamePart Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 Copy the source code from the wiki and then replace "getPlayerFromName" on your code with "getPlayerFromNamePart". Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 i can't really understand how to put it is that true ? function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then if target then for i, player in ipairs(getElementsByType("player")) do if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then return player local target = getPlayerFromName ( target ) if ( not isElement ( target ) ) then outputChatBox ( "There is no player with this name", player, 255, 255, 0 ) return end end end end return false 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 ) Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 No, you messed everything up, just copy the source code from the wiki and use the new function name, not hard to understand. Link to comment
Chaos Posted August 24, 2013 Author Share Posted August 24, 2013 local mutedSerials = { } function muteSomeone ( player, cmd, target, reason, time ) if ( target and reason and time ) then local target = getPlayerNameFromNamePart("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 true ? Link to comment
Castillo Posted August 24, 2013 Share Posted August 24, 2013 No, you are using "getPlayerNameFromNamePart" which isn't the correct name, use "getPlayerFromNamePart" and don't put target with quotes. 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