• Print

Author Topic: Running ULX console commands properly.  (Read 7302 times)

0 Members and 1 Guest are viewing this topic.

Offline Jonas Præstegaard

  • Newbie
  • *
  • Posts: 6
  • Karma: 3
Running ULX console commands properly.
« on: June 08, 2016, 12:52:19 am »
Hey everyone.

I'm trying to make my admins run certain commands using a menu. As party of the menu, I have something like this:

Code: [Select]
RunConsoleCommand("ulx","slay",tar:Name())
That works, but the problem is, sometimes it doesn't. Sometimes it will target multiple people with similar names, other times it wont be able to find any target(s).

ULX doesn't seem to support targeting via SteamID, so is there any other way to target a specific player, using Lua-run console commands?

Any help is appreciated :D

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Running ULX console commands properly.
« Reply #1 on: June 08, 2016, 03:55:21 am »
I'm guessing here, as I don't really know for sure, but try using tar:Nick() instead. Just a thought and it usually works better than Name(). I could be wrong though, worth a shot
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Running ULX console commands properly.
« Reply #2 on: June 08, 2016, 04:52:29 am »
Don't run a console command, just call the function itself.

Code: Lua
  1. ulx.slay( admin, target)

Changing tar:Name() to tar:Nick() will not change anything as they're exactly the same. Player:Name() is just an alias for Player:Nick().

EDIT:

Thinking about this a bit more, I'm not sure the command's function will exist client-side. I'm going to check out XLIB/XGUI's source and see how it targets players, and then report back to you.\

It looks like XGUI uses ULib.getUniqueIDForPlayer( ply ). I'm not exactly sure what the player's UniqueID is (I don't think it's the same as Garry's UniqueID), but apparently you can use it as the player argument. Hopefully a Ulysses dev can explain more.
« Last Edit: June 08, 2016, 06:26:59 am by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Jonas Præstegaard

  • Newbie
  • *
  • Posts: 6
  • Karma: 3
Re: Running ULX console commands properly.
« Reply #3 on: June 08, 2016, 07:20:46 am »
Thanks roastchicken

I would indeed love to hear from a dev regarding UniqueIDs. If targeting via console command using UniqueID is not possible, then I suppose I'd have to do some net message jumble...

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: Running ULX console commands properly.
« Reply #4 on: June 08, 2016, 07:24:29 am »
I believe unique ID is the position of a certain player in a table of connected players. I don't know even if that's right or if you'd be able to get to it.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Running ULX console commands properly.
« Reply #5 on: June 08, 2016, 10:09:48 am »
ULX does support targeting by any type of IDs you like using the '$' operator:
Quote from: ULX Help
... '$<userid>' to target by ID (steamid, uniqueid, userid, ip) ...

So, something like the following should work:
Code: Lua
  1. RunConsoleCommand("ulx","slay", "$" .. tar:SteamID())

However, if someone else were to set their name to be (for example) "$STEAM_0:1:<your_steam_id>", this would still cause a conflict. This is where ULib.getUniqueIDForPlayer( ply ) comes in. It's not really clear, but this function basically returns any type of a player's ID that does not conflict with another player's name or ID. It will return one of the following (I think in this order): UniqueID, IP address, SteamID, or UserID (seen in sv_status). As noted in the docs, this data is best fed into ULib.getUser(s), or into the $ operator in a targeting string.

So, to use that in your example would look like this:
Code: Lua
  1. RunConsoleCommand("ulx","slay", "$" .. ULib.getUniqueIDForPlayer(tar))

One final note, the reason why you're getting a lot of conflicts with names and multiple targets found might have to do with RunConsoleCommand and splitting args on spaces- Due to how ULX commands are set up, you might have to split the name by spaces, then pass each segment as an additional argument to RunConsoleCommand.
« Last Edit: June 08, 2016, 10:17:02 am by Stickly Man! »
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Running ULX console commands properly.
« Reply #6 on: June 08, 2016, 11:00:12 am »
Thanks for the info Stickly Man!

I hadn't thought about names with spaces, it makes sense that they might mess up with RunConsoleCommand.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

  • Print