Ulysses

General => Developers Corner => Topic started by: Lolomat on August 29, 2014, 07:54:12 AM

Title: TTT Scoreboard additional feature
Post by: Lolomat on August 29, 2014, 07:54:12 AM
hey folks,

Right now I am using this code:

Code: [Select]
function PANEL:DoRightClick()
   local menu = DermaMenu()
   menu.Player = self:GetPlayer()

   local close = hook.Call( "TTTScoreboardMenu", nil, menu )
   if close then menu:Remove() return end

   menu:Open()
    local ply = self.Player

if LocalPlayer():IsAdmin() or LocalPlayer():IsSuperAdmin() then
surface.PlaySound("buttons/button9.wav")
local options = DermaMenu()
options:AddOption("Copy Name", function() SetClipboardText(ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/user_edit.png")
options:AddOption("Copy SteamID", function() SetClipboardText(ply:SteamID()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/tag_blue.png")
options:AddSpacer()
options:AddOption("Open Profile", function() ply:ShowProfile() surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/world.png")
options:AddSpacer()

if IsValid(ply) then
local adminop,subimg = options:AddSubMenu("Admin")
subimg:SetImage("icon16/lorry.png")
adminop:AddOption("Slay Next Round", function() RunConsoleCommand("ulx","slaynr",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/cross.png")
adminop:AddOption("Slay Now", function() RunConsoleCommand("ulx","slay",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/cut_red.png")
adminop:AddOption("Kick", function() RunConsoleCommand("ulx","kick",ply:Nick(),"You were kicked") surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/door_out.png")
adminop:AddOption("Ban", function() RunConsoleCommand("ulx","ban",ply:Nick(),120,"You were banned") surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/delete.png")
adminop:AddSpacer()
adminop:AddOption("Mute", function() RunConsoleCommand("ulx","mute",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/asterisk_yellow.png")
adminop:AddOption("Gag", function() RunConsoleCommand("ulx","gag",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/asterisk_orange.png")
adminop:AddSpacer()
adminop:AddOption("Spectate", function() RunConsoleCommand("ulx","spectate",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/zoom.png")
adminop:AddSpacer()
options:Open()
end
end
end

to add a feature for my admins to allow them to rightklick on the scoreboard in TTT and use some command, like copy name, open steamprofile(so we can easily detect ghoster). But i also want that my normal players can use this. But only until the "Admin" drop down menu opens. So i tried this:

Code: [Select]
function PANEL:DoRightClick()
   local menu = DermaMenu()
   menu.Player = self:GetPlayer()

   local close = hook.Call( "TTTScoreboardMenu", nil, menu )
   if close then menu:Remove() return end

   menu:Open()
    local ply = self.Player

if LocalPlayer():IsUser() then
surface.PlaySound("buttons/button9.wav")
local options = DermaMenu()
options:AddOption("Copy Name", function() SetClipboardText(ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/user_edit.png")
options:AddOption("Copy SteamID", function() SetClipboardText(ply:SteamID()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/tag_blue.png")
options:AddSpacer()
options:AddOption("Open Profile", function() ply:ShowProfile() surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/world.png")
options:AddSpacer()
if LocalPlayer():IsAdmin() or LocalPlayer():IsSuperAdmin() then
surface.PlaySound("buttons/button9.wav")
if IsValid(ply) then
local adminop,subimg = options:AddSubMenu("Admin")
subimg:SetImage("icon16/lorry.png")
adminop:AddOption("Slay Next Round", function() RunConsoleCommand("ulx","slaynr",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/cross.png")
adminop:AddOption("Slay Now", function() RunConsoleCommand("ulx","slay",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/cut_red.png")
adminop:AddOption("Kick", function() RunConsoleCommand("ulx","kick",ply:Nick(),"You were kicked") surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/door_out.png")
adminop:AddOption("Ban", function() RunConsoleCommand("ulx","ban",ply:Nick(),120,"You were banned") surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/delete.png")
adminop:AddSpacer()
adminop:AddOption("Mute", function() RunConsoleCommand("ulx","mute",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/asterisk_yellow.png")
adminop:AddOption("Gag", function() RunConsoleCommand("ulx","gag",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/asterisk_orange.png")
adminop:AddSpacer()
adminop:AddOption("Spectate", function() RunConsoleCommand("ulx","spectate",ply:Nick()) surface.PlaySound("buttons/button9.wav") end):SetImage("icon16/zoom.png")
adminop:AddSpacer()
options:Open()
end
end
end     end

In the line where it checks the group I changed Admin and Superadmin into User and added the check for admin before the admin drop down code. But then i get this error in the consol on join.

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:296: attempt to call method 'IsUser' (a nil value)
  1. DoRightClick - gamemodes/terrortown/gamemode/vgui/sb_row.lua:296
   2. unknown - lua/cl_spectator_deathmatch.lua:161

Yeah I am pretty much a newbie to lua. :)

Best regards,
Lolomat.
Title: Re: TTT Scoreboard additional feature
Post by: Neku on August 29, 2014, 10:05:53 PM
IsUser() isn't a function...lol
For groups other than Admin and SuperAdmin, you'd need to use, IsUserGroup( group ).

In this case, you would use LocalPlayer():IsUserGroup( "user" ).
Title: Re: TTT Scoreboard additional feature
Post by: Lolomat on September 11, 2014, 06:21:51 AM
Thanks,

I figured it out myself a week ago while i was scrolling through some other scripst.
But thanks for your help.
Title: Re: TTT Scoreboard additional feature
Post by: SaintSin on September 11, 2014, 11:35:21 AM
Quote from: TTT Forum
TTTScoreboardMenu (menu)
Client
Called to show a context menu when the player right-clicks a player in the scoreboard. The "menu" parameter is a DermaMenu that you can add options to that the player can click. By default there is no context menu when right clicking, it will only appear if you add options in this hook.
Are you directly editing the sb_row.lua file? Hooks have been added for easier manipulation of the scoreboard.

Also if you haven't seen it, Rejax has created a script that will add a bunch of features for your TTT scoreboard.
http://facepunch.com/showthread.php?t=1356376 (http://facepunch.com/showthread.php?t=1356376)