ULX

Author Topic: ULX XGUI commands: Dynamic drop down?  (Read 5650 times)

0 Members and 1 Guest are viewing this topic.

Offline lynx

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 15
ULX XGUI commands: Dynamic drop down?
« on: February 25, 2014, 01:55:27 AM »
I know that's probably not the most descriptive of titles, but I can't think of a better way to explain it.

I'm currently coding a ULX Pointshop administration system (to give, take, set points) and would like to also set up a way to take items the player has.

Basic code structure for this would be like this:

Code: [Select]
function ulx.pointshop_takeitem( calling_ply, target_plys, item )

if !PS then
ULib.tsayError( calling_ply, "Pointshop is not loaded. Cannot set points.", true )
return
end

if !PS.Items[item] then
ULib.tsayError( calling_ply, "Cannot take item. Item \""..item.."\" invalid.", true )
return
end

for k,v in pairs( target_plys ) do
if v:PS_HasItem(item) then
v:PS_TakeItem(item)
else
table.remove(target_plys,k)
ULib.tsayError( calling_ply, v:Name().." does not have "..item.."!", true )
end
end

ulx.fancyLogAdmin( calling_ply, "#A took a #s from #T", item, target_plys )

end
local pointshop_takeitem = ulx.command( "Pointshop", "ulx takeitem", ulx.pointshop_giveitem, "!takeitem" )
pointshop_takeitem:addParam{ type=ULib.cmds.PlayersArg }
pointshop_takeitem:addParam{ type=ULib.cmds.StringArg, hint="item", completes=ulx.pointshop_item_list }
pointshop_takeitem:defaultAccess( ULib.ACCESS_SUPERADMIN )
pointshop_takeitem:help( "Takes away the target player(s) access to the specified pointshop item, forcing them to rebuy it." )

Code has checks for pointshop validity, item validity, and checks if the player has it before actually removing it. If the admin knows the item ID, thats all fine and dandy. And ulx.pointshop_item_list gives a sorted list, by category, of the items. But that shows all the items, and in some cases (such as a server with numerous models/hats/etc) that could be a big problem. What's nice about Pointshop is that it stores all item data for a player in a SHARED table linked to the player object. So, you could easily call Player(30).PS_Items to get the table of items, if it's equipped, and the various modifications they have set.

The problem with this is that I don't know how, if at all possible, to have this bit of code query the players data after they have been selected:
Code: [Select]
pointshop_takeitem:addParam{ type=ULib.cmds.StringArg, hint="item", completes=ulx.pointshop_item_list }
The question is now: is there a way to make what I am thinking of possible? I know I could add the commands, and modify the pointshop system to use Player:query("ulx takeitem") to see if they have access and allow them to use the pointshop admin menu, I just want to try to make a fully ULX solution without needing to edit the Pointshop menu or create a new menu that pops up to populate items in a DermaMenu or something.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ULX XGUI commands: Dynamic drop down?
« Reply #1 on: February 25, 2014, 06:20:37 AM »
This is a question for Stickly Man. I'll point him toward this thread.
Experiencing God's grace one day at a time.

An Error Has Occurred!

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