.:HyPeX:. Posted January 10, 2014 Share Posted January 10, 2014 Hi guys, should this work? im not sure if it will recognize the definition of serialB when setting up a value in the table.. MutedPlayers = {} function addMutedPlayer(thePlayer, cmd, Target) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.gsub(playername0, "[A]", "a") local playername2 = string.gsub(playername1, "[b]", "b") local playername3 = string.gsub(playername2, "[C]", "c") local playername4 = string.gsub(playername3, "[D]", "d") local playername5 = string.gsub(playername4, "[E]", "e") local playername6 = string.gsub(playername5, "[F]", "f") local playername7 = string.gsub(playername6, "[G]", "g") local playername8 = string.gsub(playername7, "[H]", "h") local playername9 = string.gsub(playername8, "[i]", "i") local playername10 = string.gsub(playername9, "[J]", "j") local playername11 = string.gsub(playername10, "[K]", "k") local playername12 = string.gsub(playername11, "[L]", "l") local playername13 = string.gsub(playername12, "[M]", "m") local playername14 = string.gsub(playername13, "[Ñ]", "n") local playername15 = string.gsub(playername14, "[N]", "ñ") local playername16 = string.gsub(playername15, "[O]", "o") local playername17 = string.gsub(playername16, "[P]", "p") local playername18 = string.gsub(playername17, "[Q]", "q") local playername19 = string.gsub(playername18, "[R]", "r") local playername20 = string.gsub(playername19, "[s]", "s") local playername21 = string.gsub(playername20, "[T]", "t") local playername22 = string.gsub(playername21, "[u]", "u") local playername23 = string.gsub(playername22, "[V]", "v") local playername24 = string.gsub(playername23, "[W]", "w") local playername25 = string.gsub(playername24, "[X]", "x") local playername26 = string.gsub(playername25, "[Y]", "y") local playername27 = string.gsub(playername26, "[Z]", "z") if string.match(playername27, Target) then local serialA = getPlayerSerial(thePlayer) local serialB = getPlayerSerial(v) table.insert(MutedPlayers, serialB) MutedPlayers.serialB = serialA end end end Link to comment
Castillo Posted January 10, 2014 Share Posted January 10, 2014 What are all these string.gsub for? to make whole string lower case? if so, then simple use string.lower. Link to comment
Moderators IIYAMA Posted January 10, 2014 Moderators Share Posted January 10, 2014 Why don't you try: MutedPlayers[serialB] = serialA Link to comment
.:HyPeX:. Posted January 10, 2014 Author Share Posted January 10, 2014 Why don't you try: MutedPlayers[serialB] = serialA Thanks didnt thought of that, will it also directly add it? or i need to insert it first? @Castillo its just how i like it, and well, never knew that existed! Link to comment
Moderators IIYAMA Posted January 10, 2014 Moderators Share Posted January 10, 2014 (edited) No need to use table.insert. Because it is already doing that, except it isn't making use of a function. But the best way is using a table in a table: MutedPlayers[serialB] = {manager=serialA,muteTime=getTickCount()+30000,reason=""} Everybody has it's own way of writing down tables. I do it like this: MutedPlayers[serialB] = {["manager"]=serialA,["muteTime"]=getTickCount()+30000,["reason"]=""} It gives the same result. UPDATED Edited January 10, 2014 by Guest Link to comment
.:HyPeX:. Posted January 10, 2014 Author Share Posted January 10, 2014 No need to use table.insert.Because it is already doing that, except it isn't making use of a function. Thanks for the help, i'll soon see if it works and it goes on Link to comment
.:HyPeX:. Posted January 11, 2014 Author Share Posted January 11, 2014 Just continuing, faced another problem, removing the value after a predefined time, but i get errors. function addMutedPlayer(thePlayer, cmd, Target, time) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerSerial(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA MutedTime = time * 1000 muted = setTimer(function(), MutedPlayers[SerialB] = nil end, MutedTime, 1) end end end addCommandHandler("mp", addMutedPlayer, false,false) Line 11: unexpected symbol near ',' line 12: '' expected near 'end' line 13: '' expected near 'end' line 14: '' expected near 'end' Link to comment
Moderators IIYAMA Posted January 11, 2014 Moderators Share Posted January 11, 2014 muted = setTimer(function(), MutedPlayers[SerialB] = nil end, MutedTime, 1) function(), muted = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) Also put a break when you found your target. (can save you some memory by ending up the loop) function addMutedPlayer(thePlayer, cmd, Target, time) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerSerial(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA MutedTime = time * 1000 muted = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) break -- save memory! end end end addCommandHandler("mp", addMutedPlayer, false,false) Link to comment
.:HyPeX:. Posted January 11, 2014 Author Share Posted January 11, 2014 I just like placing apart the unmute timer from the mute itself, this way an unmute would work (supposing target is in server)? function addMutedPlayer(thePlayer, cmd, Target, time) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerSerial(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA if time then MutedTime = time * 1000 muted = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) break end end end end addCommandHandler("mp", addMutedPlayer, false,false) function DelMutedPlayer(thePlayer, cmd, Target) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialB = getPlayerSerial(v) MutedPlayers[serialB] = nil break end end end addCommandHandler("ump", DelMutedPlayer, false,false) Link to comment
Moderators IIYAMA Posted January 11, 2014 Moderators Share Posted January 11, 2014 I would choose for something similar to the resource mission timer. 1 Timer to manage the future time of the saved mutes and saving lots of memory. Link to comment
.:HyPeX:. Posted January 11, 2014 Author Share Posted January 11, 2014 I found a problem on the almost finished script.. Error on line 38: table index is nill ----Anti-Spam-Script-by-HyPeX-- ----Locals---- local resRoot = getResourceRootElement(getThisResource()) ------------------------------- ----Messages of Startup---- outputChatBox ("#00aaff[AntiSpam]: Script v1.2 by HyPeX Started.",root, 255, 255, 255, true) outputChatBox ("#00aaff[AntiSpam]: Aviable commands: sleft",root , 255, 255, 255, true) ------------------------------- ----Functions--- function credits() outputChatBox ( "Anti-Spam Script By HyPeX Loaded", source, 55, 125, 255 ) end addEventHandler("onPlayerJoin", root, credits) MutedPlayers = {} MutedPlayer = {} antiSpam = {} antiSpamFlood = {} antiSpamCheck = {} antiSpamMuted = {} function addMutedPlayer(thePlayer, cmd, Target, time) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerNameClean(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA if time then MutedTime = time * 1000 MutedPlayer[source] = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerNameClean(v) .."#00aaff was muted by ".. getPlayerNameClean(thePlayer), getRootElement(), 255,255,255,true) outputChatBox("#00aaff[AntiSpam]: Mute Time: #00aaff for ".. time .. " seconds!", getRootElement(), 255,255,255,true) else outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) end break end end end addCommandHandler("mp", addMutedPlayer, false,false) function DelMutedPlayer(thePlayer, cmd, Target) for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialB = getPlayerSerial(v) MutedPlayers[serialB] = nil outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was unmuted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) break end end end addCommandHandler("ump", DelMutedPlayer, false,false) Link to comment
Moderators IIYAMA Posted January 11, 2014 Moderators Share Posted January 11, 2014 May I ask what line it is on this post? Because at line 38 there isn't a table. Line 36, you defined source, while addCommandHandler doesn't have a source, only event's have. MutedPlayer[source] = setTimer(function() Link to comment
.:HyPeX:. Posted January 11, 2014 Author Share Posted January 11, 2014 Thanks it is working really well, but im struck with a point, i cant make the difference when there is no reason and there is no time, so its not saying reason when time is nill... just says muted. function addMutedPlayer(thePlayer, cmd, Target, time, reason) if hasObjectPermissionTo(thePlayer, "command.mute") then for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerName(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA if time then MutedTime = time * 1000 MutedPlayer[thePlayer] = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) if reason then outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) outputChatBox("#00aaff[AntiSpam]: Mute Time: #00aaff ".. string.format ( '%02d:%02d', math.floor(MutedTime/60/1000), math.fmod(math.floor(MutedTime/1000),60)) .. " , reason: ".. reason, getRootElement(), 255,255,255,true) else outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) outputChatBox("#00aaff[AntiSpam]: Mute Time: #00aaff ".. string.format ( '%02d:%02d', math.floor(MutedTime/60/1000), math.fmod(math.floor(MutedTime/1000),60)) .. " , reason: - ", getRootElement(), 255,255,255,true) end else if time == nil and reason then outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer).." | reason: ".. reason, getRootElement(), 255,255,255,true) else outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) end end break end end else return outputChatBox("#00aaff[AntiSpam]: You cant use this!", thePlayer, 255,255,255,true) end end addCommandHandler("mp", addMutedPlayer, false,false) EDIT: Im also struck at the point where i want to make a gui to manage muted players and players itself.. i can do the players part, but i kinda need some help on the muted players part.. so as to get muted time, reason, whos muted, serial, etc. Link to comment
.:HyPeX:. Posted January 11, 2014 Author Share Posted January 11, 2014 Bump, i just gave off the reasons, im quite amazed why it just says target cant be found.. function addMutedPlayer(thePlayer, cmd, Target, time) if hasObjectPermissionTo(thePlayer, "command.mute") then for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerName(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA if time then MutedTime = time * 1000 MutedPlayer[thePlayer] = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) outputChatBox("#00aaff[AntiSpam]: Mute Time: #00aaff ".. string.format ( '%02d:%02d', math.floor(MutedTime/60/1000), math.fmod(math.floor(MutedTime/1000),60)), getRootElement(), 255,255,255,true) else outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) end else outputChatBox("#00aaff[AntiSpam]: Player Could not be found!", thePlayer, 255,255,255,true) end break end else return outputChatBox("#00aaff[AntiSpam]: You cant use this!", thePlayer, 255,255,255,true) end end addCommandHandler("mp", addMutedPlayer, false,false) function DelMutedPlayer(thePlayer, cmd, Target) if hasObjectPermissionTo(thePlayer, "command.unmute") then for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialB = getPlayerSerial(v) if isTimer(antiSpamMuted[thePlayer]) then antiSpamMuted[source] = nil end MutedPlayers[serialB] = nil MutedPlayer[thePlayer] = nil outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was unmuted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) else outputChatBox("#00aaff[AntiSpam]: Cant find player!", thePlayer, 255,255,255,true) end break end else return outputChatBox("#00aaff[AntiSpam]: You cant use this!", thePlayer, 255,255,255,true) end end addCommandHandler("ump", DelMutedPlayer, false,false) Link to comment
.:HyPeX:. Posted January 30, 2014 Author Share Posted January 30, 2014 Hello? any help anyone?, it cant find somehow the target.. Link to comment
Moderators IIYAMA Posted January 30, 2014 Moderators Share Posted January 30, 2014 why don't you output both the names and find your problem... Those bugs can be found when you are debugging, when you don't do that it will cost 10 times more time to find it. Link to comment
.:HyPeX:. Posted January 31, 2014 Author Share Posted January 31, 2014 i got a strange problem, getElementsByType("player") only returns one player (from 20 online)... idk why.. Link to comment
.:HyPeX:. Posted January 31, 2014 Author Share Posted January 31, 2014 i got a strange problem, getElementsByType("player") only returns one player (from 20 online)... idk why.. Nvm, found out break was stopping the loop.. Link to comment
Moderators IIYAMA Posted January 31, 2014 Moderators Share Posted January 31, 2014 Well the break should be there after it found it's target. Only you have out it in the wrong block. Should be in the 4th block. function () --block 1 if --block 2 for .... loop... --block 3 if true then -- fount target condition... --block 4 break end end end end Link to comment
.:HyPeX:. Posted January 31, 2014 Author Share Posted January 31, 2014 It was outside block 4, it was in block 5 Link to comment
Moderators IIYAMA Posted January 31, 2014 Moderators Share Posted January 31, 2014 It should be here: function addMutedPlayer(thePlayer, cmd, Target, time) if hasObjectPermissionTo(thePlayer, "command.mute") then for i,v in ipairs(getElementsByType("player")) do local playername0 = string.gsub(getPlayerName(v), "#%x%x%x%x%x%x", "") local playername1 = string.lower(playername0) if string.match(playername1, Target) then local serialA = getPlayerName(thePlayer) local serialB = getPlayerSerial(v) MutedPlayers[serialB] = serialA if time then MutedTime = time * 1000 MutedPlayer[thePlayer] = setTimer(function() MutedPlayers[SerialB] = nil end, MutedTime, 1) outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) outputChatBox("#00aaff[AntiSpam]: Mute Time: #00aaff ".. string.format ( '%02d:%02d', math.floor(MutedTime/60/1000), math.fmod(math.floor(MutedTime/1000),60)), getRootElement(), 255,255,255,true) else outputChatBox("#00aaff[AntiSpam]: Player ".. getPlayerName(v) .."#00aaff was muted by ".. getPlayerName(thePlayer), getRootElement(), 255,255,255,true) end break else outputChatBox("#00aaff[AntiSpam]: Player Could not be found!", thePlayer, 255,255,255,true) end end else return outputChatBox("#00aaff[AntiSpam]: You cant use this!", thePlayer, 255,255,255,true) end end addCommandHandler("mp", addMutedPlayer, false,false) 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