ULX

Author Topic: TTT - Group Restricted Weapons  (Read 6741 times)

0 Members and 2 Guests are viewing this topic.

Offline looter

  • Newbie
  • *
  • Posts: 1
  • Karma: 3
TTT - Group Restricted Weapons
« on: August 26, 2013, 01:25:26 PM »
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.
Code: [Select]
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.
Code: [Select]
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.

Offline thetomm2010

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: TTT - Group Restricted Weapons
« Reply #1 on: September 19, 2013, 02:20:24 PM »
is this for the T and D shop?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: TTT - Group Restricted Weapons
« Reply #2 on: September 19, 2013, 04:09:08 PM »
Thanks looper, and welcome to the community as more than a lurker.
:)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming