Coffey Posted March 18, 2013 Share Posted March 18, 2013 Hey! I have a global chat script. I want to make it so if someone types: /gcoff then he can't see the GCHAT. It doesn't necessary to save this data, but if anybody can help me make this, I'd really appreciate it! Here is the code. function globalMessage(thePlayer, cmd, ...) local message = table.concat ( { ... }, " " ); local name = getPlayerName(thePlayer); for _,v in ipairs(getElementsByType("player")) do outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message,v, 255, 255, 255, true) end end addCommandHandler("global", globalMessage); addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() for index,player in pairs(getElementsByType("player")) do bindKey(player,"b", "down", "chatbox", "global"); end end ) addEventHandler("onPlayerJoin",root, function () bindKey(source,"b", "down", "chatbox", "global"); end ); I would really appreciate your help! Link to comment
Castillo Posted March 18, 2013 Share Posted March 18, 2013 Create a table, when a player uses that command, insert the player element as index in the table, inside the loop to send the chat message, check if he player is in that table. Link to comment
Renkon Posted March 18, 2013 Share Posted March 18, 2013 In order to make something similar to your request, you should create, as Castillo said, a table holding every player as a row. Inside each row, you should place a variable depending on whether it's disabled (true) or not. By default, everything is false in a table. So, you create a commandHandler setting their table[player] equal to false. That's done, one step more. You must add a if-check inside the function where you outputChatBox in order to send (or not) the message. Please, don't watch out the spoiler unless you tried and you couldn't do it. local isChatDisabled = {} function globalMessage(thePlayer, cmd, ...) local message = table.concat ( { ... }, " " ); local name = getPlayerName(thePlayer); for _,v in ipairs(getElementsByType("player")) do if not isChatDisabled[v] then outputChatBox("#FF0000[GLOBAL]#00FF00"..name..": #FFFFFF"..message,v, 255, 255, 255, true) end end end addCommandHandler("global", globalMessage); addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() for index,player in pairs(getElementsByType("player")) do bindKey(player,"b", "down", "chatbox", "global"); end end ) addEventHandler("onPlayerJoin",root, function () bindKey(source,"b", "down", "chatbox", "global"); end ); addCommandHandler("gcoff", function(p) isChatDisabled[p] = true; end ); Link to comment
Coffey Posted March 18, 2013 Author Share Posted March 18, 2013 Hey. I've tried to make something like that, but it just didn't work. I copied a bit from your code, but somehow if I type /gcoff, it really turns it off, but then I cant turn it on back... Anyway, thank your help, I hope you can help me with this, I am really a big noob in LUA but I am trying hard. Link to comment
Renkon Posted March 18, 2013 Share Posted March 18, 2013 Hey.I've tried to make something like that, but it just didn't work. I copied a bit from your code, but somehow if I type /gcoff, it really turns it off, but then I cant turn it on back... Anyway, thank your help, I hope you can help me with this, I am really a big noob in LUA but I am trying hard. Add another command handler to set isChatDisabled[p] to false Link to comment
Coffey Posted March 18, 2013 Author Share Posted March 18, 2013 Thank you dude, it's working! 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