• Print

Author Topic: Command Confusion  (Read 13327 times)

0 Members and 1 Guest are viewing this topic.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Command Confusion
« on: August 03, 2010, 07:38:40 am »
I am being confused by how I should go about making a console and chat command.
How should I? I've had a look at the documentation, but it just confuses me. Please explain the best mothod.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command Confusion
« Reply #1 on: August 03, 2010, 08:33:29 am »
Assuming SVN, the simplest "traditional" approach is to use ULib.cmds.addCommand. If you want autocompletion for subcommands (see example), you'll need to execute that function on both server and client, otherwise just server is fine.

Otherwise, to get per argument restrictions and to have the input translated for your function, you want to use ULib.cmds.TranslateCommand:instantiate along with addParam on the object returned from instantiate. If you want to make a command like slap, it would be something like this...

Code: Lua
  1. function mySlap( calling_ply, target_plys, damage )
  2.     for i=1, #target_plys do
  3.         print( calling_ply .. " slapped " .. target_plys[ i ] )
  4.         -- Perform slap logic
  5.     end
  6. end
  7. local slap = ULib.cmds.TranslateCommand:instantiate( "myslap", mySlap, "!myslap" )
  8. slap:addParam{ type=ULib.cmds.CallingPlayerArg } -- First param to the function is the player calling slap
  9. slap:addParam{ type=ULib.cmds.PlayersArg } -- Second param is the target player(s)
  10. slap:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="damage", ULib.cmds.optional, ULib.cmds.round } -- Third return is an optional rounded number for damage, minimum 0 and default 0. The hint is for autocomplete.
  11. slap:defaultAccess( ULib.ACCESS_ADMIN ) -- Who has access by default.

Does this help clear things up for you?
Experiencing God's grace one day at a time.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #2 on: August 03, 2010, 12:27:08 pm »
Yes, thank you, it has really cleared things up.
« Last Edit: August 03, 2010, 12:32:47 pm by EMB »

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #3 on: August 17, 2010, 06:15:18 am »
Ugh, now it wont recognise my second parameter...

What is wrong with this?
Code: [Select]
imitate:addParam{ type=ULib.cmds.StringArg } -- Second param is the string to use

BTW, not going to be here for the next two weeks, but i'd thought i'd throw this question out there anyway.
« Last Edit: August 17, 2010, 06:18:09 am by EMB »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command Confusion
« Reply #4 on: August 17, 2010, 09:21:19 am »
What do you mean won't recognize?
Experiencing God's grace one day at a time.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #5 on: September 02, 2010, 08:11:24 am »
It throws up an error when trying to load the module, something about it needing to be a function.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command Confusion
« Reply #6 on: September 02, 2010, 11:22:07 am »
Need the exact error.
Experiencing God's grace one day at a time.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #7 on: September 03, 2010, 01:33:14 pm »
It says on that line, a function is expected.
Will get the exact error when I remember.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #8 on: September 15, 2010, 12:43:19 pm »
bad argument #2 to ULib.cmds.TranslateCommand (function expected)

There, the exact error, now can I please have some help? It's annoying not knowing what has gone wrong.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command Confusion
« Reply #9 on: September 15, 2010, 12:49:43 pm »
You're not passing a function in to argument two when a function is expected.
Experiencing God's grace one day at a time.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #10 on: September 15, 2010, 12:54:44 pm »
...
I'm not a dumbass, what is wrong with the code?

imitate:addParam{ type=ULib.cmds.StringArg } -- Second param is the string to use

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command Confusion
« Reply #11 on: September 15, 2010, 02:43:01 pm »
It's not that part of your code that's the problem, it's when you're calling TranslateCommand.
« Last Edit: September 15, 2010, 02:46:41 pm by Megiddo »
Experiencing God's grace one day at a time.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #12 on: September 16, 2010, 09:08:14 am »
Code: [Select]
-- To imitate a player speaking.
-- Made by EMB

-- The actual function
function UImitate( target_plys, stuff_say )
   for i=1, #target_plys do -- For every player
        target_plys[ i ]:concommand( "say " .. stuff_say ) -- Make the person say it
   end
end

-- Add the command
local imitate = ULib.cmds.TranslateCommand:instantiate( "ulx imitate", UImitate, "!im", true )
imitate:addParam{ type=ULib.cmds.PlayersArg } -- First param is the target player(s)
imitate:addParam{ type=ULib.cmds.StringArg } -- Second param is the string to use
imitate:defaultAccess( ULib.ACCESS_OWNER ) -- Who has access by default.

What is wrong?
« Last Edit: September 19, 2010, 03:15:28 am by EMB »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Command Confusion
« Reply #13 on: September 16, 2010, 10:39:50 am »
You haven't defined the function, you need to have a function to call back.
Experiencing God's grace one day at a time.

Offline EMB

  • Newbie
  • *
  • Posts: 26
  • Karma: 0
Re: Command Confusion
« Reply #14 on: September 16, 2010, 12:52:12 pm »
Wut?

  • Print