General > Developers Corner

ULX Commands

<< < (3/6) > >>

Megiddo:
Unfortunately ULX isn't documented as well as ULib. You need to return true from the function in the event of success, otherwise ULX assumes that there was something wrong with the input (trying to jail a ragdoll, etc).

Tested with return true:

--- Quote ---[ULX]Megiddo: !warn me one two
You warned yourself for one two
--- End quote ---

JamminR:
Megiddo, thanks for confirming. I'd thought that was the case but wasn't sure. I remembered <command object>:<Ulib.mds.*> checking for success, but had forgotten how it went about doing that.

Aaron113, do you understand how the addparam work with the "completes" variable table suggestions from the rate code I showed?
I can write a longer bit of example command code with comments if needed.

Aaron113:

--- Quote from: JamminR on November 07, 2010, 01:08:56 PM ---Aaron113, do you understand how the addparam work with the "completes" variable table suggestions from the rate code I showed?
I can write a longer bit of example command code with comments if needed.

--- End quote ---
A longer version would be nice.  I haven't had time to try anything since you posted before.

JamminR:
Here's code including 'suggestions' for autocomplete of your warning system.
I've not tested it.


--- Code: ---local CATEGORY_NAME = "Custom"
-- Set table for autocomplete suggestions.
my_warn_reasons = { "Spamming", "Rude", "Language", "Arguing with a mod", "Prop Killing" }
-- Set your function as normal
function ulx.warn( calling_ply, target_plys, Reason )
return true
end
-- set your command as normal
local warn = ulx.command( CATEGORY_NAME, "ulx warn", ulx.warn, "!warn" )
warn:addParam{ type=ULib.cmds.PlayerArg }
-- Here, you deviate. You give addParam an additional table, "completes", set in previous table, "my_warn_reasons"
-- After you've typed "ulx warn <some player>" in console, the dropdown will contain the table. If you type the first
-- few letters of a word from the table (for instance, "S", "Spamming" would attempt to auto complete).
warn:addParam{ type=ULib.cmds.StringArg, hint="reason", completes=my_warn_reasons, ULib.cmds.takeRestOfLine }
warn:defaultAccess( ULib.ACCESS_ADMIN )
warn:help( "Warn a player." )
warn:logString( "#1s warned #2s for #3s" )
--- End code ---

See http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.StringArg
According to that, the following apply with ULib.cmds.StringArg
"hint" = Gives hint as part of error (if error not overridden)
"completes" = Table of strings to be used as auto complete in option.
"ULib.cmds.restrictToCompletes" - Obvious, allow only what is given in "completes" as input.
or
"ULib.cmds.takeRestOfLine" - Obvious, take rest of line
"error" = Allow overriding the default command object error (allows for customization)
"autocomplete_fn" = Allow override of the default ULib autocomplete function.
"repeat_min", combined with "ULib.cmds.takeRestOfLine", from the description at our docs site, well, I'm not fully sure what it is myself.

Megiddo, explain repeat_min in a different way than stated at ulib docs?

Megiddo:
I think hint is just used for autocomplete and command syntax. Repeat min ensures that an argument is repeated at least n times (and also states that it CAN be repeated). This was mainly added for XGUI's benefit, but it's useful for ULX as well.

For example:
vote:addParam{ type=ULib.cmds.StringArg, hint="options", ULib.cmds.takeRestOfLine, repeat_min=2, repeat_max=10 }

That's a line from the ulx vote definition. It makes sure that there are at least 2 options given, and a maximum of 10. (I need to document repeat_max :P)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version