• Coding ULX Usergroup-Specific TTT Detective/Traitor Weapons
    28 replies, posted
I would like to know if it is possible to have a SWEP that only shows up in the detective menu depending on the player's ULX user group. For example, if a regular detective goes into the shop, he/she will not be able to buy the taser weapon unless their usergroup is set to superadmin.
I believe you have to edit the TTT base as well as the weapon but I am not sure. I have been trying to find a way for this for ages and I was thinking if I could, release it for free or on coderhire for about 5-10USD. But only if I made it of course.
In shared.lua for the weapon try something like [lua]if not Owner:IsUserGroup("Group") then return end else SWEP.CanBuy = { ROLE_TRAITOR } end [/lua] I honestly don't know if this would work, especially since the owner might not have been defined before the weapon is bought, but its worth a shot and this might help you figure it out at least.
Doesn't work. [CODE][ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:24: '<eof>' expected near 'end' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0[/CODE]
[QUOTE=capnsparrow;41737035]In shared.lua for the weapon try something like [lua]if not Owner:IsUserGroup("Group") then return end else SWEP.CanBuy = { ROLE_TRAITOR } end [/lua] I honestly don't know if this would work, especially since the owner might not have been defined before the weapon is bought, but its worth a shot and this might help you figure it out at least.[/QUOTE] LOL WRONG MAZAFAKER!Siriously its wrong.Here is normal code [CODE]if not Owner:IsUserGroup("Group") then return "" else SWEP.CanBuy = { ROLE_TRAITOR } end[/CODE]
[CODE][ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:86: 'end' expected (to close 'function' at line 82) near '<eof>' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0[/CODE] Doesn't work....
try [CODE]if self.owner:IsUserGroup("Group") then SWEP.CanBuy = { ROLE_TRAITOR } else return end[/CODE] and post your 82 string with that fucntion
[lua]if self.owner:IsUserGroup("X") then SWEP.CanBuy = {ROLE_TRAITOR} else return end[/lua] idunno 4 am coding. dunno why they do it that way [editline]7th August 2013[/editline] fuck airblack
[QUOTE=zerothefallen;41743369][lua]if ply:IsUserGroup("X") then SWEP.CanBuy = {ROLE_TRAITOR} else return end[/lua] idunno 4 am coding. dunno why they do it that way [editline]7th August 2013[/editline] fuck airblack[/QUOTE] LOL Im first
Since your using ULX and checking for ULX groups, use [url=http://ulyssesmod.net/docs/files/lua/ulib/shared/sh_ucl-lua.html#Player:CheckGroup]Player:CheckGroup[/url] as it checks the group chain as well, from the wiki: [QUOTE=UCL Wiki;0] This function is similar to IsUserGroup(), but this one checks the UCL group chain as well. For example, if a user is in group “owner” which inherits from “superadmin”, this function will return true if you check the user against “superadmin”, where IsUserGroup() wouldn’t. [/QUOTE]
As I am a newb sometimes but do I put this in a function or if CLIENT then or what? Just tried it then but I got this [CODE] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:84: 'end' expected (to close 'function' at line 80) near '<eof>' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0 [/CODE] also this is my code [CODE]if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "pistol" if CLIENT then SWEP.PrintName = "Bulk Magnum" SWEP.Slot = 1 SWEP.Icon = "VGUI/ttt/icon_ump" SWEP.ViewModelFOV = 72 SWEP.EquipMenuData = { type = "item_weapon", desc = "This is a fast powerful pistol!" }; SWEP.Base = "weapon_tttbase" SWEP.Kind = WEAPON_PISTOL SWEP.WeaponID = AMMO_BULK SWEP.LimitedStock = false SWEP.Primary.Damage = 35 SWEP.Primary.Delay = 0.2 SWEP.Primary.Cone = 0.02 SWEP.Primary.ClipSize = 6 SWEP.Primary.ClipMax = 36 SWEP.Primary.DefaultClip = 30 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "AlyxGun" SWEP.AutoSpawnable = false SWEP.AmmoEnt = "item_ammo_revolver_ttt" SWEP.Primary.Recoil = 3.3 SWEP.Primary.Sound = Sound( "weapons/lolt_shoot.wav" ) SWEP.UseHands = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 44 SWEP.ViewModel = "models/weapons/a_leee.mdl" SWEP.WorldModel = "models/weapons/b_leee.mdl" SWEP.HeadshotMultiplier = 4.5 -- brain fizz SWEP.IronSightsPos = Vector (-3.6515, -1.5076, 5.2519) SWEP.IronSightsAng = Vector (-1.2663, 0.0386, 0) SWEP.RunArmOffset = Vector (0.1534, 0, 5.8667) SWEP.RunArmAngle = Vector (-22.532, 0.7012, 0) SWEP.Speed = 0.7 SWEP.Mass = 0.9 /*--------------------------------------------------------- Name: SWEP:Precache() Desc: Use this function to precache stuff. ---------------------------------------------------------*/ function SWEP:Precache() util.PrecacheSound("weapons/brow_shoot.wav") end /*--------------------------------------------------------- Name: SWEP:ReloadAnimation() ---------------------------------------------------------*/ function SWEP:ReloadAnimation() if (self.Weapon:Clip1() == 0) then self.Weapon:SendWeaponAnim(ACT_VM_IDLE) local Animation = self.Owner:GetViewModel() Animation:SetSequence(Animation:LookupSequence("reload_noshoot")) else self.Weapon:SendWeaponAnim(ACT_VM_IDLE) local Animation = self.Owner:GetViewModel() Animation:SetSequence(Animation:LookupSequence("reload_noshoot")) end end function customcheck() if ply:IsUserGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end[/CODE]
[QUOTE=Sm63;41744425]As I am a newb sometimes but do I put this in a function or if CLIENT then or what? Just tried it then but I got this [CODE] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:84: 'end' expected (to close 'function' at line 80) near '<eof>' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0 [/CODE] also this is my code [CODE]if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "pistol" if CLIENT then SWEP.PrintName = "Bulk Magnum" SWEP.Slot = 1 SWEP.Icon = "VGUI/ttt/icon_ump" SWEP.ViewModelFOV = 72 SWEP.EquipMenuData = { type = "item_weapon", desc = "This is a fast powerful pistol!" }; SWEP.Base = "weapon_tttbase" SWEP.Kind = WEAPON_PISTOL SWEP.WeaponID = AMMO_BULK SWEP.LimitedStock = false SWEP.Primary.Damage = 35 SWEP.Primary.Delay = 0.2 SWEP.Primary.Cone = 0.02 SWEP.Primary.ClipSize = 6 SWEP.Primary.ClipMax = 36 SWEP.Primary.DefaultClip = 30 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "AlyxGun" SWEP.AutoSpawnable = false SWEP.AmmoEnt = "item_ammo_revolver_ttt" SWEP.Primary.Recoil = 3.3 SWEP.Primary.Sound = Sound( "weapons/lolt_shoot.wav" ) SWEP.UseHands = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 44 SWEP.ViewModel = "models/weapons/a_leee.mdl" SWEP.WorldModel = "models/weapons/b_leee.mdl" SWEP.HeadshotMultiplier = 4.5 -- brain fizz SWEP.IronSightsPos = Vector (-3.6515, -1.5076, 5.2519) SWEP.IronSightsAng = Vector (-1.2663, 0.0386, 0) SWEP.RunArmOffset = Vector (0.1534, 0, 5.8667) SWEP.RunArmAngle = Vector (-22.532, 0.7012, 0) SWEP.Speed = 0.7 SWEP.Mass = 0.9 /*--------------------------------------------------------- Name: SWEP:Precache() Desc: Use this function to precache stuff. ---------------------------------------------------------*/ function SWEP:Precache() util.PrecacheSound("weapons/brow_shoot.wav") end /*--------------------------------------------------------- Name: SWEP:ReloadAnimation() ---------------------------------------------------------*/ function SWEP:ReloadAnimation() if (self.Weapon:Clip1() == 0) then self.Weapon:SendWeaponAnim(ACT_VM_IDLE) local Animation = self.Owner:GetViewModel() Animation:SetSequence(Animation:LookupSequence("reload_noshoot")) else self.Weapon:SendWeaponAnim(ACT_VM_IDLE) local Animation = self.Owner:GetViewModel() Animation:SetSequence(Animation:LookupSequence("reload_noshoot")) end end function customcheck() if ply:IsUserGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end[/CODE][/QUOTE] LOL You're dumb forgot to close customcheck fuction [CODE]function customcheck() if ply:IsUserGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end END[/CODE]
try this. [lua] function customcheck() if ply:IsUserGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end [/lua] EDIT: Ohh same second we posted :D... well :)
[QUOTE=morten7000;41745014]try this. [lua] function customcheck() if ply:IsUserGroup("superadmin") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end [/lua] EDIT: Ohh same second we posted :D... well :)[/QUOTE] IM ALWAYS FIRST BECAUSE IM WINNER MUAHAHAHA
[QUOTE=AirBlack;41745025]IM ALWAYS FIRST BECAUSE IM WINNER MUAHAHAHA[/QUOTE] yeah :D... i got pwned :p [editline]7th August 2013[/editline] Now I just wonder... What if you need to add more Groups to the function? :D
[QUOTE=morten7000;41745014]try this. [lua] function customcheck() if ply:IsUserGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end [/lua] EDIT: Ohh same second we posted :D... well :)[/QUOTE] [lua] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:85: 'end' expected (to close 'if' at line 7) near '<eof>' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0[/lua] EDIT: Also the reason why I didn't lose it at first is because it gave me the same exact lua error when I did close it.
[QUOTE=Sm63;41745064][lua] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:85: 'end' expected (to close 'if' at line 7) near '<eof>' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0[/lua] EDIT: Also the reason why I didn't lose it at first is because it gave me the same exact lua error when I did close it.[/QUOTE] -snip-
And no I didn't, as in the code I put it in a function. [lua] function customcheck() if ply:IsUserGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end [/lua]
[QUOTE=morten7000;41745032]yeah :D... i got pwned :p [editline]7th August 2013[/editline] Now I just wonder... What if you need to add more Groups to the function? :D[/QUOTE] [CODE]function customcheck() if ply:IsUserGroup("vip+") or ply:IsUserGroup("Nigga") or ply:IsUserGroup("YouGotPWND") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end[/CODE] [editline]7th August 2013[/editline] [QUOTE=Sm63;41745064][lua] [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:85: 'end' expected (to close 'if' at line 7) near '<eof>' 1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_bulkmagnum/shared.lua:0[/lua] EDIT: Also the reason why I didn't lose it at first is because it gave me the same exact lua error when I did close it.[/QUOTE] Put another END because you're dumb forgot to close if CLIENT then
No lua errors or anything but its not in the menu. -temp snip-
[QUOTE=Sm63;41745382]No lua errors or anything but its not in the menu. -temp snip-[/QUOTE] Thats were I also came to.. Seems Im stuck there for a while. Coundn't find the answer. Sorry
I think as I said before we have to edit the TTT base.
[QUOTE=Sm63;41745382]No lua errors or anything but its not in the menu. -temp snip-[/QUOTE] Try [CODE]function SWEP:Customcheck() if self.Owner:CheckGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end[/CODE] or [CODE]function customcheck() if LocalPlayer():CheckGroup("vip+") then SWEP.CanBuy = {ROLE_TRAITOR} else return end end[/CODE]
I do like how people being remotely helpful are labeled as dumb when you can't get it to work [editline]7th August 2013[/editline] Try [lua] if LocalPlayer():IsUserGroup("group") then SWEP.CanBuy = {ROLE_TRAITOR} else return end [/lua]
None of the above work. No lua errors but it doesn't show up in the Traitor Equipment Menu
[QUOTE=Sm63;41755219]None of the above work. No lua errors but it doesn't show up in the Traitor Equipment Menu[/QUOTE] Are you sure you're in that group? Try that(without function) [CODE] if LocalPlayer():CheckGroup("vip+") or LocalPlayer:IsAdmin() then SWEP.CanBuy = {ROLE_TRAITOR} else return end[/CODE]
And yes air, I used rcon to add myself vip+ and it didn't show at all
This is pretty hacky, but it's the only way I could think of easily adding this functionality for every SWEP, whether in an addon or in TTT itself, without the need to modify base TTT code so you can easily keep up with updates. Place this code into autorun/ttt_hacky_ulx.lua on the server. [lua] if SERVER then AddCSLuaFile(); else local oWeaponsGetList = weapons.GetList; function weapons.GetList() local tbl = oWeaponsGetList(); -- LocalPlayer does not exist yet, do not filter if( !IsValid( LocalPlayer() ) ) then return tbl; end 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 [/lua] Then, just add this code to any weapon you want to be restricted to a group. [lua] SWEP.GroupOnly = true; SWEP.Groups = {"vip", "admin", "someothergroup"}; [/lua] Supports multiple groups, tested this on a dedicated server and didn't run into any issues. The detour only target's TTT's cl_equip.lua's GetEquipmentForRole(role) function on line 10. Oh and, you guys are using CanBuy incorrectly. To get a good idea of how to use it correctly, look at ttt_knife near line 45, you define it with the rest of the SWEP.* Variables, not in it's own function. like this [img]http://filesmelt.com/dl/correct_way1.png[/img]
So, I tried it. It works! Thank you so much for this. Hope the OP locks the thread now :)
Sorry, you need to Log In to post a reply to this thread.