Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.21 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // GangWarsRP Crafting
  3. // Copyright (c) Mercior
  4. // 12th August 2010
  5.  
  6. require("datastream")
  7.  
  8. // includes
  9. include("ddragicon.lua")
  10. include("dicongrid.lua")
  11.  
  12.  
  13. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. // Menus
  15.  
  16. local cl_craft_menu = nil
  17.  
  18. local function DoBlackSmithMenu(  )
  19.     if LocalPlayer():GetNWBool("babygod") == true then return end
  20.    
  21.     // check for craft bench
  22.     local bench = false
  23.     local benches = ents.FindByClass("craft_bench")
  24.     if benches then
  25.         for k,v in pairs(benches) do
  26.             if v:GetPos():Distance( LocalPlayer():GetPos() ) < 250 then
  27.                 bench = true
  28.                 break
  29.             end
  30.         end
  31.     end
  32.    
  33.     // check we're near the relevant NPC(s)
  34.     if not bench and GetNamedSpawn("blacksmith"):Distance( LocalPlayer():GetPos() ) > 250 then
  35.         return
  36.     end
  37.    
  38.    
  39.     if not cl_craft_menu or not cl_craft_menu:IsVisible() then
  40.    
  41.         if not cl_craft_menu or not cl_craft_menu:IsValid() then
  42.             cl_craft_menu = vgui.Create('DFrame')
  43.             cl_craft_menu:SetSize(330, 389)
  44.             cl_craft_menu:Center()
  45.             cl_craft_menu:SetTitle("Blacksmith")
  46.             cl_craft_menu:SetSizable(false)
  47.             cl_craft_menu:SetDeleteOnClose(false)
  48.             cl_craft_menu:ShowCloseButton(false)
  49.             cl_craft_menu.OnClose = nil
  50.            
  51.             function cl_craft_menu:Think()
  52.                 if (!self.Dragging) then return end
  53.                 local x = gui.MouseX() - self.Dragging[1]
  54.                 local y = gui.MouseY() - self.Dragging[2]
  55.                 x = math.Clamp( x, 0, ScrW() - self:GetWide() )
  56.                 y = math.Clamp( y, 0, ScrH() - self:GetTall() )
  57.                 self:SetPos( x, y )        
  58.             end
  59.  
  60.             local invmenu = GangWars.Crafting.menu
  61.             invmenu:SetParent(cl_craft_menu)
  62.             invmenu:SetPos(5, 25)
  63.             invmenu:SetSize(320, 384)
  64.             invmenu:SetVisible(true)
  65.         end
  66.        
  67.         -- We can also do anything else the client can do, like using the chat!
  68.         chat.AddText(Color(255,255,128), "Blacksmith: ",Color(255,255,255), "Drag on the blueprint you wish to craft, and the items required" )
  69.        
  70.         GangWars.Crafting.menu.InvGrid:Clear()
  71.         GangWars.Crafting.menu.BPGrid:Clear()
  72.        
  73.         gui.EnableScreenClicker(true)
  74.         cl_craft_menu:SetVisible(true)
  75.         GangWars.Crafting.menu.InvGrid:SetActive(true)
  76.         GangWars.Crafting.menu.BPGrid:SetActive(true)
  77.     else
  78.    
  79.         if cl_craft_menu then
  80.             cl_craft_menu:SetVisible(false)
  81.             GangWars.Crafting.menu.InvGrid:SetActive(false)
  82.             GangWars.Crafting.menu.BPGrid:SetActive(false)
  83.             gui.EnableScreenClicker(false)
  84.         end
  85.     end
  86. end
  87. concommand.Add("blacksmith_menu", DoBlackSmithMenu) --Hook the menu, so we can use it Serverside
  88.  
  89.  
  90. // Crafting Panel
  91. function GangWars.Crafting.Panel()
  92.     local CharPanel = vgui.Create('DPanel')
  93.    
  94.     function CharPanel:Update()
  95.         // destroy any previous icongrid for the inventory: TODO: BUG: possible memory leak here, what happens to the old icons?
  96.         if self.InvGrid then self.InvGrid:DestroyReferences() end
  97.         if self.BPGrid then self.BPGrid:DestroyReferences() end
  98.         self:Clear(true)
  99.         local inv_panel = vgui.Create('DPanel')
  100.         inv_panel:SetParent(CharPanel)
  101.         inv_panel:SetSize(320, 320 + 64)
  102.         inv_panel:SetPos(0, 0)
  103.        
  104.         // Blueprint grid
  105.         local BPGrid = vgui.Create( "DIconGrid", inv_panel )
  106.         self.BPGrid = BPGrid
  107.         BPGrid:SetPos( 16, 16 )
  108.         BPGrid:SetGrid( 1, 1 )
  109.         BPGrid:SetNoLose(true)
  110.         BPGrid:SetActive(false)
  111.         BPGrid:SetGridName("craftblueprint")
  112.         function BPGrid:AllowInherit(icon, oldgrid)
  113.             if not cl_craft_menu or not cl_craft_menu:IsValid() then
  114.                 return false
  115.             end
  116.             if icon.item.class == "blueprint" and oldgrid:GetGridName() == "inventory" then
  117.                 return true
  118.             end
  119.             return false
  120.         end
  121.        
  122.         // Materials grid
  123.         local InvGrid = vgui.Create( "DIconGrid", inv_panel )
  124.         self.InvGrid = InvGrid
  125.         InvGrid:SetPos( 0, 64 + 32 )
  126.         InvGrid:SetGrid( 5, 4 )
  127.         InvGrid:SetNoLose(true)
  128.         InvGrid:SetActive(false)
  129.         InvGrid:SetGridName("craftitems")
  130.         function InvGrid:AllowInherit(icon, oldgrid)
  131.             if not cl_craft_menu or not cl_craft_menu:IsValid() then
  132.                 return false
  133.             end
  134.             if icon.item.class == "material" and oldgrid:GetGridName() == "inventory" then
  135.                 return true
  136.             end
  137.             return false
  138.         end
  139.        
  140.  
  141.         // Craft button
  142.         local btnDropItem = vgui.Create('DButton')
  143.         btnDropItem:SetParent(inv_panel)
  144.         btnDropItem:SetSize(80, 32)
  145.         btnDropItem:SetPos(320 - 80 - 15, 16)
  146.         btnDropItem:SetText('Craft Item')
  147.         btnDropItem.DoClick = function()
  148.             datastream.StreamToServer( "CraftItem", { items = InvGrid:GetItemsTable(), blueprint = BPGrid:GetItemsTable() } )
  149.             RunConsoleCommand("blacksmith_menu")
  150.         end
  151.        
  152.         // Close button
  153.         local btnCancel = vgui.Create('DButton')
  154.         btnCancel:SetParent(inv_panel)
  155.         btnCancel:SetSize(80, 32)
  156.         btnCancel:SetPos(320 - 80 - 15, 32 + 16)
  157.         btnCancel:SetText('Cancel')
  158.         btnCancel.DoClick = function()
  159.             RunConsoleCommand("blacksmith_menu")
  160.             RunConsoleCommand("inv_refresh")
  161.         end
  162.        
  163.     end
  164.    
  165.  
  166.    
  167.     CharPanel:Update() 
  168.     return CharPanel
  169. end
  170.  
  171.  
  172. // set global for inv menu
  173. hook.Add("InitPostEntity", "GangWarsCreateCrafting", function()
  174.                                                     GangWars.Crafting.menu = GangWars.Crafting.Panel()
  175.                                                     GangWars.Crafting.menu:SetVisible(false)
  176.                                                 end )
  177.  
  178.  
  179.  
  180. l
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement