Ulysses

General => Developers Corner => Topic started by: iSnipeu on July 28, 2012, 11:34:05 PM

Title: How would you add extra 'Global' targets
Post by: iSnipeu 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).
Title: Re: How would you add extra 'Global' targets
Post by: Megiddo 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.
Title: Re: How would you add extra 'Global' targets
Post by: iSnipeu 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
Title: Re: How would you add extra 'Global' targets
Post by: Megiddo 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. :)
Title: Re: How would you add extra 'Global' targets
Post by: JamminR on July 30, 2012, 08:49:32 PM
Meg, would our functions specifically target non-alive players though?
Title: Re: How would you add extra 'Global' targets
Post by: iSnipeu 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.
Title: Re: How would you add extra 'Global' targets
Post by: Megiddo 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.