Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: Lua  |  size: 2.54 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. TOOL.Category = "Tech"
  2. TOOL.Tab = "Ship"
  3. TOOL.Name = "#Cores"
  4. TOOL.Command = nil
  5. TOOL.ConfigName = "" --Setting this means that you do not have to create external configuration files to define the layout of the tool config-hud
  6. self.coretype = nil
  7. function TOOL:LeftClick( trace )
  8.         if (CLIENT) then return true end
  9.         if(self.coretype!=nil) then
  10.                 print("spawn")
  11.                 local entity = ents.Create(self.coretype)
  12.                         if not entity or not entity:IsValid() then return false end
  13.                         local pos = trace.HitPos
  14.                         local ang = trace.HitNormal:Angle()+Angle(90,0,0)
  15.                         entity:SetAngles(ang)
  16.                         entity:SetPos(pos)
  17.                         entity:Spawn()
  18.                         entity:Initialize()
  19.                         entity:SetPos(trace.HitPos - trace.HitNormal * entity:OBBMins().z)
  20.         end
  21. end
  22.  
  23. function TOOL:RightClick( trace )
  24. end
  25.  
  26. function TOOL.BuildCPanel( panel )
  27.         panel:AddControl("Header", { Text = "Example TOOL", Description = "Just an little example" })
  28.  
  29.         panel:AddControl("CheckBox", {
  30.             Label = "Weld",
  31.             //Command = "example_bool"
  32.         })
  33.         panel:AddControl("CheckBox", {
  34.             Label = "AutoFreeze",
  35.             //Command = "example_bool"
  36.         })
  37.        
  38.         local ctrl = vgui.Create( "DTree", panel )
  39.  
  40.         ctrl:SetPos( 5, 30 )
  41.         ctrl:SetPadding( 5 )
  42.         ctrl:SetSize( 300, 300 )
  43.        
  44.         treeitems = {}
  45.         ctrl.DoClick = function ()
  46.                 for i=1,table.Count(treeitems) do
  47.                         if(string.Explode("^", treeitems[i])[1]==tostring(ctrl:GetSelectedItem())) then
  48.                                 local name = string.Explode("^", treeitems[i])[2]
  49.                                 if(name!="dontspawn") then
  50.                                         self.coretype = name
  51.                                         print(name)
  52.                                 else
  53.                                         self.coretype = nil
  54.                                 end
  55.                                 break
  56.                         end
  57.                 end
  58.         end
  59.        
  60.         local node = ctrl:AddNode( "Ship Cores" ); treeitems[table.Count(treeitems)+1] = tostring(node).."^dontspawn"
  61.                 local ctnode = node:AddNode( "Large Core" ); treeitems[table.Count(treeitems)+1] = tostring(ctnode).."^sf_shipcore_large"
  62.                         ctnode.Icon:SetImage( "gui/silkicons/newspaper" )
  63.                 local ctnode = node:AddNode( "Small Core" ); treeitems[table.Count(treeitems)+1] = tostring(ctnode).."^sf_shipcore_small"
  64.                         ctnode.Icon:SetImage( "gui/silkicons/newspaper" )
  65.         local node = ctrl:AddNode( "Station Cores" ); treeitems[table.Count(treeitems)+1] = tostring(node).."^dontspawn"
  66.                 local ctnode = node:AddNode( "Large Core" ); treeitems[table.Count(treeitems)+1] = tostring(ctnode).."^sf_stationcore_large"
  67.                         ctnode.Icon:SetImage( "gui/silkicons/newspaper" )
  68.                 local ctnode = node:AddNode( "Small Core" ); treeitems[table.Count(treeitems)+1] = tostring(ctnode).."^sf_stationcore_small"
  69.                         ctnode.Icon:SetImage( "gui/silkicons/newspaper" )
  70.                        
  71.         panel:AddPanel(ctrl)
  72.        
  73. end