Advertisement
Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.22 KB | None | 0 0
  1. /*---------------------------------------------------------------------------
  2.  
  3. Creator: TheCodingBeast - TheCodingBeast.com
  4. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
  5. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/
  6.  
  7. ---------------------------------------------------------------------------*/
  8.  
  9. --[[---------------------------------------------------------
  10. Fonts
  11. -----------------------------------------------------------]]
  12. for i=0,24 do
  13.  
  14. --> Size
  15. local size = 10+i
  16.  
  17. --> Font
  18. surface.CreateFont("TCBDealer_"..size, {
  19. font = "Trebuchet24",
  20. size = size,
  21. })
  22.  
  23. end
  24.  
  25. --[[---------------------------------------------------------
  26. Convars
  27. -----------------------------------------------------------]]
  28. CreateClientConVar("tcb_cardealer_r", 0, true, true)
  29. CreateClientConVar("tcb_cardealer_g", 0, true, true)
  30. CreateClientConVar("tcb_cardealer_b", 0, true, true)
  31.  
  32. --[[---------------------------------------------------------
  33. Chat Text
  34. -----------------------------------------------------------]]
  35. local function chatText()
  36. chat.AddText(Color(52, 152, 219), "[Dealer]", Color(255, 255, 255), " "..net.ReadString())
  37. end
  38. net.Receive("TCBDealerChat", chatText)
  39.  
  40.  
  41. --[[---------------------------------------------------------
  42. Derma Blur - Credits: Mrkrabz
  43. -----------------------------------------------------------]]
  44. local blur = Material("pp/blurscreen")
  45. local function DrawBlur(panel, amount)
  46. local x, y = panel:LocalToScreen(0, 0)
  47. local scrW, scrH = ScrW(), ScrH()
  48. surface.SetDrawColor(255, 255, 255)
  49. surface.SetMaterial(blur)
  50. for i = 1, 3 do
  51. blur:SetFloat("$blur", (i / 3) * (amount or 6))
  52. blur:Recompute()
  53. render.UpdateScreenEffectTexture()
  54. surface.DrawTexturedRect(x * -1, y * -1, scrW, scrH)
  55. end
  56. end
  57.  
  58. --[[---------------------------------------------------------
  59. Dealer Menu
  60. -----------------------------------------------------------]]
  61. local function carDealer()
  62.  
  63. --> Variables
  64. local vehiclesTable = TCBDealer.vehicleTable
  65. local ownedTable = net.ReadTable()
  66.  
  67. local dealerID = net.ReadInt(32)
  68.  
  69. local w = 450
  70. local h = 602
  71.  
  72. --> Frame
  73. local frame = vgui.Create("DFrame")
  74. frame:SetPos(ScrW()/2-w/2, ScrH())
  75. frame:SetSize(w, h)
  76. frame:SetTitle("")
  77. frame:SetDraggable(false)
  78. frame:ShowCloseButton(false)
  79. frame:MakePopup()
  80. frame:MoveTo(ScrW()/2-w/2, ScrH()/2-h/2, 0.2, 0, -1)
  81.  
  82. frame.Paint = function(pnl, w, h)
  83.  
  84. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 100))
  85. draw.RoundedBox(0, 1, 1, w-2, h-2, Color(255, 255, 255, 255))
  86.  
  87. draw.RoundedBox(0, 1, 1, w-2, 40, Color(63, 81, 181, 255))
  88. draw.SimpleText(TCBDealer.settings.frameTitle.." - Car Dealer", "TCBDealer_24", 11, 41-20, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
  89.  
  90. end
  91.  
  92. --> Close
  93. local close = vgui.Create("DButton", frame)
  94. close:SetPos(w-65-7, 41/2-24/2)
  95. close:SetSize(65, 26)
  96. close:SetText("")
  97.  
  98. close.DoClick = function()
  99.  
  100. frame:MoveTo(ScrW()/2-w/2, ScrH(), 0.2, 0, -1, function()
  101. frame:Remove()
  102. end)
  103.  
  104. end
  105.  
  106. close.Paint = function(pnl, w, h)
  107.  
  108. draw.RoundedBox(3, 0, 0, w, h, Color(244, 67, 54, 255))
  109. draw.SimpleText("x", "TCBDealer_24", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  110.  
  111. if close.Hovered then
  112. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  113. end
  114.  
  115. end
  116.  
  117. --> Color Picker
  118. if TCBDealer.settings.colorPicker then
  119.  
  120. --> Convars
  121. local clrValR = GetConVar("tcb_cardealer_r"):GetInt() or 0
  122. local clrValG = GetConVar("tcb_cardealer_g"):GetInt() or 0
  123. local clrValB = GetConVar("tcb_cardealer_b"):GetInt() or 0
  124.  
  125. --> Variables
  126. local pickerExapnded = false
  127.  
  128. local pickerPanel = nil
  129. local pickerColor = Color(clrValR, clrValG, clrValB, 255)
  130.  
  131. --> Color
  132. local color = vgui.Create("DButton", frame)
  133. color:SetPos(w-26-12-close:GetWide(), 41/2-24/2)
  134. color:SetSize(26, 26)
  135. color:SetText("")
  136.  
  137. color.DoClick = function()
  138.  
  139. if pickerExapnded then
  140.  
  141. --> Variables
  142. pickerPanel:Remove()
  143. pickerExapnded = false
  144.  
  145. else
  146.  
  147. --> Variables
  148. pickerExapnded = true
  149.  
  150. --> Panel
  151. local colorPanel = vgui.Create("DPanel", frame)
  152. colorPanel:SetSize(200, 200)
  153. colorPanel:SetPos(w-277, 40-11)
  154.  
  155. colorPanel.Paint = function(pnl, w, h)
  156. draw.RoundedBox(3, 0, 0, w, h, Color(0, 0, 0, 100))
  157. draw.RoundedBoxEx(3, 2, 2, w-4, h-4, pickerColor, true, false, true, true)
  158. draw.RoundedBox(0, w-24, 0, 22, 2, pickerColor)
  159. end
  160.  
  161. pickerPanel = colorPanel
  162.  
  163. --> Mixer
  164. local mixer = vgui.Create("DColorMixer", colorPanel)
  165. mixer:Dock(FILL)
  166. mixer:DockPadding(10, 10, 10, 10)
  167. mixer:SetWangs(false)
  168. mixer:SetAlphaBar(false)
  169. mixer:SetPalette(false)
  170. mixer:SetColor(pickerColor)
  171.  
  172. --> Change
  173. mixer.ValueChanged = function()
  174. local clr = mixer:GetColor()
  175. pickerColor = clr
  176.  
  177. RunConsoleCommand("tcb_cardealer_r", clr.r)
  178. RunConsoleCommand("tcb_cardealer_g", clr.g)
  179. RunConsoleCommand("tcb_cardealer_b", clr.b)
  180. end
  181.  
  182. end
  183.  
  184. end
  185.  
  186. color.Paint = function(pnl, w, h)
  187.  
  188. draw.RoundedBox(3, 0, 0, w, h, Color(0, 0, 0, 100))
  189. draw.RoundedBox(3, 2, 2, w-4, h-4, pickerColor)
  190.  
  191. if color.Hovered then
  192. draw.RoundedBox(3, 2, 2, w-4, h-4, Color(255, 255, 255, 6))
  193. end
  194.  
  195. end
  196.  
  197. end
  198.  
  199. --> Panel
  200. local panel = vgui.Create("DScrollPanel", frame)
  201. panel:SetPos(1, 41)
  202. panel:SetSize(w-2, h-2-40)
  203.  
  204. panel.VBar.Paint = function( pnl, w, h ) draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 50) ) end
  205. panel.VBar.btnUp.Paint = function( pnl, w, h ) draw.RoundedBox( 0, 2, 2, w - 4, h - 4, Color( 0, 0, 0, 25 ) ) draw.DrawText( "▲", "HudHintTextSmall", 3, 2, Color( 255, 255, 255, 255 ) ) end
  206. panel.VBar.btnDown.Paint = function( pnl, w, h ) draw.RoundedBox( 0, 2, 2, w - 4, h - 4, Color( 0, 0, 0, 25 ) ) draw.DrawText( "▼", "HudHintTextSmall", 3, 2, Color( 255, 255, 255, 255 ) ) end
  207. panel.VBar.btnGrip.Paint = function( pnl, w, h ) draw.RoundedBox( 4, 3, 2, w - 6, h - 4, Color( 63, 81, 181, 255 ) ) end
  208.  
  209. --> Slide EWW :(
  210. local slide = vgui.Create("DPanel", panel)
  211. slide:SetPos(0, 0)
  212. slide:SetSize(1, panel:GetTall()+1)
  213.  
  214. --> Store
  215. local cvehicle = nil
  216. local currentVehicle = LocalPlayer():GetNWEntity("currentVehicle")
  217. if IsValid(currentVehicle) and LocalPlayer():GetPos():Distance(currentVehicle:GetPos()) <= TCBDealer.settings.storeDistance then
  218. cvehicle = currentVehicle
  219. end
  220.  
  221. local posY = 0
  222. if cvehicle then
  223.  
  224. --> Panel
  225. local store = vgui.Create("DPanel", panel)
  226. store:SetPos(0, posY)
  227. store:SetSize((w-2)-16, 80)
  228.  
  229. store.Paint = function(pnl, w, h)
  230.  
  231. --> Background
  232. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 25))
  233. draw.RoundedBox(0, 0, h-1, w, 1, Color(0, 0, 0, 50))
  234.  
  235. --> Model
  236. draw.RoundedBox(2, 4, 4, h-8, h-8, Color(0, 0, 0, 40))
  237.  
  238. --> Title
  239. draw.SimpleText("Closest Vehicle", "TCBDealer_24", w/2-15, 25, Color(0, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  240.  
  241. --> Name
  242. draw.SimpleText(cvehicle:GetNWString("dealerName"), "TCBDealer_22", w/2-15, 55, Color(0, 0, 0, 225), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  243.  
  244. end
  245.  
  246. --> Model Preview
  247. local model = vgui.Create("DModelPanel", store)
  248. model:SetSize(store:GetTall()-8, store:GetTall()-8)
  249. model:SetPos(4, 4)
  250. model:SetModel(cvehicle:GetModel())
  251. model:SetColor(cvehicle:GetColor())
  252. model:SetCamPos(Vector(150, -100, 50))
  253.  
  254. --> Store
  255. local storeBtn = vgui.Create("DButton", store)
  256. storeBtn:SetSize(100, store:GetTall()/2-5)
  257. storeBtn:SetPos(store:GetWide()-104, 4+storeBtn:GetTall()/2+1)
  258. storeBtn:SetText("")
  259.  
  260. storeBtn.DoClick = function()
  261. net.Start("TCBDealerStore")
  262. net.WriteInt(dealerID, 32)
  263. net.SendToServer(LocalPlayer())
  264.  
  265. frame:MoveTo(ScrW()/2-w/2, ScrH(), 0.2, 0, -1, function()
  266. frame:Remove()
  267. end)
  268. end
  269.  
  270. storeBtn.Paint = function(pnl, w, h)
  271.  
  272. draw.RoundedBox(3, 0, 0, w, h, Color(231, 76, 60, 255))
  273. draw.SimpleText("Store Vehicle", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  274.  
  275. if storeBtn.Hovered then
  276. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  277. end
  278.  
  279. end
  280.  
  281. --> Position
  282. posY = posY + store:GetTall()
  283.  
  284. end
  285.  
  286. --> Vehicles
  287. local count = 0
  288. for k,v in SortedPairsByMemberValue(vehiclesTable, "price", true) do
  289.  
  290. --> Check
  291. if v.customCheck and !v.customCheck(LocalPlayer()) then continue end
  292.  
  293. --> Count
  294. count = count+1;
  295.  
  296. --> Vehicle Info
  297. local vehicleInfo = {}
  298. if !v.name or !v.mdl then
  299. vehicleInfo = list.Get("Vehicles")[k]
  300. if !vehicleInfo then continue end
  301. end
  302.  
  303. local vehName = v.name or vehicleInfo.Name
  304. local vehMdl = v.mdl or vehicleInfo.Model
  305.  
  306. --> Vehicle Panel
  307. local vehicle = vgui.Create("DPanel", panel)
  308. vehicle:SetPos(0, posY)
  309. vehicle:SetSize((w-2)-16, 80)
  310. vehicle.count = count
  311.  
  312. vehicle.Paint = function(pnl, w, h)
  313.  
  314. --> Stripe
  315. if math.mod(vehicle.count, 2) == 0 then
  316. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 15))
  317. end
  318.  
  319. --> Model
  320. draw.RoundedBox(2, 4, 4, h-8, h-8, Color(0, 0, 0, 40))
  321.  
  322. --> Name
  323. draw.SimpleText(vehName, "TCBDealer_24", w/2-15, 25, Color(0, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  324.  
  325. --> Price
  326. draw.SimpleText("Price: "..DarkRP.formatMoney(v.price), "TCBDealer_22", w/2-15, 55, Color(0, 0, 0, 225), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  327.  
  328. end
  329.  
  330. --> Model Preview
  331. local model = vgui.Create("DModelPanel", vehicle)
  332. model:SetSize(vehicle:GetTall()-8, vehicle:GetTall()-8)
  333. model:SetPos(4, 4)
  334. model:SetModel(vehMdl)
  335. model:SetCamPos(Vector(150, -100, 50))
  336.  
  337. if v.color then
  338. model:SetColor(v.color)
  339. elseif TCBDealer.settings.randomColor then
  340. model:SetColor(Color(math.random(0, 255), math.random(0, 255), math.random(0, 255), 255))
  341. end
  342.  
  343. --> Buttons
  344. if !table.HasValue(ownedTable, k) then
  345.  
  346. --> Purchase
  347. local purchase = vgui.Create("DButton", vehicle)
  348. purchase:SetSize(100, vehicle:GetTall()/2-6)
  349. purchase:SetPos(vehicle:GetWide()-104, 4)
  350. purchase:SetText("")
  351.  
  352. purchase.DoClick = function()
  353. net.Start("TCBDealerPurchase")
  354. net.WriteString(k)
  355. net.SendToServer(LocalPlayer())
  356.  
  357. frame:MoveTo(ScrW()/2-w/2, ScrH(), 0.2, 0, -1, function()
  358. frame:Remove()
  359. end)
  360. end
  361.  
  362. purchase.Paint = function(pnl, w, h)
  363.  
  364. draw.RoundedBox(3, 0, 0, w, h, Color(46, 204, 113, 255))
  365. draw.SimpleText("Purchase", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  366.  
  367. if purchase.Hovered then
  368. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  369. end
  370.  
  371. end
  372.  
  373. --> Preview
  374. local preview = vgui.Create("DButton", vehicle)
  375. preview:SetSize(100, vehicle:GetTall()/2-6)
  376. preview:SetPos(vehicle:GetWide()-104, purchase:GetTall()+8)
  377. preview:SetText("")
  378.  
  379. preview.DoClick = function()
  380. net.Start("TCBDealerSpawn")
  381. net.WriteString(k)
  382. net.WriteInt(dealerID, 32)
  383. net.WriteBool(true)
  384. net.SendToServer(LocalPlayer())
  385.  
  386. frame:MoveTo(ScrW()/2-w/2, ScrH(), 0.2, 0, -1, function()
  387. frame:Remove()
  388. end)
  389. end
  390.  
  391. preview.Paint = function(pnl, w, h)
  392.  
  393. draw.RoundedBox(3, 0, 0, w, h, Color(52, 152, 219, 255))
  394. draw.SimpleText("Test Drive", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  395.  
  396. if preview.Hovered then
  397. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  398. end
  399.  
  400. end
  401.  
  402. else
  403.  
  404. --> Spawn
  405. local spawn = vgui.Create("DButton", vehicle)
  406. spawn:SetSize(100, vehicle:GetTall()/2-6)
  407. spawn:SetPos(vehicle:GetWide()-104, 4)
  408. spawn:SetText("")
  409.  
  410. spawn.DoClick = function()
  411. net.Start("TCBDealerSpawn")
  412. net.WriteString(k)
  413. net.WriteInt(dealerID, 32)
  414. net.WriteBool(false)
  415. net.SendToServer(LocalPlayer())
  416.  
  417. frame:MoveTo(ScrW()/2-w/2, ScrH(), 0.2, 0, -1, function()
  418. frame:Remove()
  419. end)
  420. end
  421.  
  422. spawn.Paint = function(pnl, w, h)
  423.  
  424. draw.RoundedBox(3, 0, 0, w, h, Color(46, 204, 113, 255))
  425. draw.SimpleText("Spawn", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  426.  
  427. if spawn.Hovered then
  428. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  429. end
  430.  
  431. end
  432.  
  433. --> Sell
  434. local sell = vgui.Create("DButton", vehicle)
  435. sell:SetSize(100, vehicle:GetTall()/2-6)
  436. sell:SetPos(vehicle:GetWide()-104, spawn:GetTall()+8)
  437. sell:SetText("")
  438.  
  439. sell.DoClick = function()
  440.  
  441. local cover = vgui.Create("DPanel", frame)
  442. cover:SetSize(w, h)
  443. cover:SetPos(0, 0)
  444.  
  445. cover.Paint = function(pnl, w, h)
  446.  
  447. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 150))
  448. DrawBlur(pnl, 1)
  449.  
  450. end
  451.  
  452. local coverFront = vgui.Create("DPanel", cover)
  453. coverFront:SetSize(cover:GetWide(), 100)
  454. coverFront:SetPos(-500, 40+((cover:GetTall()-40)/2-(100/2)))
  455. coverFront:MoveTo(0, 40+((cover:GetTall()-40)/2-(100/2)), 0.2)
  456.  
  457. coverFront.Paint = function(pnl, w, h)
  458.  
  459. draw.RoundedBox(0, 0, 0, w, h, Color(63, 81, 181, 255))
  460.  
  461. draw.SimpleText("Are you sure you want to sell this vehicle for "..DarkRP.formatMoney(v.price*(TCBDealer.settings.salePercentage/100)).."?", "TCBDealer_22", w/2, 25, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  462.  
  463. end
  464.  
  465. --> Yes
  466. local yes = vgui.Create("DButton", coverFront)
  467. yes:SetSize(coverFront:GetWide()/2-30, 30)
  468. yes:SetPos(20, 50)
  469. yes:SetText("")
  470.  
  471. yes.DoClick = function()
  472. net.Start("TCBDealerSell")
  473. net.WriteString(k)
  474. net.SendToServer(LocalPlayer())
  475.  
  476. frame:MoveTo(ScrW()/2-w/2, ScrH(), 0.2, 0, -1, function()
  477. frame:Remove()
  478. end)
  479. end
  480.  
  481. yes.Paint = function(pnl, w, h)
  482.  
  483. draw.RoundedBox(3, 0, 0, w, h, Color(231, 76, 60, 255))
  484. draw.SimpleText("Yes", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  485.  
  486. if yes.Hovered then
  487. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  488. end
  489.  
  490. end
  491.  
  492. --> Cancel
  493. local cancel = vgui.Create("DButton", coverFront)
  494. cancel:SetSize(coverFront:GetWide()/2-30, 30)
  495. cancel:SetPos(40+yes:GetWide(), 50)
  496. cancel:SetText("")
  497.  
  498. cancel.DoClick = function()
  499. coverFront:MoveTo(-500, 40+((cover:GetTall()-40)/2-(100/2)), 0.2, 0, -1, function()
  500. cover:Remove()
  501. end)
  502. end
  503.  
  504. cancel.Paint = function(pnl, w, h)
  505.  
  506. draw.RoundedBox(3, 0, 0, w, h, Color(46, 204, 113, 255))
  507. draw.SimpleText("Cancel", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  508.  
  509. if cancel.Hovered then
  510. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  511. end
  512.  
  513. end
  514.  
  515. end
  516.  
  517. sell.Paint = function(pnl, w, h)
  518.  
  519. draw.RoundedBox(3, 0, 0, w, h, Color(231, 76, 60, 255))
  520. draw.SimpleText("Sell ("..DarkRP.formatMoney(v.price*(TCBDealer.settings.salePercentage/100))..")", "DermaDefaultBold", w/2, h/2-1, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  521.  
  522. if sell.Hovered then
  523. draw.RoundedBox(3, 0, 0, w, h, Color(255, 255, 255, 6))
  524. end
  525.  
  526. end
  527.  
  528. end
  529.  
  530. --> Position
  531. posY = posY + vehicle:GetTall()
  532.  
  533. end
  534.  
  535. end
  536. net.Receive("TCBDealerMenu", carDealer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement