Chaos Posted August 23, 2013 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)
fmj02 Posted August 23, 2013 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
Chaos Posted August 24, 2013 Author Posted August 24, 2013 like this ? setTimer(setPlayerMuted(muted, false), time*60*1000, 1)
fmj02 Posted August 24, 2013 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.
Castillo Posted August 24, 2013 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 )
Chaos Posted August 24, 2013 Author Posted August 24, 2013 well it's working but how can i save the time when some player reconnect?
Castillo Posted August 24, 2013 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.
Chaos Posted August 24, 2013 Author Posted August 24, 2013 can you simplify more or show me an example
Castillo Posted August 24, 2013 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
Chaos Posted August 24, 2013 Author 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
Castillo Posted August 24, 2013 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.
Chaos Posted August 24, 2013 Author 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
Castillo Posted August 24, 2013 Posted August 24, 2013 function afterreconnect (source) Remove "source" from there.
Chaos Posted August 24, 2013 Author Posted August 24, 2013 thanks it's working but when i reconnect the mute will still forever
Chaos Posted August 24, 2013 Author 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 ?
Castillo Posted August 24, 2013 Posted August 24, 2013 Now you removed the line that mutes the player... also, why is there a bracket at the end of setTimer?
Chaos Posted August 24, 2013 Author 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
Castillo Posted August 24, 2013 Posted August 24, 2013 https://wiki.multitheftauto.com/wiki/Ge ... omNamePart
Castillo Posted August 24, 2013 Posted August 24, 2013 Copy the source code from the wiki and then replace "getPlayerFromName" on your code with "getPlayerFromNamePart".
Chaos Posted August 24, 2013 Author 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 )
Castillo Posted August 24, 2013 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.
Chaos Posted August 24, 2013 Author 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 ?
Castillo Posted August 24, 2013 Posted August 24, 2013 No, you are using "getPlayerNameFromNamePart" which isn't the correct name, use "getPlayerFromNamePart" and don't put target with quotes.
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