Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.22 KB | None | 0 0
  1. local SpawnList = {}
  2.  
  3. SpawnList = BaseWars.SpawnList
  4. GrenadeTimer = 0
  5.  
  6. local function LimitDeduct(self, ent, ply)
  7.  
  8.     self.o_OnRemove = self.OnRemove
  9.  
  10.     self.OnRemove = function(e)
  11.  
  12.         local ply = BaseWars.Ents:ValidPlayer(ply)
  13.  
  14.         if ply then
  15.             ply:GetTable()["limit_" .. ent] = ply:GetTable()["limit_" .. ent] - 1
  16.         end
  17.  
  18.         e:o_OnRemove()
  19.     end
  20.  
  21.     ply:GetTable()["limit_" .. ent] = ply:GetTable()["limit_" .. ent] + 1
  22.  
  23. end
  24.  
  25. if SERVER then
  26.  
  27.     local function Spawn(ply, cat, subcat, item)
  28.  
  29.         if ply.IsBanned and ply:IsBanned() then return end
  30.  
  31.         if not ply:Alive() then ply:Notify(BaseWars.LANG.DeadBuy, BASEWARS_NOTIFICATION_ERROR) return end
  32.  
  33.         local l = SpawnList and SpawnList
  34.  
  35.         if not l then return end
  36.  
  37.         if not cat or not item then return end
  38.  
  39.         local i = l[cat]
  40.  
  41.         if not i then return end
  42.  
  43.         i = i[subcat]
  44.  
  45.         if not i then return end
  46.  
  47.         i = i[item]
  48.  
  49.         if not i then return end
  50.  
  51.         local model, price, ent, sf, lim = i.Model, i.Price, i.ClassName, i.UseSpawnFunc, i.Limit
  52.         local gun, drug, ammo, ignore_raid = i.Gun, i.Drug, i.Ammo, i.IgnoreRaid
  53.  
  54.         local vip = i.VIP
  55.         local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, ply:GetUserGroup()) or ply:IsAdmin())
  56.  
  57.         local level = i.Level
  58.         if gun and (not level or level < BaseWars.Config.LevelSettings.BuyWeapons) then level = BaseWars.Config.LevelSettings.BuyWeapons end
  59.  
  60.         if (level and not ply:HasLevel(level)) or (vip and not HasVIP) then
  61.  
  62.             ply:EmitSound("buttons/button10.wav")
  63.  
  64.         return end
  65.  
  66.         local tr
  67.  
  68.         if ent then
  69.  
  70.             tr = {}
  71.  
  72.             tr.start = ply:EyePos()
  73.             tr.endpos = tr.start + ply:GetAimVector() * 85
  74.             tr.filter = ply
  75.  
  76.             tr = util.TraceLine(tr)
  77.  
  78.         else
  79.  
  80.             tr = ply:GetEyeTraceNoCursor()
  81.  
  82.             if not tr.Hit then return end
  83.  
  84.         end
  85.  
  86.         local SpawnPos = tr.HitPos + BaseWars.Config.SpawnOffset
  87.         local SpawnAng = ply:EyeAngles()
  88.         SpawnAng.p = 0
  89.         SpawnAng.y = SpawnAng.y + 180
  90.         SpawnAng.y = math.Round(SpawnAng.y / 45) * 45
  91.  
  92.         if not gun and not drug and not ignore_raid and not ammo and ply:InRaid() then
  93.  
  94.             ply:Notify(BaseWars.LANG.CannotPurchaseRaid, BASEWARS_NOTIFICATION_ERROR)
  95.  
  96.         return end
  97.        
  98.         if gun and string.match(ent, "cw_flash_grenade") or string.match(ent, "cw_frag_grenade") or string.match(ent, "cw_smoke_grenade") then
  99.             if GrenadeTimer = 0 then
  100.                 GrenadeTimer = 1
  101.                 return true end
  102.             else
  103.             ply:Notify("You may only purchase a grenade once every 30 seconds", BASEWARS_NOTIFICATION_ERROR)
  104.                 timer.Simple(30, function()
  105.                 GrenadeTimer = 0
  106.                 end)
  107.             end
  108.            
  109.            
  110.         end
  111.        
  112.  
  113.         if ent and not ply:InRaid() then
  114.             if string.match(ent, "bw_weapon_c4") or string.match(ent, "bw_explosive_nuke") or string.match(ent, "bw_explosive_bigbomb") then
  115.                 ply:Notify("You cannot purchase these unless you're in an active raid!", BASEWARS_NOTIFICATION_ERROR)
  116.             return end
  117.         end
  118.  
  119.         if lim then
  120.  
  121.             local Amount = ply:GetTable()["limit_" .. ent] or 0
  122.             ply:GetTable()["limit_" .. ent] = Amount
  123.  
  124.             if lim and lim <= Amount then
  125.  
  126.                 ply:Notify(string.format(BaseWars.LANG.EntLimitReached, ent), BASEWARS_NOTIFICATION_ERROR)
  127.  
  128.             return end
  129.  
  130.         end
  131.  
  132.         local Res, Msg
  133.         if gun then
  134.  
  135.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyGun", ply, ent) -- Player, Gun class
  136.  
  137.         elseif drug then
  138.  
  139.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyDrug", ply, ent) -- Player, Drug type
  140.  
  141.         elseif ent then
  142.  
  143.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyEntity", ply, ent) -- Player, Entity class
  144.  
  145.         else
  146.  
  147.             Res, Msg = hook.Run("BaseWars_PlayerCanBuyProp", ply, ent) -- Player, Entity class
  148.  
  149.         end
  150.  
  151.         if Res == false then
  152.  
  153.             if Msg then
  154.  
  155.                 ply:Notify(Msg, BASEWARS_NOTIFICATION_ERROR)
  156.  
  157.             end
  158.  
  159.         return end
  160.  
  161.         if price > 0 then
  162.  
  163.             local plyMoney = ply:GetMoney()
  164.  
  165.             if plyMoney < price then
  166.  
  167.                 ply:Notify(BaseWars.LANG.SpawnMenuMoney, BASEWARS_NOTIFICATION_ERROR)
  168.  
  169.             return end
  170.  
  171.             ply:SetMoney(plyMoney - price)
  172.             ply:EmitSound("mvm/mvm_money_pickup.wav")
  173.  
  174.             ply:Notify(string.format(BaseWars.LANG.SpawnMenuBuy, item, BaseWars.NumberFormat(price)), BASEWARS_NOTIFICATION_MONEY)
  175.  
  176.         end
  177.  
  178.         if gun then
  179.  
  180.             local Ent = ents.Create("bw_weapon")
  181.                 Ent.WeaponClass = ent
  182.                 Ent.Model = model
  183.                 Ent:SetPos(SpawnPos)
  184.                 Ent:SetAngles(SpawnAng)
  185.             Ent:Spawn()
  186.             Ent:Activate()
  187.             Ent:CPPISetOwner(ply)
  188.  
  189.             hook.Run("BaseWars_PlayerBuyGun", ply, Ent) -- Player, Gun entity
  190.  
  191.         return end
  192.  
  193.         if drug then
  194.  
  195.             local Rand = (ent == "Random")
  196.             local Ent = ents.Create("bw_drink_drug")
  197.                 if not Rand then
  198.  
  199.                     Ent:SetDrugEffect(ent)
  200.                     Ent.Random = false
  201.  
  202.                 end
  203.  
  204.                 Ent:SetPos(SpawnPos)
  205.                 Ent:SetAngles(SpawnAng)
  206.             Ent:Spawn()
  207.             Ent:Activate()
  208.             Ent:CPPISetOwner(ply)
  209.  
  210.             hook.Run("BaseWars_PlayerBuyDrug", ply, Ent) -- Player, Drug entity
  211.  
  212.         return end
  213.  
  214.         local prop
  215.         local noundo
  216.  
  217.         if ent then
  218.  
  219.             local newEnt = ents.Create(ent)
  220.  
  221.             if not newEnt then return end
  222.  
  223.             if newEnt.SpawnFunction and sf then
  224.  
  225.                 newEnt = newEnt:SpawnFunction(ply, tr, ent)
  226.  
  227.                 if newEnt.CPPISetOwner then
  228.  
  229.                     newEnt:CPPISetOwner(ply)
  230.  
  231.                 end
  232.  
  233.                 if newEnt.SetCreator then
  234.  
  235.                     newEnt:SetCreator(ply)
  236.  
  237.                 end
  238.  
  239.                 if lim then
  240.  
  241.                     LimitDeduct(newEnt, ent, ply)
  242.  
  243.                 end
  244.  
  245.                 newEnt.CurrentValue = price
  246.                 if newEnt.SetUpgradeCost then newEnt:SetUpgradeCost(price) end
  247.  
  248.                 newEnt.DoNotDuplicate = true
  249.  
  250.                 hook.Run("BaseWars_PlayerBuyEntity", ply, newEnt) -- Player, Entity
  251.  
  252.             return end
  253.  
  254.             if lim then
  255.  
  256.                 LimitDeduct(newEnt, ent, ply)
  257.  
  258.             end
  259.  
  260.             newEnt.CurrentValue = price
  261.             if newEnt.SetUpgradeCost then newEnt:SetUpgradeCost(price) end
  262.  
  263.             newEnt.DoNotDuplicate = true
  264.  
  265.             prop = newEnt
  266.             noundo = true
  267.  
  268.         end
  269.  
  270.         if not prop then prop = ents.Create(ent or "prop_physics") end
  271.         if not noundo then undo.Create("prop") end
  272.  
  273.         if not prop or not IsValid(prop) then return end
  274.  
  275.         prop:SetPos(SpawnPos)
  276.         prop:SetAngles(SpawnAng)
  277.  
  278.         if model and not ent then
  279.  
  280.             prop:SetModel(model)
  281.  
  282.         end
  283.  
  284.         if lim and not ent then
  285.  
  286.             LimitDeduct(prop, ent, ply)
  287.  
  288.         end
  289.  
  290.         local vname = i.VehicleName
  291.         local vt = list.Get("Vehicles")[vname]
  292.  
  293.         if vname and vt then
  294.             if prop.SetVehicleClass then prop:SetVehicleClass(vname) end
  295.  
  296.             prop.VehicleTable = vt
  297.             prop.ClassOverride = vt.Class
  298.             prop.VehicleName = vname
  299.  
  300.             if vt.KeyValues then
  301.                 for k, v in pairs(vt.KeyValues) do
  302.                     prop:SetKeyValue(k, v)
  303.                 end
  304.             end
  305.  
  306.             if vt.Members then
  307.                 table.Merge(prop, vt.Members)
  308.             end
  309.  
  310.             if vt.Model then
  311.                 prop:SetModel(vt.Model)
  312.             end
  313.         end
  314.  
  315.         prop:Spawn()
  316.         prop:Activate()
  317.  
  318.         if vname and vt then
  319.             hook.Run("PlayerSpawnedVehicle", ply, prop)
  320.         end
  321.  
  322.         prop:DropToFloor()
  323.  
  324.         local phys = prop:GetPhysicsObject()
  325.  
  326.         if IsValid(phys) then
  327.  
  328.             if i.ShouldFreeze then
  329.  
  330.                 phys:EnableMotion(false)
  331.  
  332.             else
  333.  
  334.                 phys:Wake()
  335.  
  336.             end
  337.  
  338.         end
  339.  
  340.         undo.AddEntity(prop)
  341.         undo.SetPlayer(ply)
  342.         undo.Finish()
  343.  
  344.         if prop.CPPISetOwner then
  345.  
  346.             prop:CPPISetOwner(ply)
  347.  
  348.         end
  349.  
  350.         if ent then
  351.  
  352.             hook.Run("BaseWars_PlayerBuyEntity", ply, prop) -- Player, Entity
  353.  
  354.         else
  355.  
  356.             hook.Run("BaseWars_PlayerBuyProp", ply, prop) -- Player, Prop
  357.  
  358.         end
  359.  
  360.     end
  361.  
  362.     concommand.Add("basewars_spawn",function(ply,_,args)
  363.  
  364.         if not IsValid(ply) then return end
  365.         Spawn(ply, args[1], args[2], args[3], args[4])
  366.  
  367.     end)
  368.  
  369.     local function Disallow_Spawning(ply, ...)
  370.  
  371.         --BaseWars.UTIL.Log(ply, ...)
  372.  
  373.         if not ply:IsAdmin()  then
  374.  
  375.             ply:Notify(BaseWars.LANG.UseSpawnMenu, BASEWARS_NOTIFICATION_ERROR)
  376.             return false
  377.  
  378.         end
  379.  
  380.     end
  381.  
  382.     local name = "BaseWars.Disallow_Spawning"
  383.  
  384.     if BaseWars.Config.RestrictProps then
  385.  
  386.         hook.Add("PlayerSpawnObject",   name, Disallow_Spawning)
  387.  
  388.     end
  389.  
  390.     hook.Add("PlayerSpawnSENT",         name, Disallow_Spawning)
  391.     hook.Add("PlayerGiveSWEP",          name, Disallow_Spawning)
  392.     hook.Add("PlayerSpawnSWEP",         name, Disallow_Spawning)
  393.     hook.Add("PlayerSpawnVehicle",  name, Disallow_Spawning)
  394.     hook.Add("PlayerSpawnNPC",          name, Disallow_Spawning)
  395.  
  396. return end
  397.  
  398. local overlayFont = "BaseWars.SpawnList.Overlay"
  399. surface.CreateFont(overlayFont,{
  400.  
  401.     font = "Roboto",
  402.     size = BaseWars.Config.PricesSize,
  403.     weight = 900,
  404.  
  405. })
  406.  
  407. local overlayFont2 = "BaseWars.SpawnList.Overlay.Small"
  408. surface.CreateFont(overlayFont2,{
  409.  
  410.     font = "Roboto",
  411.     size = 12,
  412.     weight = 800,
  413.  
  414. })
  415.  
  416. local PANEL = {}
  417.  
  418. function PANEL:Init()
  419.  
  420.     self.Panels = {}
  421.  
  422. end
  423.  
  424. function PANEL:AddPanel(name,pnl)
  425.  
  426.     self.Panels[name] = pnl
  427.  
  428.     if not self.CurrentPanel then
  429.  
  430.         pnl:Show()
  431.         self.CurrentPanel = pnl
  432.  
  433.     else
  434.  
  435.         pnl:Hide()
  436.  
  437.     end
  438.  
  439. end
  440.  
  441. function PANEL:SwitchTo(name,instant)
  442.  
  443.     local pnl = self.Panels[name]
  444.  
  445.     if not pnl then return end
  446.  
  447.     local oldpnl = self.CurrentPanel
  448.  
  449.     if pnl == oldpnl then return end
  450.  
  451.     if oldpnl then
  452.  
  453.         oldpnl:AlphaTo(0, instant and 0 or 0.2, 0, function(_,pnl) pnl:Hide() end)
  454.  
  455.     end
  456.  
  457.     pnl:Show()
  458.     pnl:AlphaTo(255, instant and 0 or 0.2, 0, function() end)
  459.  
  460.     self.CurrentPanel = pnl
  461.  
  462. end
  463.  
  464. vgui.Register("BaseWars.PanelCollection", PANEL, "Panel")
  465.  
  466. local PANEL = {}
  467.  
  468. local white = Color(255, 255, 255)
  469. local gray = Color(192, 192, 192)
  470. local black = Color(0, 0, 0)
  471. local errorcolor = Color(255, 100, 100)
  472. local highlight = Color(100, 100, 100, 200)
  473. local orange = Color (255, 165, 0, 200)
  474.  
  475. function PANEL:CheckError()
  476.  
  477.     return false
  478.  
  479. end
  480.  
  481. function PANEL:Paint(w, h)
  482.  
  483.     draw.RoundedBox(4, 0, 0, w, h, black)
  484.     draw.RoundedBox(4, 1, 1, w - 2, h - 2, self:CheckError() and errorcolor or white)
  485.  
  486.     self:DrawTextEntryText(black, highlight, gray)
  487.  
  488.     return false
  489.  
  490. end
  491.  
  492. vgui.Register("BaseWars.ErrorCheckTextEntry", PANEL, "DTextEntry")
  493.  
  494. local white = Color(255, 255, 255)
  495. local trans = Color(0, 0, 0, 0)
  496.  
  497. local blue  = Color(0, 90, 200, 180)
  498. local green = Color(90, 200, 0, 180)
  499. local grey  = Color(90, 90, 90, 180)
  500. local red   = Color(200, 0, 20, 180)
  501.  
  502. local shade = Color(0, 0, 0, 200)
  503.  
  504. local SpawnList = BaseWars.SpawnList
  505.  
  506. if not SpawnList then return end
  507.  
  508. local Models = SpawnList
  509.  
  510. local enable_popup = CreateClientConVar("bw_enable_popup", "1", true, false)
  511.  
  512. local function MakeTab(type)
  513.     return function(pnl)
  514.  
  515.         local cats = pnl:Add("DCategoryList")
  516.  
  517.         cats:Dock(FILL)
  518.  
  519.         function cats:Paint() end
  520.  
  521.         for catName, subT in SortedPairs(Models[type]) do
  522.  
  523.             if catName == "__inf" then continue end
  524.  
  525.             local cat = cats:Add(catName)
  526.  
  527.             local iLayout = vgui.Create("DIconLayout")
  528.  
  529.             iLayout:Dock(FILL)
  530.  
  531.             iLayout:SetSpaceX(4)
  532.             iLayout:SetSpaceY(4)
  533.  
  534.             for name, tab in SortedPairsByMemberValue(subT, "Price") do
  535.  
  536.                 local model = tab.Model
  537.                 local money = tab.Price
  538.                 local level = tab.Level
  539.                 local vip = tab.VIP
  540.  
  541.                 if tab.Gun and (not level or level < BaseWars.Config.LevelSettings.BuyWeapons) then level = BaseWars.Config.LevelSettings.BuyWeapons end
  542.  
  543.                 local icon = iLayout:Add("SpawnIcon")
  544.  
  545.                 icon:SetModel(model)
  546.                 icon:SetTooltip(name .. (money > 0 and " (" .. string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(money)) .. ")" or ""))
  547.  
  548.                 local is = BaseWars.Config.IconSize
  549.                 icon:SetSize(is, is)
  550.  
  551.                 function icon:DoClick()
  552.  
  553.                     local HasLevel = not level or LocalPlayer():HasLevel(level)
  554.                     local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, LocalPlayer():GetUserGroup()) or LocalPlayer():IsAdmin())
  555.                     if not HasLevel or not HasVIP then
  556.  
  557.                         surface.PlaySound("buttons/button10.wav")
  558.  
  559.                     return end
  560.  
  561.                     local myMoney = LocalPlayer():GetMoney()
  562.  
  563.                     surface.PlaySound("ui/buttonclickrelease.wav")
  564.  
  565.                     local a1, a2, a3 = type, catName, name
  566.  
  567.                     local function DoIt()
  568.  
  569.                         RunConsoleCommand("basewars_spawn", type, catName, name)
  570.  
  571.                     end
  572.  
  573.                     if (money > 0) and not (myMoney / 100 > money) then
  574.  
  575.                         if myMoney < money then
  576.  
  577.                             Derma_Message(BaseWars.LANG.SpawnMenuMoney, "Error")
  578.  
  579.                         return end
  580.  
  581.                         if enable_popup:GetBool() then
  582.                             Derma_Query(string.format(BaseWars.LANG.SpawnMenuBuyConfirm, name, BaseWars.NumberFormat(money)),
  583.                                 BaseWars.LANG.SpawnMenuConf, "   " .. BaseWars.LANG.Yes .. "   ", DoIt, "   " .. BaseWars.LANG.No .. "   ")
  584.                         else
  585.                             DoIt()
  586.                         end
  587.  
  588.                     else
  589.  
  590.                         DoIt()
  591.  
  592.                     end
  593.  
  594.  
  595.                 end
  596.  
  597.                 function icon:Paint(w, h)
  598.  
  599.                     local myMoney = LocalPlayer():GetMoney()
  600.                     local HasLevel = not level or LocalPlayer():HasLevel(level)
  601.                     local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, LocalPlayer():GetUserGroup()) or LocalPlayer():IsAdmin())
  602.  
  603.                     local DrawCol = green
  604.  
  605.                     if not HasVIP then
  606.  
  607.                         DrawCol = orange
  608.  
  609.                     elseif not HasLevel then
  610.  
  611.                         DrawCol = grey
  612.  
  613.                     elseif money <= 0 then
  614.  
  615.                         DrawCol = trans
  616.  
  617.                     elseif money >= myMoney * 2 then
  618.  
  619.                         DrawCol = grey
  620.  
  621.                     elseif money > myMoney then
  622.  
  623.                         DrawCol = red
  624.  
  625.                     elseif money < myMoney / 100 then
  626.  
  627.                         DrawCol = blue
  628.  
  629.                     end
  630.  
  631.                     draw.RoundedBox(4, 1, 1, w - 2, h - 2, DrawCol)
  632.  
  633.                 end
  634.  
  635.                 --local pO = icon.PaintOver
  636.  
  637.                 function icon:PaintOver(w, h)
  638.  
  639.                     --pO(self, w, h)
  640.  
  641.                     local text
  642.  
  643.                     local HasVIP = not vip or (table.HasValue(BaseWars.Config.VIPRanks, LocalPlayer():GetUserGroup()) or LocalPlayer():IsAdmin())
  644.                     if not HasVIP then
  645.  
  646.                         text = "VIP ONLY"
  647.  
  648.                         draw.DrawText(text, overlayFont2, w / 2, h / 2, shade, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  649.                         draw.DrawText(text, overlayFont2, w / 2 - 2, h / 2 - 2, white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  650.  
  651.                     return end
  652.  
  653.                     local HasLevel = not level or LocalPlayer():HasLevel(level)
  654.                     if not HasLevel then
  655.  
  656.                         text = "LVL " .. level
  657.  
  658.                         draw.DrawText(text, overlayFont2, w / 2, h / 2, shade, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  659.                         draw.DrawText(text, overlayFont2, w / 2 - 2, h / 2 - 2, white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  660.  
  661.                     return end
  662.  
  663.                     if money > 0 then
  664.  
  665.                         text = string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(money))
  666.  
  667.                         draw.DrawText(text, overlayFont, w - 2, h - 14, shade, TEXT_ALIGN_RIGHT)
  668.                         draw.DrawText(text, overlayFont, w - 4, h - 16, white, TEXT_ALIGN_RIGHT)
  669.  
  670.                     end
  671.  
  672.                     text = (utf8.sub and utf8.sub(name, 1, 11) or string.sub(name, 1, 11)) .. ((utf8.len and utf8.len(name) or string.len(name)) <= 11 and "" or "...")
  673.  
  674.                     draw.DrawText(text, overlayFont2, 4, 4, shade, TEXT_ALIGN_LEFT)
  675.                     draw.DrawText(text, overlayFont2, 2, 2, white, TEXT_ALIGN_LEFT)
  676.  
  677.                 end
  678.  
  679.             end
  680.  
  681.             cat:SetContents(iLayout)
  682.             cat:SetExpanded(true)
  683.  
  684.         end
  685.  
  686.     end
  687.  
  688. end
  689.  
  690. local Panels = {
  691.  
  692.     Default = function(pnl)
  693.  
  694.         local lbl = pnl:Add("ContentHeader")
  695.  
  696.         lbl:SetPos(16, 0)
  697.  
  698.         lbl:SetText(BaseWars.LANG.BaseWarsSpawnlist)
  699.  
  700.         local lbl = pnl:Add("DLabel")
  701.  
  702.         lbl:SetPos(16, 64)
  703.  
  704.         lbl:SetFont("DermaLarge")
  705.         lbl:SetText(BaseWars.LANG.CategoryLeft)
  706.  
  707.         lbl:SetBright(true)
  708.  
  709.         lbl:SizeToContents()
  710.  
  711.     end,
  712.  
  713. }
  714.  
  715. local function MakeSpawnList()
  716.  
  717.     local pnl = vgui.Create("DPanel")
  718.  
  719.     function pnl:Paint(w,h) end
  720.  
  721.     local leftPanel = pnl:Add("DPanel")
  722.  
  723.     leftPanel:Dock(LEFT)
  724.     leftPanel:SetWide(256 - 64)
  725.     leftPanel:DockPadding(1, 1, 1, 1)
  726.  
  727.     local tree = leftPanel:Add("DTree")
  728.  
  729.     function tree:Paint() end
  730.  
  731.     tree:Dock(FILL)
  732.  
  733.     local rightPanel = pnl:Add("BaseWars.PanelCollection")
  734.  
  735.     rightPanel:Dock(FILL)
  736.  
  737.     rightPanel:SetMouseInputEnabled(true)
  738.     rightPanel:SetKeyboardInputEnabled(true)
  739.  
  740.     local defaultNode = tree:AddNode(BaseWars.LANG.BaseWarsSpawnlist)
  741.  
  742.     function defaultNode:OnNodeSelected()
  743.  
  744.         rightPanel:SwitchTo("Default")
  745.  
  746.     end
  747.  
  748.     defaultNode:SetIcon("icon16/application_view_tile.png")
  749.  
  750.     defaultNode:SetExpanded(true, true)
  751.  
  752.     defaultNode:GetRoot():SetSelectedItem(defaultNode)
  753.  
  754.     local i = 0
  755.     for key, build in SortedPairs(BaseWars.SpawnList) do
  756.         i = i + 1
  757.         local idx = tostring(i)
  758.  
  759.         local node = defaultNode:AddNode(build.__inf.name or "(UNNAMED)")
  760.  
  761.         local ico = build.__inf.icon or "icon16/cancel.png"
  762.         node:SetIcon(ico)
  763.  
  764.         local container = rightPanel:Add("DPanel")
  765.         function container:Paint() end
  766.         container:Dock(FILL)
  767.  
  768.         local ap = MakeTab(key)
  769.         pcall(ap, container)
  770.  
  771.         rightPanel:AddPanel(idx, container)
  772.  
  773.         function node:OnNodeSelected()
  774.             rightPanel:SwitchTo(idx)
  775.         end
  776.  
  777.     end
  778.  
  779.     for name, build in next, Panels do
  780.  
  781.         local container = rightPanel:Add("DPanel")
  782.         function container:Paint() end
  783.         container:Dock(FILL)
  784.  
  785.         pcall(build, container)
  786.         rightPanel:AddPanel(name, container)
  787.  
  788.     end
  789.  
  790.     rightPanel:SwitchTo("Default", true)
  791.  
  792.     return pnl
  793.  
  794. end
  795.  
  796. spawnmenu.AddCreationTab("#spawnmenu.category.basewars", MakeSpawnList, "icon16/building.png", BaseWars.Config.RestrictProps and -100 or 2)
  797.  
  798. spawnmenu.Reload = spawnmenu.Reload or concommand.GetTable().spawnmenu_reload
  799. concommand.Add("spawnmenu_reload", function(...)
  800.     spawnmenu.Reload(...)
  801.     if GetConVar("developer"):GetInt() < 2 then
  802.         local toRemove = {
  803.             "#spawnmenu.category.saves",
  804.             "#spawnmenu.category.dupes",
  805.             "#spawnmenu.category.postprocess",
  806.             "#spawnmenu.category.vehicles",
  807.             "#spawnmenu.category.weapons",
  808.             "#spawnmenu.category.npcs",
  809.             "#spawnmenu.category.entities"
  810.         }
  811.         local i = 1
  812.         for k, v in next, g_SpawnMenu.CreateMenu.Items do
  813.             if table.HasValue(toRemove, v.Name) then
  814.                 g_SpawnMenu.CreateMenu.tabScroller.Panels[i] = nil
  815.                 g_SpawnMenu.CreateMenu.Items[k] = nil
  816.                 v.Tab:Remove()
  817.             end
  818.             i = i + 1
  819.         end
  820.     end
  821. end)
  822.  
  823. BaseWars.SpawnMenuReload = BaseWars.SpawnMenuReload or concommand.GetTable().spawnmenu_reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement