Ulysses Stuff > Suggestions

A new option for PlayerArg and PlayersArg

(1/2) > >>

markusmarkusz:
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: ---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." )
--- End code ---

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

Bytewave:
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.

An Error Has Occurred!

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

[0] Board index

Go to full version