Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.91 KB | None | 0 0
  1. local Menu = {}
  2.  
  3. local function Option(title, icon, cmd, check)
  4. table.insert(Menu, {title = title, icon = icon, cmd = cmd, check = check})
  5. end
  6.  
  7. local function SubMenu(title, icon, func, check)
  8. table.insert(Menu, {title = title, icon = icon, func = func, check = check})
  9. end
  10.  
  11. local function Spacer(check)
  12. table.insert(Menu, {check = check})
  13. end
  14.  
  15. local function Request(title, text, func)
  16. return function()
  17. Derma_StringRequest(DarkRP.getPhrase(title) or title, DarkRP.getPhrase(text) or text, nil, function(s)
  18. func(s)
  19. end)
  20. end
  21. end
  22.  
  23. local function isCP()
  24. return LocalPlayer():isCP()
  25. end
  26.  
  27. local function isMayor()
  28. return LocalPlayer():Team() == TEAM_MAYOR
  29. end
  30.  
  31.  
  32. local function add(t)
  33. table.insert(Menu, t)
  34. end
  35.  
  36. /* YOU CAN EDIT STUFF BELOW THIS POINT */
  37.  
  38.  
  39. Option(C_LANGUAGE_MONEY_DROP, "icon16/money_delete.png", Request(C_LANGUAGE_MONEY_DROP, C_LANGUAGE_MONEY_DROP_DESCRIPTION, function(s)
  40. RunConsoleCommand("darkrp", "dropmoney", s)
  41. end))
  42.  
  43.  
  44.  
  45. Option(C_LANGUAGE_MONEY_GIVE, "icon16/money.png", Request(C_LANGUAGE_MONEY_GIVE, C_LANGUAGE_MONEY_GIVE_DESCRIPTION, function(s)
  46. RunConsoleCommand("darkrp", "give", s)
  47. end))
  48.  
  49. SubMenu("Выписать чек", "icon16/script_edit.png", function(self)
  50.  
  51. for k, v in pairs(player.GetAll()) do
  52.  
  53. if v == LocalPlayer() then continue end
  54.  
  55.  
  56.  
  57. self:AddOption(v:Name(), Request("Выписка чека", "Сколько денег должен получить человек?", function(s)
  58.  
  59. RunConsoleCommand("darkrp", "cheque", v:UserID(), s)
  60.  
  61. end)):SetColor(v:getJobTable().color)
  62.  
  63. end
  64.  
  65. end)
  66.  
  67.  
  68. Spacer()
  69.  
  70. Option(C_LANGUAGE_DROP, "icon16/gun.png", function()
  71. RunConsoleCommand("darkrp", "dropweapon")
  72. end)
  73.  
  74.  
  75. Option("Купить патроны на текущее оружие", "icon16/application.png", function()
  76. RunConsoleCommand("darkrp", "buyammo", LocalPlayer():GetActiveWeapon().Primary.Ammo)
  77. end,
  78. function()
  79. return IsValid(LocalPlayer():GetActiveWeapon()) and istable(LocalPlayer():GetActiveWeapon().Primary) and LocalPlayer():GetActiveWeapon().Primary.Ammo and fn.Head(fn.Filter(function(x) return x.ammoType == LocalPlayer():GetActiveWeapon().Primary.Ammo end, GAMEMODE.AmmoTypes))
  80. end)
  81.  
  82. Option(C_LANGUAGE_LICENSE, "icon16/page_white_text.png", function()
  83. RunConsoleCommand("say", "/requestlicense")
  84. end)
  85.  
  86. Spacer()
  87.  
  88.  
  89. SubMenu(C_LANGUAGE_DEMOTE, "icon16/user_delete.png", function(self)
  90. for k, v in pairs(player.GetAll()) do
  91. if v == LocalPlayer() then continue end
  92. self:AddOption(v:Name(), Request(C_LANGUAGE_DEMOTE, C_LANGUAGE_DEMOTE_DESCRIPTION, function(s)
  93. RunConsoleCommand("darkrp", "demote", v:UserID(), s)
  94. end)):SetColor(v:getJobTable().color)
  95. end
  96. end)
  97.  
  98. Option(C_LANGUAGE_UNOWN_ALL, "icon16/door.png", function()
  99. RunConsoleCommand("darkrp", "unownalldoors")
  100. end)
  101.  
  102.  
  103.  
  104. Spacer(isCP)
  105.  
  106. SubMenu("Повесить розыск", "icon16/flag_red.png", function(self)
  107. for k, v in pairs(player.GetAll()) do
  108. if v == LocalPlayer() then continue end
  109. if !v:isWanted() then
  110. self:AddOption(v:Name(), Request(C_LANGUAGE_WANTED, C_LANGUAGE_WANTED_DESCRIPTION, function(s)
  111. RunConsoleCommand("darkrp", "wanted", v:UserID(), s)
  112. end)):SetColor(v:getJobTable().color)
  113. end
  114. end
  115. end, isCP)
  116.  
  117. SubMenu("Снять розыск", "icon16/flag_green.png", function(self)
  118. for k, v in pairs(player.GetAll()) do
  119. if v:isWanted() then
  120. self:AddOption(v:Name(), function(s)
  121. RunConsoleCommand("darkrp", "unwanted", v:UserID(), s)
  122. end):SetColor(v:getJobTable().color)
  123. end
  124. end
  125. end, isCP)
  126.  
  127. SubMenu("Запросить ордер", "icon16/door_in.png", function(self)
  128. for k, v in pairs(player.GetAll()) do
  129. if v == LocalPlayer() then continue end
  130. self:AddOption(v:Name(), Request(C_LANGUAGE_WARRANT, C_LANGUAGE_WARRANT_DESCRIPTION, function(s)
  131. RunConsoleCommand("darkrp", "warrant", v:UserID(), s)
  132. end)):SetColor(v:getJobTable().color)
  133. end
  134. end, isCP)
  135.  
  136. Option("Выдать лицензию", "icon16/page_add.png", function(self)
  137. RunConsoleCommand("darkrp", "givelicense")
  138. end, function()
  139. local ply = LocalPlayer()
  140. local noMayorExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isMayor), player.GetAll}
  141. local noChiefExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isChief), player.GetAll}
  142.  
  143. local canGiveLicense = fn.FOr{
  144. ply.isMayor, -- Mayors can hand out licenses
  145. fn.FAnd{ply.isChief, noMayorExists}, -- Chiefs can if there is no mayor
  146. fn.FAnd{ply.isCP, noChiefExists, noMayorExists} -- CP's can if there are no chiefs nor mayors
  147. }
  148.  
  149. return canGiveLicense(ply)
  150. end)
  151.  
  152. Spacer(function() return LocalPlayer():isMayor() end)
  153.  
  154.  
  155.  
  156. Option(C_LANGUAGE_LOCKDOWN, "icon16/sound.png",
  157.  
  158. Request(START_LOCKDOWN, REASON, function(s)
  159.  
  160.  
  161. RunConsoleCommand("say", "/lkd " .. s)
  162. end),
  163.  
  164. function() return LocalPlayer():isMayor() and !GetGlobalBool("LockDown") end)
  165.  
  166. Option(C_LANGUAGE_UNLOCKDOWN, "icon16/stop.png", function(s)
  167. RunConsoleCommand("say", "/unlkd")
  168. end, function() return LocalPlayer():isMayor() and GetGlobalBool("LockDown1") end)
  169.  
  170.  
  171. --
  172.  
  173. Option(CALL_ADMIN, "icon16/flag_green.png", function(s)
  174. RunConsoleCommand("say", "/calladmin", s)
  175. end)
  176. --
  177.  
  178. Option("Запустить лотерею", "icon16/money_dollar.png",
  179. Request("Запустить лотерею", "Введите сумму вложения для запуска лотереи ($50 - $50.000)", function(s)
  180. RunConsoleCommand("say", "/lottery " .. s)
  181. LocalPlayer():ChatPrint("Вы запустили лотерею на " .. s .."$")
  182. end),
  183. function() return LocalPlayer():isMayor() end)
  184.  
  185. Option("Оповещение городу", "icon16/sound.png",
  186. Request("Оповещение городу", "Введите сообщение", function(s)
  187. RunConsoleCommand("say", "/broadcast " .. s)
  188. end),
  189. function() return LocalPlayer():isMayor() end)
  190.  
  191. Spacer()
  192.  
  193.  
  194. Option("Режим полета", "icon16/arrow_out.png", function()
  195.  
  196. RunConsoleCommand("ulx", "noclip")
  197.  
  198. end, function() return ULib.ucl.query(LocalPlayer(), "ulx noclip") end)
  199.  
  200.  
  201. /* DO NOT EDIT STUFF BELOW THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING */
  202.  
  203. local menu
  204. hook.Add("OnContextMenuOpen", "CMenuOnContextMenuOpen", function()
  205. if not g_ContextMenu:IsVisible() then
  206. local orig = g_ContextMenu.Open
  207. g_ContextMenu.Open = function(self, ...)
  208. self.Open = orig
  209. orig(self, ...)
  210.  
  211. menu = vgui.Create("CMenuExtension")
  212. menu:SetDrawOnTop(false)
  213.  
  214. for k, v in pairs(Menu) do
  215. if not v.check or v.check() then
  216. if v.cmd then
  217. menu:AddOption(v.title, isfunction(v.cmd) and v.cmd or function() RunConsoleCommand(v.cmd) end):SetImage(v.icon)
  218. elseif v.func then
  219. local m, s = menu:AddSubMenu(v.title)
  220. s:SetImage(v.icon)
  221. v.func(m)
  222. else
  223. menu:AddSpacer()
  224. end
  225. end
  226. end
  227.  
  228. menu:Open()
  229. if C_CONFIG_POSITION == "bottom" then
  230. menu:CenterHorizontal()
  231. menu.y = ScrH()
  232. menu:MoveTo(menu.x, ScrH() - menu:GetTall() - 8, .1, 0)
  233. elseif C_CONFIG_POSITION == "right" then
  234. menu:CenterVertical()
  235. menu.x = ScrW()
  236. menu:MoveTo(ScrW() - menu:GetWide() - 8, menu.y, .1, 0)
  237. elseif C_CONFIG_POSITION == "left" then
  238. menu:CenterVertical()
  239. menu.x = - menu:GetWide()
  240. menu:MoveTo(8, menu.y, .1, 0)
  241. else
  242. menu:CenterHorizontal()
  243. menu.y = - menu:GetTall()
  244. menu:MoveTo(menu.x, 30 + 8, .1, 0)
  245. end
  246.  
  247.  
  248. menu:MakePopup()
  249. end
  250. end
  251. end)
  252.  
  253. hook.Add( "CloseDermaMenus", "CMenuCloseDermaMenus", function()
  254. if menu && menu:IsValid() then
  255. menu:MakePopup()
  256. end
  257. end)
  258.  
  259. hook.Add("OnContextMenuClose", "CMenuOnContextMenuClose", function()
  260. menu:Remove()
  261. end)
  262.  
  263.  
  264.  
  265. local PANEL = {}
  266.  
  267. AccessorFunc( PANEL, "m_bBorder", "DrawBorder" )
  268. AccessorFunc( PANEL, "m_bDeleteSelf", "DeleteSelf" )
  269. AccessorFunc( PANEL, "m_iMinimumWidth", "MinimumWidth" )
  270. AccessorFunc( PANEL, "m_bDrawColumn", "DrawColumn" )
  271. AccessorFunc( PANEL, "m_iMaxHeight", "MaxHeight" )
  272.  
  273. AccessorFunc( PANEL, "m_pOpenSubMenu", "OpenSubMenu" )
  274.  
  275.  
  276. --[[---------------------------------------------------------
  277. Init
  278. -----------------------------------------------------------]]
  279. function PANEL:Init()
  280.  
  281. self:SetIsMenu( true )
  282. self:SetDrawBorder( true )
  283. self:SetDrawBackground( true )
  284. self:SetMinimumWidth( 100 )
  285. self:SetDrawOnTop( true )
  286. self:SetMaxHeight( ScrH() * 0.9 )
  287. self:SetDeleteSelf( true )
  288.  
  289. self:SetPadding( 0 )
  290.  
  291. end
  292.  
  293. --[[---------------------------------------------------------
  294. AddPanel
  295. -----------------------------------------------------------]]
  296. function PANEL:AddPanel( pnl )
  297.  
  298. self:AddItem( pnl )
  299. pnl.ParentMenu = self
  300.  
  301. end
  302.  
  303. --[[---------------------------------------------------------
  304. AddOption
  305. -----------------------------------------------------------]]
  306. function PANEL:AddOption( strText, funcFunction )
  307.  
  308. local pnl = vgui.Create( "DMenuOption", self )
  309. pnl:SetMenu( self )
  310. pnl:SetText( strText )
  311. if ( funcFunction ) then pnl.DoClick = funcFunction end
  312.  
  313. self:AddPanel( pnl )
  314.  
  315. return pnl
  316.  
  317. end
  318.  
  319. --[[---------------------------------------------------------
  320. AddCVar
  321. -----------------------------------------------------------]]
  322. function PANEL:AddCVar( strText, convar, on, off, funcFunction )
  323.  
  324. local pnl = vgui.Create( "DMenuOptionCVar", self )
  325. pnl:SetMenu( self )
  326. pnl:SetText( strText )
  327. if ( funcFunction ) then pnl.DoClick = funcFunction end
  328.  
  329. pnl:SetConVar( convar )
  330. pnl:SetValueOn( on )
  331. pnl:SetValueOff( off )
  332.  
  333. self:AddPanel( pnl )
  334.  
  335. return pnl
  336.  
  337. end
  338.  
  339. --[[---------------------------------------------------------
  340. AddSpacer
  341. -----------------------------------------------------------]]
  342. function PANEL:AddSpacer( strText, funcFunction )
  343.  
  344. local pnl = vgui.Create( "DPanel", self )
  345. pnl.Paint = function( p, w, h )
  346. surface.SetDrawColor( Color( 0, 0, 0, 100 ) )
  347. surface.DrawRect( 0, 0, w, h )
  348. end
  349.  
  350. pnl:SetTall( 1 )
  351. self:AddPanel( pnl )
  352.  
  353. return pnl
  354.  
  355. end
  356.  
  357. --[[---------------------------------------------------------
  358. AddSubMenu
  359. -----------------------------------------------------------]]
  360. function PANEL:AddSubMenu( strText, funcFunction )
  361.  
  362. local pnl = vgui.Create( "DMenuOption", self )
  363. local SubMenu = pnl:AddSubMenu( strText, funcFunction )
  364.  
  365. pnl:SetText( strText )
  366. if ( funcFunction ) then pnl.DoClick = funcFunction end
  367.  
  368. self:AddPanel( pnl )
  369.  
  370. return SubMenu, pnl
  371.  
  372. end
  373.  
  374. --[[---------------------------------------------------------
  375. Hide
  376. -----------------------------------------------------------]]
  377. function PANEL:Hide()
  378.  
  379. local openmenu = self:GetOpenSubMenu()
  380. if ( openmenu ) then
  381. openmenu:Hide()
  382. end
  383.  
  384. self:SetVisible( false )
  385. self:SetOpenSubMenu( nil )
  386.  
  387. end
  388.  
  389. --[[---------------------------------------------------------
  390. OpenSubMenu
  391. -----------------------------------------------------------]]
  392. function PANEL:OpenSubMenu( item, menu )
  393.  
  394. -- Do we already have a menu open?
  395. local openmenu = self:GetOpenSubMenu()
  396. if ( IsValid( openmenu ) ) then
  397.  
  398. -- Don't open it again!
  399. if ( menu && openmenu == menu ) then return end
  400.  
  401. -- Close it!
  402. self:CloseSubMenu( openmenu )
  403.  
  404. end
  405.  
  406. if ( !IsValid( menu ) ) then return end
  407.  
  408. local x, y = item:LocalToScreen( self:GetWide(), 0 )
  409. menu:Open( x-3, y, false, item )
  410.  
  411. self:SetOpenSubMenu( menu )
  412.  
  413. end
  414.  
  415.  
  416. --[[---------------------------------------------------------
  417. CloseSubMenu
  418. -----------------------------------------------------------]]
  419. function PANEL:CloseSubMenu( menu )
  420.  
  421. menu:Hide()
  422. self:SetOpenSubMenu( nil )
  423.  
  424. end
  425.  
  426. --[[---------------------------------------------------------
  427. Paint
  428. -----------------------------------------------------------]]
  429. function PANEL:Paint( w, h )
  430.  
  431. if ( !self:GetDrawBackground() ) then return end
  432.  
  433. derma.SkinHook( "Paint", "Menu", self, w, h )
  434. return true
  435.  
  436. end
  437.  
  438. function PANEL:ChildCount()
  439. return #self:GetCanvas():GetChildren()
  440. end
  441.  
  442. function PANEL:GetChild( num )
  443. return self:GetCanvas():GetChildren()[ num ]
  444. end
  445.  
  446. --[[---------------------------------------------------------
  447. PerformLayout
  448. -----------------------------------------------------------]]
  449. function PANEL:PerformLayout()
  450.  
  451. local w = self:GetMinimumWidth()
  452.  
  453. -- Find the widest one
  454. for k, pnl in pairs( self:GetCanvas():GetChildren() ) do
  455.  
  456. pnl:PerformLayout()
  457. w = math.max( w, pnl:GetWide() )
  458.  
  459. end
  460.  
  461. self:SetWide( w )
  462.  
  463. local y = 0 -- for padding
  464.  
  465. for k, pnl in pairs( self:GetCanvas():GetChildren() ) do
  466.  
  467. pnl:SetWide( w )
  468. pnl:SetPos( 0, y )
  469. pnl:InvalidateLayout( true )
  470.  
  471. y = y + pnl:GetTall()
  472.  
  473. end
  474.  
  475. y = math.min( y, self:GetMaxHeight() )
  476.  
  477. self:SetTall( y )
  478.  
  479. derma.SkinHook( "Layout", "Menu", self )
  480.  
  481. DScrollPanel.PerformLayout( self )
  482.  
  483. end
  484.  
  485.  
  486. --[[---------------------------------------------------------
  487. Open - Opens the menu.
  488. x and y are optional, if they're not provided the menu
  489. will appear at the cursor.
  490. -----------------------------------------------------------]]
  491. function PANEL:Open( x, y, skipanimation, ownerpanel )
  492.  
  493. local maunal = x and y
  494.  
  495. x = x or gui.MouseX()
  496. y = y or gui.MouseY()
  497.  
  498. local OwnerHeight = 0
  499. local OwnerWidth = 0
  500.  
  501. if ( ownerpanel ) then
  502. OwnerWidth, OwnerHeight = ownerpanel:GetSize()
  503. end
  504.  
  505. self:PerformLayout()
  506.  
  507. local w = self:GetWide()
  508. local h = self:GetTall()
  509.  
  510. self:SetSize( w, h )
  511.  
  512.  
  513. if ( y + h > ScrH() ) then y = ((maunal and ScrH()) or (y + OwnerHeight)) - h end
  514. if ( x + w > ScrW() ) then x = ((maunal and ScrW()) or x) - w end
  515. if ( y < 1 ) then y = 1 end
  516. if ( x < 1 ) then x = 1 end
  517.  
  518. self:SetPos( x, y )
  519.  
  520. -- Popup!
  521. self:MakePopup()
  522.  
  523. -- Make sure it's visible!
  524. self:SetVisible( true )
  525.  
  526. -- Keep the mouse active while the menu is visible.
  527. self:SetKeyboardInputEnabled( false )
  528.  
  529. end
  530.  
  531. --
  532. -- Called by DMenuOption
  533. --
  534. function PANEL:OptionSelectedInternal( option )
  535.  
  536. self:OptionSelected( option, option:GetText() )
  537.  
  538. end
  539.  
  540. function PANEL:OptionSelected( option, text )
  541.  
  542. -- For override
  543.  
  544. end
  545.  
  546. function PANEL:ClearHighlights()
  547.  
  548. for k, pnl in pairs( self:GetCanvas():GetChildren() ) do
  549. pnl.Highlight = nil
  550. end
  551.  
  552. end
  553.  
  554. function PANEL:HighlightItem( item )
  555.  
  556. for k, pnl in pairs( self:GetCanvas():GetChildren() ) do
  557. if ( pnl == item ) then
  558. pnl.Highlight = true
  559. end
  560. end
  561.  
  562. end
  563.  
  564. --[[---------------------------------------------------------
  565. Name: GenerateExample
  566. -----------------------------------------------------------]]
  567. function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
  568.  
  569.  
  570. end
  571.  
  572. derma.DefineControl( "CMenuExtension", "A Menu", PANEL, "DScrollPanel" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement