Author Topic: Command with all parameters optional  (Read 2609 times)

0 Members and 3 Guests are viewing this topic.

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Command with all parameters optional
« on: May 27, 2020, 04:50:59 AM »
Hello everyone, long time no see

I am currently running into a issue with ULX where I created a command with all parameters being optional ( the first one is a optional player parameter ), but when the console uses the command without parameters it doesn't even attempt to run the function, as the player parameter gets run trough "ulx.getUniqueIDForPlayer", which causes a error as the console is ( you guessed it ) not a player. Here is the lua error:

Code: [Select]
[ERROR] addons/ulib/lua/ulib/shared/player.lua:121: Tried to use a NULL entity!
  1. indexFn - [C]:-1
   2. getUniqueIDForPlayer - addons/ulib/lua/ulib/shared/player.lua:121
    3. parseAndValidate - addons/ulib/lua/ulib/shared/commands.lua:515
     4. __fn - addons/ulib/lua/ulib/shared/commands.lua:916
      5. execute - addons/ulib/lua/ulib/shared/commands.lua:1323
       6. unknown - addons/ulib/lua/ulib/shared/commands.lua:1351
        7. unknown - lua/includes/modules/concommand.lua:54

My question is if there is something I can do without injecting into ULX code ( which I really want to avoid ) ?
Is there some kind of hidden parameter that I don't know yet which isn't documented?

Example:
Code: [Select]
    local exampleFunction = function(calling_ply, target_ply)
        -- It doesn't even go in here
    end
    local exampleCommand= ulx.command( "Example", "example_command", exampleFunction, "!example" )
    exampleCommand:addParam{ type=ULib.cmds.PlayerArg, hint="player", ULib.cmds.optional}
    exampleCommand:defaultAccess( ULib.ACCESS_SUPERADMIN )
    exampleCommand:help( "Example command to demonstrate how the console will not be able to run this command without parameters" )

Now when you run this command "example_command" from the console without parameters, you will recieve a error message and the command function won't be executed at all.

If you know a solution, I am happy to hear about it.

Thank you for reading my rambling,
~cap
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Command with all parameters optional
« Reply #1 on: May 27, 2020, 07:25:34 PM »
Best comparison to look would be ulx noclip.
It uses isValid to check target ply.
Ends if console.
https://github.com/TeamUlysses/ulx/blob/a8b31ffb3ec6ae1e7bbcea35019312d1b2ca52e1/lua/ulx/modules/sh/util.lua#L172
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: Command with all parameters optional
« Reply #2 on: May 27, 2020, 09:11:28 PM »
Best comparison to look would be ulx noclip.
It uses isValid to check target ply.
Ends if console.
https://github.com/TeamUlysses/ulx/blob/a8b31ffb3ec6ae1e7bbcea35019312d1b2ca52e1/lua/ulx/modules/sh/util.lua#L172


Thats what I tried to do, but the function doesnt even get executed, it errors out before even attempting to run the function, and if it doesn't open the function I am also unable to add a check for it
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Command with all parameters optional
« Reply #3 on: May 28, 2020, 10:47:52 AM »
On issue tracker: https://github.com/TeamUlysses/ulib/issues/36

This error was patched, but hasn't made it in the latest ULib release yet.

The latest dev build will show a "target must be specified" validation error instead.

It looks like optional Player(s)Arg types are currently not supported from the server console.

No straightforward way to solve this without modifications to the ULib source... A custom PlayerArg comes to mind.