DREFTHUN Posted January 12, 2018 Share Posted January 12, 2018 I made a custom chat, and I made it to recognize commands by using if string.sub(guiGetText(chatGUI),1,1) == "/" then It's all good, but then I can't get the arguments server side. Like when I type /mute Player12 30, I don't know how to seperate them, in 2 arguments. I just need a little help to get started with. Link to comment
Overkillz Posted January 12, 2018 Share Posted January 12, 2018 function yourFunctionName (thePlayer,cmd,argument1,argument2) -- Your Code end addCommandHandler ("mute",yourFunctionName) Link to comment
Moderators IIYAMA Posted January 12, 2018 Moderators Share Posted January 12, 2018 If using a gui, use this to split: https://wiki.multitheftauto.com/wiki/Split And for using commands. The addCommandHandler function automatic splits arguments when passed over to the attached function. See examples: https://wiki.multitheftauto.com/wiki/AddCommandHandler Link to comment
Fist Posted January 12, 2018 Share Posted January 12, 2018 I made a while ago custom command handler for normal chat, but you can easily remake it for your chat. https://community.multitheftauto.com/index.php?p=resources&s=details&id=14380 Link to comment
ShayF2 Posted January 12, 2018 Share Posted January 12, 2018 Try something like this. -- NOTE This code is not tested and may need to be edited to work properly. local symbol = '/' local commands = { 'help', 'commands' } addEventHandler('onPlayerChat',root,function(message) local textTable = split(message,' ') for k=1,#textTable do for l=1,#commands do if textTable[1] == symbol..commands[l] then table.remove(textTable,1) triggerEvent(commands[l],root,source,textTable) end end end end) for i=1,#commands do addEvent(commands[i]) end addEventHandler('help',root,function(source,payload) outputChatBox('Use /commands for a list of commands.',source) end) addEventHandler('commands',root,function(source,payload) outputChatBox('Commands: '..table.concat(commands,', '),source) end) 1 Link to comment
DREFTHUN Posted January 29, 2018 Author Share Posted January 29, 2018 Thank you IIYAMA! Your reply was helpful! ShayF Yeah, it's good, but when I want to type like /mute DREFTHUN 34 that script won't seperate the arguments. Anyway, thanks! I'm all good now. Link to comment
ShayF2 Posted January 29, 2018 Share Posted January 29, 2018 You can make it do what you want. 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