I've been experiencing a lot of problems when interpreting the name of the item to get the id, this is going to become impossible if i use the LANG.TryTranslation(name) to convert the string into the actual name for the item, so for the users i want them to see the name but for the command i need the id. Any ideas how to accomplish this?
Current code for help.
--[Ulx Completes]------------------------------------------------------------------------------
ulx.get_equipment = {}
function GetEquipment()
table.Empty( ulx.get_equipment )
for role, _ in pairs(EquipmentItems) do
for _, item in pairs(EquipmentItems[role]) do
if not table.HasValue(ulx.get_equipment, tostring(item.name)) then
table.insert(ulx.get_equipment, tostring(item.name))
end
end
end
end
hook.Add( "Initialize", "ULXGetEquipment", GetEquipment )
hook.Add( ULib.HOOK_UCLCHANGED, "ULXGetEquipment", GetEquipment )
--[End]----------------------------------------------------------------------------------------
--[Toggle spectator]---------------------------------------------------------------------------
--[[ulx.spec][Forces <target(s)> to and from spectator.]
@param {[PlayerObject]} calling_ply [The player who used the command.]
@param {[PlayerObject]} target_plys [The player(s) who will have the effects of the command applied to them.]
--]]
function ulx.equipment( calling_ply, target_plys, equipment )
if GamemodeCheck(calling_ply) then return end
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]
local match = FindEquipmentMatch(name, equipment, id )
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
elseif GetRoundState() == 1 or GetRoundState() == 2 then
ULib.tsayError( calling_ply, "The round has not begun!", true )
elseif not v:Alive() then
ULib.tsayError( calling_ply, v:Nick() .. " is dead!", true )
elseif not match and v:HasEquipmentItem(FindEquipmentMatch(name, equipment, id )) then
ULib.tsayError( calling_ply, v:Nick() .. " already has that equipment!", true )
else
local match = FindEquipmentMatch(name, equipment, id )
if match then
v:GiveEquipmentItem(match)
GiveEquipmentWeapon(v:UniqueID(), match)
end
table.insert( affected_plys, v )
end
end
ulx.fancyLogAdmin( calling_ply, "#A gave #T " .. equipment, affected_plys)
end
local equipment = ulx.command( CATEGORY_NAME, "ulx give equipment", ulx.equipment )
equipment:addParam{ type=ULib.cmds.PlayersArg }
equipment:addParam{ type=ULib.cmds.StringArg, completes=ulx.get_equipment, hint="Equipment", error="Invalid equpiment:\"%s\" specified", ULib.cmds.restrictToCompletes }
equipment:defaultAccess( ULib.ACCESS_SUPERADMIN )
equipment:help( "Give <target(s)> specified equpiment." )
--[Helper Functions]---------------------------------------------------------------------------
function FindEquipmentMatch(type, equipment, return_type )
for role, _ in pairs(EquipmentItems) do
for _, item in pairs(EquipmentItems[role]) do
if equipment == item[type] then
return item[return_type]
else
return false
end
end
end
end
--[End]----------------------------------------------------------------------------------------
Would it be possible to define ulx.get_equipment as
ulx.get_equipment = {["name"] = {}, ["id"] ={} }
then set the autocomplete table to ulx.get_equipment.name?
I can't think of any other way to pass the id aswell.