Last active
March 14, 2016 03:42
-
-
Save NanoAi/2a32e660ade31b5474fb to your computer and use it in GitHub Desktop.
Gmod Spraymesh Context Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Created by LuaTenshi @ https://github.com/LuaTenshi | |
-- Pro Tip: Requires http://steamcommunity.com/sharedfiles/filedetails/?id=394091909 | |
local Menu = {} | |
local function contextgen(title, tab) | |
-- Created by LuaTenshi @ https://github.com/LuaTenshi | |
if Menu and IsValid(Menu) then Menu:Remove() end | |
local Menu = vgui.Create( "DMenu" ) | |
Menu.CancleFunc = function() end | |
Menu.MainFunc = function(self) -- This is ran when an item is selected from the menu. | |
local str = tostring(self:GetText()) | |
if str == "<Undefined>" or str == "<Empty>" then str = "" end | |
if string.Trim(str) ~= "" then SetClipboardText(str) end | |
end | |
Menu.Paint = function(self, w, h) | |
local color = self:IsHovered() and Color( 202, 221, 248, 255 ) or Color( 255, 255, 255, 255 ) | |
draw.RoundedBoxEx(8, 0, 0, w, h, color, false, true, true, false) | |
end | |
local icon = title:match('%[i=(.*)%]') | |
title = tostring(title):gsub('%[i=(.*)%]', '') | |
local mTitle = Menu:AddOption( title ) | |
if icon then | |
mTitle:SetIcon( icon ) | |
else | |
mTitle:SetIcon( "icon16/bug.png" ) | |
end | |
mTitle.Paint = function(self, w, h) draw.RoundedBoxEx(8, 0, 0, w, h, Color( 240, 240, 240, 255 ), false, true, false, false) end | |
Menu:GetVBar().Paint = function() return true end | |
Menu:GetVBar().btnUp.Paint = function() return true end | |
Menu:GetVBar().btnDown.Paint = function() return true end | |
Menu:GetVBar().btnGrip.Paint = function() return true end | |
Menu:GetVBar():SetWidth(0) | |
function Menu:OnScrollbarAppear() return true end | |
Menu:AddSpacer() | |
for k,v in next, tab do | |
local key = isnumber(tonumber(k)) | |
local x = string.Trim(tostring(v)) | |
local icons = {x = x:match('%[i=(.*)%]')} | |
x, k = tostring(x):gsub('%[i=(.*)%]', ''), tostring(k):gsub('%[i=(.*)%]', '') | |
local SubMenu = key and Menu:AddOption(x, isfunction(v) and v or Menu.MainFunc) or Menu:AddSubMenu( k, Menu.MainFunc ) | |
SubMenu.Paint = Menu.Paint | |
if icons.x then SubMenu:SetIcon(icons.x) end | |
if not key then | |
if x ~= "" then | |
if type(v) == "table" then | |
local s = SubMenu:AddOption( tostring(x), Menu.MainFunc ) | |
s.Paint = mTitle.Paint | |
SubMenu:AddSpacer() | |
local count = 0 | |
for i,d in next, v do | |
key = isnumber(tonumber(i)) | |
local l = key and SubMenu:AddOption(d, isfunction(d) and d or Menu.MainFunc) or SubMenu:AddSubMenu(tostring(i), Menu.MainFunc) | |
l.Paint = Menu.Paint | |
if not key then | |
if string.Trim(tostring(d)) ~= "" then | |
l:AddOption( tostring(d), Menu.MainFunc ) | |
else | |
l:AddOption( "<Undefined>", Menu.CancleFunc ) | |
end | |
end | |
count = count + 1 | |
end | |
if count <= 0 then SubMenu:AddOption( "<Empty>", Menu.CancleFunc ) end | |
count = 0 | |
else | |
SubMenu:AddOption( tostring(x), Menu.MainFunc ) | |
end | |
else | |
SubMenu:AddOption( "<Undefined>", Menu.CancleFunc ) | |
end | |
end | |
end | |
Menu:Open() | |
Menu:RequestFocus() | |
return Menu | |
end | |
local export = {} | |
timer.Simple(1, function() | |
local old = SprayMesh.PlaceSpray | |
function SprayMesh.PlaceSpray(hitpos,hitnormal,ply,url) | |
export[IsValid(ply) and ply.SteamID and ply:SteamID() or 'lastfail'] = { | |
hitpos = hitpos, | |
hitnormal = hitnormal, | |
ply = ply, | |
url = url | |
} | |
return old(hitpos,hitnormal,ply,url) | |
end | |
end) | |
local function click(code) | |
if ( !hook.Call( "ContextMenuOpen", GAMEMODE ) ) then return end | |
if code == MOUSE_RIGHT then | |
for k,v in next, SprayMesh.Players do | |
local k = tostring(k) | |
local tr = LocalPlayer():GetEyeTrace() | |
local mpos, spos = IsValid(LocalPlayer()) and tr.HitPos or false, export[k] and (export[k].hitpos+export[k].hitnormal) or false | |
if (mpos and spos) and mpos:Distance(spos) < 30 and tr.HitWorld then | |
timer.Simple(0, function() | |
Menu = contextgen( | |
'[i=icon16/book_open.png]Sprayed By...', | |
{ | |
'[i=icon16/user.png]'..(IsValid(v.ply) and tostring(v.ply:Nick()) or 'Disconnected'), | |
'[i=icon16/user_edit.png]'..k, | |
'[i=icon16/world_link.png]'..tostring(v.meshdata.url) | |
}) | |
end) | |
end | |
end | |
end | |
end | |
hook.Add('VGUIMouseReleased', '_killmenu', function() if IsValid(Menu) then Menu:Remove() end end) | |
hook.Add('OnContextMenuClose', '_killmenu', function() if IsValid(Menu) then Menu:Remove() end end) | |
hook.Add('OnContextMenuOpen', 'SpraymeshContext', function() | |
hook.Add('GUIMousePressed', '_spraymenu', click) | |
end) | |
hook.Add('OnContextMenuClose', 'SpraymeshContext', function() | |
hook.Remove('GUIMousePressed', '_spraymenu') | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment