cyklopas Posted October 21, 2010 Share Posted October 21, 2010 (edited) Well, whoever is familiar to Roleplay, must know what "/do" is used for. So yeah. It's my first normal script. And whoever doesn't know what /my command does, I'll explain you... For example your nickname is Doctor. You type /my balls are big. And here comes the screen: *Doctor's balls are big. Thanks for downloading and helping the project. Version 1.0 DOWNLOAD: Here. Version 2.0 DOWNLOAD: Here. Changelog: Version 2.0- Added the /my command. Thanks to: Me- the main idea. ThaCoinz- Bug Fixing Edited October 21, 2010 by Guest Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 why on console command not with addCommandHandler ? Link to comment
cyklopas Posted October 21, 2010 Author Share Posted October 21, 2010 Because it works this way too. Link to comment
dzek (varez) Posted October 21, 2010 Share Posted October 21, 2010 addCommandHandler seems to be much simplier and using "/do" in chatbox instead of "do" in console will work? im not sure about this so im asking Link to comment
cyklopas Posted October 21, 2010 Author Share Posted October 21, 2010 addCommandHandler seems to be much simplierand using "/do" in chatbox instead of "do" in console will work? im not sure about this so im asking It will Link to comment
eAi Posted October 21, 2010 Share Posted October 21, 2010 We've always recommended _not_ using onConsole for this. addCommandHandler is both easier and more secure as you can easily secure console commands from being used through the ACL, plus write much less code. This is a very silly way to do it. Your code: function input_Console ( text ) local command = gettok (text, 1, 32 ) if ( command == "my" ) then local playerName = getPlayerName ( source ) local actionText = string.sub ( text, 3 ) outputChatBox ( " *" .. playerName .. "'s" .. actionText .. " ", root, 255, 40, 80, true ) end end addEventHandler ( "onConsole", getRootElement(), input_Console ) How it should be done: function myCommand( playerSource, commandName, ...) local actionText = table.concat( arg, " " ) local playerName = getPlayerName ( playerSource ) outputChatBox ( " *" .. playerName .. "'s" .. actionText .. " ", root, 255, 40, 80, true ) end addCommandHandler("my", myCommand) Link to comment
cyklopas Posted October 21, 2010 Author Share Posted October 21, 2010 We've always recommended _not_ using onConsole for this. addCommandHandler is both easier and more secure as you can easily secure console commands from being used through the ACL, plus write much less code.This is a very silly way to do it. Your code: function input_Console ( text ) local command = gettok (text, 1, 32 ) if ( command == "my" ) then local playerName = getPlayerName ( source ) local actionText = string.sub ( text, 3 ) outputChatBox ( " *" .. playerName .. "'s" .. actionText .. " ", root, 255, 40, 80, true ) end end addEventHandler ( "onConsole", getRootElement(), input_Console ) How it should be done: function myCommand( playerSource, commandName, ...) local actionText = table.concat( arg, " " ) local playerName = getPlayerName ( playerSource ) outputChatBox ( " *" .. playerName .. "'s" .. actionText .. " ", root, 255, 40, 80, true ) end addCommandHandler("my", myCommand) Many thanks, mate Link to comment
eAi Posted October 21, 2010 Share Posted October 21, 2010 Read the addCommandHandler wiki page for many more examples. Link to comment
cyklopas Posted October 21, 2010 Author Share Posted October 21, 2010 Read the addCommandHandler wiki page for many more examples. Yeah, I can see that. Thanks for the info. I'll use more of these in future. Link to comment
razvan2299 Posted June 28, 2015 Share Posted June 28, 2015 Can you add a syntax if only "/my" is written? 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