Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // GangWarsRP Crafting
- // Copyright (c) Mercior
- // 12th August 2010
- require("datastream")
- // includes
- include("ddragicon.lua")
- include("dicongrid.lua")
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Menus
- local cl_craft_menu = nil
- local function DoBlackSmithMenu( )
- if LocalPlayer():GetNWBool("babygod") == true then return end
- // check for craft bench
- local bench = false
- local benches = ents.FindByClass("craft_bench")
- if benches then
- for k,v in pairs(benches) do
- if v:GetPos():Distance( LocalPlayer():GetPos() ) < 250 then
- bench = true
- break
- end
- end
- end
- // check we're near the relevant NPC(s)
- if not bench and GetNamedSpawn("blacksmith"):Distance( LocalPlayer():GetPos() ) > 250 then
- return
- end
- if not cl_craft_menu or not cl_craft_menu:IsVisible() then
- if not cl_craft_menu or not cl_craft_menu:IsValid() then
- cl_craft_menu = vgui.Create('DFrame')
- cl_craft_menu:SetSize(330, 389)
- cl_craft_menu:Center()
- cl_craft_menu:SetTitle("Blacksmith")
- cl_craft_menu:SetSizable(false)
- cl_craft_menu:SetDeleteOnClose(false)
- cl_craft_menu:ShowCloseButton(false)
- cl_craft_menu.OnClose = nil
- function cl_craft_menu:Think()
- if (!self.Dragging) then return end
- local x = gui.MouseX() - self.Dragging[1]
- local y = gui.MouseY() - self.Dragging[2]
- x = math.Clamp( x, 0, ScrW() - self:GetWide() )
- y = math.Clamp( y, 0, ScrH() - self:GetTall() )
- self:SetPos( x, y )
- end
- local invmenu = GangWars.Crafting.menu
- invmenu:SetParent(cl_craft_menu)
- invmenu:SetPos(5, 25)
- invmenu:SetSize(320, 384)
- invmenu:SetVisible(true)
- end
- -- We can also do anything else the client can do, like using the chat!
- chat.AddText(Color(255,255,128), "Blacksmith: ",Color(255,255,255), "Drag on the blueprint you wish to craft, and the items required" )
- GangWars.Crafting.menu.InvGrid:Clear()
- GangWars.Crafting.menu.BPGrid:Clear()
- gui.EnableScreenClicker(true)
- cl_craft_menu:SetVisible(true)
- GangWars.Crafting.menu.InvGrid:SetActive(true)
- GangWars.Crafting.menu.BPGrid:SetActive(true)
- else
- if cl_craft_menu then
- cl_craft_menu:SetVisible(false)
- GangWars.Crafting.menu.InvGrid:SetActive(false)
- GangWars.Crafting.menu.BPGrid:SetActive(false)
- gui.EnableScreenClicker(false)
- end
- end
- end
- concommand.Add("blacksmith_menu", DoBlackSmithMenu) --Hook the menu, so we can use it Serverside
- // Crafting Panel
- function GangWars.Crafting.Panel()
- local CharPanel = vgui.Create('DPanel')
- function CharPanel:Update()
- // destroy any previous icongrid for the inventory: TODO: BUG: possible memory leak here, what happens to the old icons?
- if self.InvGrid then self.InvGrid:DestroyReferences() end
- if self.BPGrid then self.BPGrid:DestroyReferences() end
- self:Clear(true)
- local inv_panel = vgui.Create('DPanel')
- inv_panel:SetParent(CharPanel)
- inv_panel:SetSize(320, 320 + 64)
- inv_panel:SetPos(0, 0)
- // Blueprint grid
- local BPGrid = vgui.Create( "DIconGrid", inv_panel )
- self.BPGrid = BPGrid
- BPGrid:SetPos( 16, 16 )
- BPGrid:SetGrid( 1, 1 )
- BPGrid:SetNoLose(true)
- BPGrid:SetActive(false)
- BPGrid:SetGridName("craftblueprint")
- function BPGrid:AllowInherit(icon, oldgrid)
- if not cl_craft_menu or not cl_craft_menu:IsValid() then
- return false
- end
- if icon.item.class == "blueprint" and oldgrid:GetGridName() == "inventory" then
- return true
- end
- return false
- end
- // Materials grid
- local InvGrid = vgui.Create( "DIconGrid", inv_panel )
- self.InvGrid = InvGrid
- InvGrid:SetPos( 0, 64 + 32 )
- InvGrid:SetGrid( 5, 4 )
- InvGrid:SetNoLose(true)
- InvGrid:SetActive(false)
- InvGrid:SetGridName("craftitems")
- function InvGrid:AllowInherit(icon, oldgrid)
- if not cl_craft_menu or not cl_craft_menu:IsValid() then
- return false
- end
- if icon.item.class == "material" and oldgrid:GetGridName() == "inventory" then
- return true
- end
- return false
- end
- // Craft button
- local btnDropItem = vgui.Create('DButton')
- btnDropItem:SetParent(inv_panel)
- btnDropItem:SetSize(80, 32)
- btnDropItem:SetPos(320 - 80 - 15, 16)
- btnDropItem:SetText('Craft Item')
- btnDropItem.DoClick = function()
- datastream.StreamToServer( "CraftItem", { items = InvGrid:GetItemsTable(), blueprint = BPGrid:GetItemsTable() } )
- RunConsoleCommand("blacksmith_menu")
- end
- // Close button
- local btnCancel = vgui.Create('DButton')
- btnCancel:SetParent(inv_panel)
- btnCancel:SetSize(80, 32)
- btnCancel:SetPos(320 - 80 - 15, 32 + 16)
- btnCancel:SetText('Cancel')
- btnCancel.DoClick = function()
- RunConsoleCommand("blacksmith_menu")
- RunConsoleCommand("inv_refresh")
- end
- end
- CharPanel:Update()
- return CharPanel
- end
- // set global for inv menu
- hook.Add("InitPostEntity", "GangWarsCreateCrafting", function()
- GangWars.Crafting.menu = GangWars.Crafting.Panel()
- GangWars.Crafting.menu:SetVisible(false)
- end )
- l
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement