Author Topic: A new option for PlayerArg and PlayersArg  (Read 4007 times)

0 Members and 3 Guests are viewing this topic.

Offline markusmarkusz

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
A new option for PlayerArg and PlayersArg
« on: November 13, 2016, 06:26:59 AM »
It would be very nice to have a option that can be used to restrict PlayerArg and PlayersArg to players which fit some things.
Example:
I have a respawn Command. Let's called it ulx respawn.
And I want it that you can only target players that are dead.
So that users where Player:Alive() returns false aren't displayed.
Something like:
Code: [Select]
local function targets()
local pl = {}
for k,v in pairs(player.GetAll()) do
if not v:Alive() then table.insert(pl, v) end
end
return pl
end
function ulx.respawn( calling_ply, target_ply)
target_ply:Spawn()
ulx.fancyLogAdmin( calling_ply, "#A respawned #T", affected_plys, dmg )
end
local respawn = ulx.command("Util", "ulx respawn", ulx.respawn, "!respawn" )
respawn:addParam{ type=ULib.cmds.PlayerArg, autocomplete_fn=targets }
respawn:defaultAccess(ULib.ACCESS_ADMIN)
respawn:help( "Respawns target." )

If this is already possible and I just missed something, then tell me what.
Thanks.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: A new option for PlayerArg and PlayersArg
« Reply #1 on: November 13, 2016, 09:24:22 AM »
Well, for starters, it looks like you've copied a template for another command without modifying it to suit your needs.

Your call to fancyLogAdmin uses two undefined variables, affected_plys and dmg (which looks similar to ulx.slap). Instead of those, just use target_ply.

Second off, using autocomplete to hide targets doesn't mean they can't go outside of the bounds you set (IIRC). You would still need to have checks in your code which determine if the targeted player is dead, which rather defeats the purpose.
bw81@ulysses-forums ~ % whoami
Homepage

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given