ULX

Author Topic: How would you add extra 'Global' targets  (Read 2889 times)

0 Members and 1 Guest are viewing this topic.

Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
How would you add extra 'Global' targets
« on: July 28, 2012, 11:34:05 PM »
When your using ulx commands you can use things like ^ (to target yourself), * (to target everyone) and I'm pretty sure you can use % to target groups (e.g %admin)

Is there a way to add extra stuff to this?
For example "!slap &" (which could only target alive players).
« Last Edit: July 28, 2012, 11:51:10 PM by iSnipeu »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: How would you add extra 'Global' targets
« Reply #1 on: July 29, 2012, 05:34:37 AM »
When your using ulx commands you can use things like ^ (to target yourself), * (to target everyone) and I'm pretty sure you can use % to target groups (e.g %admin)

Is there a way to add extra stuff to this?
For example "!slap &" (which could only target alive players).

You certainly can. Just edit the ULib.getUsers and ULib.getUser functions in ulib/lua/ulib/shared/player.lua. The first function is used in cases where multiple targets are expected (eg, slap). The second function is used where only one target is expected (eg, ban). You'll only need to to add the relevant "elseif" case in each of these functions... you shouldn't need to edit any other pieces.

Be sure to let us know what additions you make, we'd love to hear about them.
Experiencing God's grace one day at a time.

Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
Re: How would you add extra 'Global' targets
« Reply #2 on: July 30, 2012, 12:57:35 AM »
Thanks!
I've currently added # - this will only target alive players, you can use !# to target dead players

Here is the code if anyone wants it.

Remember this is in ulib/lua/ulib/shared/player.lua in the ULib.getUsers function @ line 109
Code: [Select]
if piece == "*" then -- All!
table.Add( tmpTargets, players )
elseif piece == "^" then -- Self!
if ply then
table.insert( tmpTargets, ply )
end
elseif piece == "#" then -- Alive players!
for _, pl in ipairs( players ) do
if pl:Team() != 1002 and pl:Alive() then
table.insert( tmpTargets, pl )
end
end
elseif piece == "@" then
if ply and ply:IsValid() then
local player = ULib.getPicker( ply )
if player then
table.insert( tmpTargets, player )
end
end
« Last Edit: July 31, 2012, 12:04:32 AM by iSnipeu »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: How would you add extra 'Global' targets
« Reply #3 on: July 30, 2012, 03:59:22 PM »
iSnipeu, you don't need to explicitly handle the "not" cases, that is "!#" and "!^". This is already being handled in the functions automagically. You only need to code the positive logic. :)
Experiencing God's grace one day at a time.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: How would you add extra 'Global' targets
« Reply #4 on: July 30, 2012, 08:49:32 PM »
Meg, would our functions specifically target non-alive players though?
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
Re: How would you add extra 'Global' targets
« Reply #5 on: July 31, 2012, 12:05:39 AM »
iSnipeu, you don't need to explicitly handle the "not" cases, that is "!#" and "!^". This is already being handled in the functions automagically. You only need to code the positive logic. :)

Fixed it, I completely forgot about that.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: How would you add extra 'Global' targets
« Reply #6 on: July 31, 2012, 04:58:42 AM »
Meg, would our functions specifically target non-alive players though?


It's a general case to inverse the selection. The set operation is just (all players) - (positive selection) within the bounds of who you're allowed to target.
Experiencing God's grace one day at a time.