General > Developers Corner
How would you add extra 'Global' targets
iSnipeu:
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).
Megiddo:
--- Quote from: 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).
--- End quote ---
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.
iSnipeu:
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: --- 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
--- End code ---
Megiddo:
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. :)
JamminR:
Meg, would our functions specifically target non-alive players though?
Navigation
[0] Message Index
[#] Next page
Go to full version