Can't believe its taken me this long to register here, been using and working with ULX off and on since the first version all those years ago. I figured now would be as good a time as any considering I have some code I don't mind releasing. Recently, someone on facepunch
requested a way to restrict certain weapons to certain groups in Trouble in terrorist town, and I coded something that allows for this functionality without the need to modify base TTT files (unless you want to restrict some of the default weapons).
Place this code in any lua file contained in the lua/autorun/ directory on the server.
if SERVER then
AddCSLuaFile();
else
local oWeaponsGetList = weapons.GetList;
function weapons.GetList()
local tbl = oWeaponsGetList();
local grp = LocalPlayer():GetUserGroup();
--Modify weapons.GetList() returned results if it's called by cl_equip.lua's GetEquipmentForRole function
--Based on the LocalPlayer's ULX group
if( string.find( tostring( debug.traceback() ), "GetEquipmentForRole" ) != nil ) then
for k,v in pairs( tbl ) do
if( v and v.CanBuy ) then
if( v.GroupOnly and v.Groups ) then
if( !table.HasValue( v.Groups, grp ) ) then
table.remove( tbl, k );
end
end
end
end
end
return tbl;
end
end
Then, just add this code to any weapon you want to be restricted to a group.
SWEP.GroupOnly = true;
SWEP.Groups = {"vip", "admin", "someothergroup"};
I figured it would be a good idea to post this script here so that it's not lost in the facepunch archives, and anyone wanting something like this could hopefully find it here easily.