Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.22 KB | None | 0 0
  1. include("shared.lua")
  2.  
  3. local base_gmodentity = scripted_ents.Get("base_gmodentity")
  4.  
  5. local function createFont(name, size)
  6. surface.CreateFont(name, {
  7. font = "Roboto",
  8. antialias = true,
  9. size = size,
  10. weight = 500,
  11. })
  12. end
  13.  
  14. createFont("MoneyClickerTitle", 48)
  15. createFont("MoneyClickerTooltip", 35)
  16. createFont("MoneyClickerMoney", 75)
  17. createFont("MoneyClickerMoneySmall", 50)
  18. createFont("MoneyClickerPoints", 75)
  19. createFont("MoneyClickerPointsSmall", 50)
  20. createFont("MoneyClickerMoneySide", 30)
  21. createFont("MoneyClickerPointsSide", 30)
  22. createFont("MoneyClickerName", 40)
  23. createFont("MoneyClickerNameSide", 30)
  24.  
  25. createFont("MoneyClickerHealth", 30)
  26. createFont("MoneyClickerHealthSide", 30)
  27.  
  28. local matHeat = Material("moneyclickers/heat")
  29. local matWithdraw = Material("moneyclickers/creditcard")
  30. local matHealth = Material("moneyclickers/health")
  31. local matRepair = Material("moneyclickers/repair")
  32. local matUpgradeAutoClick = Material("moneyclickers/upgrade_autoclick")
  33. local matUpgradeClickPower = Material("moneyclickers/upgrade_clickpower")
  34. local matUpgradeCooling = Material("moneyclickers/upgrade_cooling")
  35. local matUpgradeStorage = Material("moneyclickers/upgrade_storage")
  36.  
  37. local surface_SetDrawColor = surface.SetDrawColor
  38. local surface_DrawRect = surface.DrawRect
  39. local surface_DrawTexturedRect = surface.DrawTexturedRect
  40. local draw_DrawText = draw.DrawText
  41.  
  42. local table_insert = table.insert
  43. local sin = math.sin
  44. local cos = math.cos
  45. local abs = math.abs
  46. local max = math.max
  47. local rad = math.rad
  48. local floor = math.floor
  49.  
  50.  
  51. local function lerpColor(a, b, x)
  52. a.r = a.r + (b.r - a.r) * x
  53. a.g = a.g + (b.g - a.g) * x
  54. a.b = a.b + (b.b - a.b) * x
  55. a.a = a.a + (b.a - a.a) * x
  56.  
  57. return a
  58. end
  59.  
  60. local function processFormattedTextData(data)
  61. local lines = {}
  62. local currLine = 1
  63. lines[currLine] = {}
  64. for j = 1, #data do
  65. local v = data[j]
  66.  
  67. if v == nil then continue end
  68.  
  69. if type(v) == "table" then
  70. lines[currLine] = lines[currLine] or {}
  71. lines[currLine][#lines[currLine] + 1] = v
  72. else
  73. local split = string.Explode("\n", tostring(v))
  74. for i, str in ipairs(split) do
  75. lines[currLine] = lines[currLine] or {}
  76.  
  77. if #str > 0 then
  78. lines[currLine][#lines[currLine] + 1] = str
  79. end
  80.  
  81. if i ~= #split then
  82. currLine = currLine + 1
  83. end
  84. end
  85. end
  86. end
  87.  
  88. return lines
  89. end
  90.  
  91. local function drawFormattedTextData(data, x, y, alpha, alignment)
  92. local tCurY = y
  93. local _, lineHeight = surface.GetTextSize("\n")
  94. local currColor = Color(255, 255, 255)
  95. for _, line in ipairs(data) do
  96. local totalStr = ""
  97. for _, dat in ipairs(line) do
  98. if type(dat) == "string" then
  99. totalStr = totalStr .. dat
  100. end
  101. end
  102.  
  103. local tSubWidth, tSubHeight = surface.GetTextSize(totalStr)
  104. if alignment == TEXT_ALIGN_CENTER then
  105. surface.SetTextPos(x - tSubWidth / 2, tCurY)
  106. elseif alignment == TEXT_ALIGN_RIGHT then
  107. surface.SetTextPos(x - tSubWidth, tCurY)
  108. else
  109. surface.SetTextPos(x, tCurY)
  110. end
  111.  
  112. for _, dat in ipairs(line) do
  113. if type(dat) == "string" then
  114. surface.SetTextColor(ColorAlpha(currColor, alpha))
  115. surface.DrawText(dat)
  116. else
  117. currColor = dat
  118. end
  119. end
  120.  
  121. tCurY = tCurY + lineHeight / 2
  122. end
  123. end
  124.  
  125. -- Thanks to Bobbleheadbob for the arc code, slightly modified to suit my needs.
  126. local function precacheArc(cx,cy,radius,thickness,startang,endang,roughness)
  127. local triarc = {}
  128. -- local deg2rad = math.pi / 180
  129.  
  130. -- Define step
  131. local roughness = max(roughness or 1, 1)
  132. local step = roughness
  133.  
  134. -- Correct start/end ang
  135. local startang,endang = startang or 0, endang or 0
  136.  
  137. if startang > endang then
  138. step = abs(step) * -1
  139. end
  140.  
  141. -- Create the inner circle's points.
  142. local inner = {}
  143. local r = radius - thickness
  144. for deg=startang, endang, step do
  145. local rad = -rad(deg)
  146. -- local rad = deg2rad * deg
  147. local ox, oy = cx+(cos(rad)*r), cy+(-sin(rad)*r)
  148. table_insert(inner, {
  149. x=ox,
  150. y=oy,
  151. u=(ox-cx)/radius + .5,
  152. v=(oy-cy)/radius + .5,
  153. })
  154. end
  155.  
  156.  
  157. -- Create the outer circle's points.
  158. local outer = {}
  159. for deg=startang, endang, step do
  160. local rad = -rad(deg)
  161. -- local rad = deg2rad * deg
  162. local ox, oy = cx+(cos(rad)*radius), cy+(-sin(rad)*radius)
  163. table_insert(outer, {
  164. x=ox,
  165. y=oy,
  166. u=(ox-cx)/radius + .5,
  167. v=(oy-cy)/radius + .5,
  168. })
  169. end
  170.  
  171.  
  172. -- Triangulize the points.
  173. for tri=1,#inner*2 do -- twice as many triangles as there are degrees.
  174. local p1,p2,p3
  175. p1 = outer[floor(tri/2)+1]
  176. p3 = inner[floor((tri+1)/2)+1]
  177. if tri%2 == 0 then --if the number is even use outer.
  178. p2 = outer[floor((tri+1)/2)]
  179. else
  180. p2 = inner[floor((tri+1)/2)]
  181. end
  182.  
  183. table_insert(triarc, {p3,p2,p1})
  184. end
  185.  
  186. -- Return a table of triangles to draw.
  187. return triarc
  188. end
  189.  
  190. -- Draws an arc on your screen.
  191. -- startang and endang are in degrees,
  192. -- radius is the total radius of the outside edge to the center.
  193. -- cx, cy are the x,y coordinates of the center of the arc.
  194. -- roughness determines how many triangles are drawn. Number between 1-360; 2 or 3 is a good number.
  195. local function drawArc(cx,cy,radius,thickness,startang,endang,roughness,color)
  196. surface_SetDrawColor(color)
  197. local arc = precacheArc(cx,cy,radius,thickness,startang,endang,roughness)
  198.  
  199. for k,v in ipairs(arc) do
  200. surface.DrawPoly(v)
  201. end
  202. end
  203.  
  204. local function drawCircle(x, y, radius, seg, color)
  205. local cir = {}
  206.  
  207. table_insert(cir, { x = x, y = y, u = 0.5, v = 0.5 })
  208. for i = 0, 360, seg do
  209. local a = rad(-i)
  210. table_insert(cir, { x = x + sin(a) * radius, y = y + cos(a) * radius, u = sin(a) / 2 + 0.5, v = cos(a) / 2 + 0.5 })
  211. end
  212.  
  213. local a = rad(0) -- This is need for non absolute segment counts
  214. table_insert(cir, { x = x + sin(a) * radius, y = y + cos(a) * radius, u = sin(a) / 2 + 0.5, v = cos(a) / 2 + 0.5 })
  215.  
  216. surface_SetDrawColor(color)
  217. surface.DrawPoly(cir)
  218. end
  219.  
  220. local function rayPlaneIntersection(start, dir, pos, normal)
  221. local a = normal:Dot(dir)
  222.  
  223. -- Check if the ray is aiming towards the plane
  224. -- (fail if it origin behind the plane, but that is checked later)
  225. if a < 0 then
  226. local b = normal:Dot(pos - start)
  227.  
  228. --Check if the ray origin in front of plane
  229. if b < 0 then
  230. return start + dir * (b / a)
  231. end
  232.  
  233. --Check if the ray is parallel to the plane
  234. elseif a == 0 then
  235. --Check if the ray origin inside the plane
  236. if normal:Dot(pos - start) == 0 then
  237. return start
  238. end
  239. end
  240.  
  241. return false
  242. end
  243.  
  244. local function buildTooltipData(...)
  245. local tooltip = { ... }
  246. local tooltipData = processFormattedTextData(tooltip)
  247. local tooltipString = ""
  248. for _, dat in ipairs(tooltip) do
  249. if type(dat) == "string" then
  250. tooltipString = tooltipString .. dat
  251. end
  252. end
  253.  
  254. return {
  255. data = tooltipData,
  256. text = tooltipString
  257. }
  258. end
  259.  
  260.  
  261. local buttonMeta = {}
  262. buttonMeta.__index = buttonMeta
  263.  
  264. buttonMeta.clicked = false
  265. buttonMeta.clickX = 0
  266. buttonMeta.clickY = 0
  267. buttonMeta.alpha = 1
  268. buttonMeta.hoverTime = 0
  269. buttonMeta.clickTime = 0
  270. buttonMeta.clickDuration = 0.3
  271. buttonMeta.tooltipTime = 0
  272. buttonMeta.disabled = false
  273.  
  274. function buttonMeta:GetRadius()
  275. return math.sqrt((self.width * self.width / 4) + (self.height * self.height / 4))
  276. end
  277.  
  278. function buttonMeta:SetTooltip(...)
  279. self.tooltipData = buildTooltipData(...)
  280. end
  281.  
  282. function buttonMeta:OnClick() end
  283.  
  284. function buttonMeta:Think()
  285. if self.disabled then
  286. self.hovering = false
  287. return
  288. end
  289.  
  290. local cx = self.x + self.width / 2
  291. local cy = self.y + self.height / 2
  292.  
  293. local hovering = Vector(self.entity.cursorX, self.entity.cursorY, 0):Distance(Vector(self.x + self.width / 2, self.y + self.height / 2, 0)) < self:GetRadius() + 16
  294. if hovering and not self.hovering then
  295. surface.PlaySound(MCLICKERS.SOUND_UI_HOVER)
  296. end
  297. self.hovering = hovering
  298.  
  299. if hovering and LocalPlayer():KeyDown(IN_USE) and not self.oldUseDown then
  300. self.clicked = true
  301. self.clickTime = CurTime()
  302. self.clickX = self.entity.cursorX
  303. self.clickY = self.entity.cursorY
  304.  
  305. surface.PlaySound(MCLICKERS.SOUND_UI_CLICK)
  306.  
  307. self:OnClick(self.clickX, self.clickY)
  308. end
  309.  
  310. self.oldUseDown = LocalPlayer():KeyDown(IN_USE)
  311. end
  312.  
  313. function buttonMeta:Paint(w, h) end
  314.  
  315. function buttonMeta:PaintOver(w, h)
  316. local cx = self.x + self.width / 2
  317. local cy = self.y + self.height / 2
  318.  
  319. if self.hovering then
  320. self.hoverTime = self.hoverTime + (1 - self.hoverTime) * 0.05
  321. else
  322. self.hoverTime = self.hoverTime + (0 - self.hoverTime) * 0.05
  323. end
  324.  
  325. if self.hoverTime > 0.01 then
  326. drawCircle(cx, cy, self:GetRadius() + 16, 16, Color(255, 255, 255, self.alpha * 20 * self.hoverTime))
  327. end
  328.  
  329. if self.clicked then
  330. local clickFract = math.Clamp((CurTime() - self.clickTime) / self.clickDuration, 0, 1)
  331. local animX = self.clickX + (cx - self.clickX) * clickFract
  332. local animY = self.clickY + (cy - self.clickY) * clickFract
  333. drawCircle(animX, animY, (self:GetRadius() + 16) * clickFract, 24, Color(255, 255, 255, self.alpha * 50 * (1 - max(clickFract * 2 - 1, 0))))
  334.  
  335. if CurTime() - self.clickTime >= self.clickDuration then
  336. self.clicked = false
  337. self.clickTime = 1
  338. end
  339. end
  340.  
  341. if self.tooltipData and self.hovering then
  342. self.tooltipTime = self.tooltipTime + (1 - self.tooltipTime) * 0.05
  343. else
  344. self.tooltipTime = self.tooltipTime + (0 - self.tooltipTime) * 0.05
  345. end
  346.  
  347. if self.tooltipTime > 0.01 then
  348. self.entity:DrawOverlayTooltip(self.x + self.width / 2, self.y + self.height / 2 + 10, "MoneyClickerTooltip", self.tooltipData, self.tooltipTime * self.alpha, TEXT_ALIGN_CENTER)
  349. end
  350. end
  351.  
  352. function ENT:Initialize()
  353. base_gmodentity.Initialize(self)
  354.  
  355. self.info = util.JSONToTable(self:GetClickerInfo())
  356. self.info.upgrades = util.JSONToTable(self:GetClickerUpgradeInfo())
  357.  
  358.  
  359.  
  360. self.buttons = {}
  361.  
  362. self.menuX = 0
  363. self.menuOpened = false
  364. self.menuTime = 0
  365. self.menuContentAlpha = 0
  366.  
  367. self.guiPos = Vector()
  368. self.guiAng = Angle()
  369.  
  370. self.guiWorldPos = Vector()
  371. self.guiWorldAng = Angle()
  372.  
  373. self.cursorX = 0
  374. self.cursorY = 0
  375.  
  376. self.guiWidth = 0
  377. self.guiHeight = 0
  378.  
  379. self.guiTopWidth = 614
  380. self.guiTopHeight = 616
  381.  
  382. self.guiSideWidth = 624
  383. self.guiSideHeight = 223
  384.  
  385. self.guiTopAng = Angle(0, 90, 0)
  386. self.guiTopPos = Vector(-16.35, -15.15, 10.7)
  387.  
  388. self.guiSideAng = Angle(0, 90, 90)
  389. self.guiSidePos = Vector(16.86, -15.405, 11.025)
  390.  
  391. local obbSize = self:OBBMaxs() - self:OBBMins()
  392. self.boundsTopWidth = obbSize.x / 1.09879
  393. self.boundsTopHeight = obbSize.y / 1.034
  394.  
  395. self.boundsSideWidth = obbSize.x / 1.08
  396. self.boundsSideHeight = obbSize.z / 1.052
  397.  
  398. self.boundsWidth = self.boundsTopWidth
  399. self.boundsHeight = self.boundsTopHeight
  400.  
  401. self.side = false
  402. self.sideAnimTime = 1
  403.  
  404. self.clickTopRadius = self.guiTopWidth / 2 - 110
  405. self.clickTopCenterX = self.guiTopWidth / 2
  406. self.clickTopCenterY = self.guiTopHeight / 2 + 70
  407.  
  408.  
  409. self.clickSideRadius = 40
  410. self.clickSideCenterX = 80
  411. self.clickSideCenterY = self.guiSideHeight / 2 + 40
  412.  
  413. self.colPrimary = self.info.colorPrimary
  414. self.colSecondary = self.info.colorSecondary
  415. self.colText = self.info.colorText
  416. self.colHealth = self.info.colorHealth
  417.  
  418. self.colorR = self.colPrimary.r
  419. self.colorG = self.colPrimary.g
  420. self.colorB = self.colPrimary.b
  421.  
  422. -- Buttons
  423. self.buttonMenu = self:AddButton(30, 68, 40, 34)
  424. self.buttonMenu.OnClick = function()
  425. self.menuOpened = not self.menuOpened
  426. self.menuTime = CurTime() + 0.5
  427. end
  428. self.buttonMenu.Paint = function(btn, w, h)
  429. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  430. surface_DrawRect(btn.x, btn.y, w, 6)
  431. surface_DrawRect(btn.x, btn.y + 14, w, 6)
  432. surface_DrawRect(btn.x, btn .y + 28, w, 6)
  433. end
  434. self.buttonMenu:SetTooltip(MCLICKERS.language.textUpgrades)
  435.  
  436. self.buttonWithdraw = self:AddButton(self.guiTopWidth - 40 - 30, 60, 40, 40)
  437. self.buttonWithdraw.OnClick = function()
  438. net.Start("money_clicker_withdraw")
  439. net.WriteEntity(self)
  440. net.SendToServer()
  441. end
  442. self.buttonWithdraw.Paint = function(btn, w, h)
  443. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  444. surface.SetMaterial(matWithdraw)
  445. surface_DrawTexturedRect(btn.x - 5, btn.y - 5, w + 10, h + 10)
  446. draw.NoTexture()
  447. end
  448.  
  449. self.buttonHealth = self:AddButton(self.guiTopWidth - 80 - 30, self.guiTopHeight - 80 - 30, 80, 80)
  450. self.buttonHealth.OnClick = function()
  451. if self.info.indestructible then return end
  452.  
  453. net.Start("money_clicker_repair")
  454. net.WriteEntity(self)
  455. net.WriteString("health")
  456. net.SendToServer()
  457. end
  458. self.buttonHealth.iconFade = 0
  459. self.buttonHealth.manualPainting = true
  460. self.buttonHealth.Paint = function(btn, w, h)
  461. if btn.hovering and not self.info.indestructible then
  462. btn.iconFade = btn.iconFade + (1 - btn.iconFade) * 0.05
  463. else
  464. btn.iconFade = btn.iconFade + (0 - btn.iconFade) * 0.05
  465. end
  466.  
  467. local pulse = math.max(sin(CurTime() * 5), 0) * (self.smoothSide and 4 or 14)
  468. local progress = 1
  469. if not self.info.indestructible then
  470. progress = self.smoothHealth / self:GetMaxHealth()
  471. end
  472. local col = lerpColor(Color(0, 0, 0, 40), self.colHealth, math.Clamp(progress + sin(CurTime() * 5) / 10, 0, 1))
  473. surface_SetDrawColor(ColorAlpha(col, btn.alpha * (1 - btn.iconFade) * col.a))
  474. surface.SetMaterial(matHealth)
  475. surface_DrawTexturedRect(btn.x - pulse / 2, btn.y - pulse / 2, w + pulse, h + pulse)
  476. draw.NoTexture()
  477.  
  478. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * btn.iconFade * 255))
  479. surface.SetMaterial(matRepair)
  480. surface_DrawTexturedRect(btn.x + 7, btn.y + 7, w - 14, h - 14)
  481. draw.NoTexture()
  482.  
  483. local health = math.Round(self.smoothHealth)
  484. if self.info.indestructible then health = "∞" end
  485.  
  486. if self.smoothSide then
  487. draw.DrawText(health, "MoneyClickerHealthSide", btn.x - 8, btn.y + h / 2 - 15, ColorAlpha(self.colText, btn.alpha * 255), TEXT_ALIGN_RIGHT)
  488. else
  489. draw.DrawText(health, "MoneyClickerHealth", btn.x + w / 2, btn.y + h - 8, ColorAlpha(self.colText, btn.alpha * 255), TEXT_ALIGN_CENTER)
  490. end
  491. end
  492.  
  493. self.buttonRepair = self:AddButton(
  494. self.clickTopCenterX - self.clickTopRadius,
  495. self.clickTopCenterY - self.clickTopRadius,
  496. self.clickTopRadius * 2, self.clickTopRadius * 2)
  497. self.buttonRepair.OnClick = function()
  498. if self:GetBroken() and CurTime() >= self:GetRepairWaitTime() then
  499. net.Start("money_clicker_repair")
  500. net.WriteEntity(self)
  501. net.WriteString("broken")
  502. net.SendToServer()
  503. end
  504. end
  505. self.buttonRepair.manualPainting = true
  506. self.buttonRepair.alpha = 0
  507. self.buttonRepair.disabled = true
  508. self.buttonRepair.Paint = function(btn, w, h)
  509. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  510. surface.SetMaterial(matRepair)
  511. surface_DrawTexturedRect(btn.x - 5, btn.y - 5, w + 10, h + 10)
  512. draw.NoTexture()
  513. end
  514.  
  515.  
  516. local function SendUpgradeMessage(update)
  517. net.Start("money_clicker_upgrade")
  518. net.WriteEntity(self)
  519. net.WriteString(update)
  520. net.SendToServer()
  521. end
  522.  
  523. self.buttonUpg1 = self:AddButton(80, 160, 150, 150)
  524. self.buttonUpg1.alpha = 0
  525. self.buttonUpg1.Paint = function(btn, w, h)
  526. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  527. surface.SetMaterial(matUpgradeAutoClick)
  528. surface_DrawTexturedRect(btn.x, btn.y, w, h)
  529. draw.NoTexture()
  530. end
  531. self.buttonUpg1.OnClick = function()
  532. SendUpgradeMessage("autoClick")
  533. end
  534.  
  535. self.buttonUpg2 = self:AddButton(self.guiTopWidth - 80 - 150, 160, 150, 150)
  536. self.buttonUpg2.alpha = 0
  537. self.buttonUpg2.Paint = function(btn, w, h)
  538. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  539. surface.SetMaterial(matUpgradeClickPower)
  540. surface_DrawTexturedRect(btn.x, btn.y, w, h)
  541. draw.NoTexture()
  542. end
  543. self.buttonUpg2.OnClick = function()
  544. SendUpgradeMessage("clickPower")
  545. end
  546.  
  547. self.buttonUpg3 = self:AddButton(self.guiTopWidth / 2 - 75, self.guiHeight - 50 - 150, 150, 150)
  548. self.buttonUpg3.alpha = 0
  549. self.buttonUpg3.Paint = function(btn, w, h)
  550. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  551. surface.SetMaterial(matUpgradeCooling)
  552. surface_DrawTexturedRect(btn.x, btn.y, w, h)
  553. draw.NoTexture()
  554. end
  555. self.buttonUpg3.OnClick = function()
  556. SendUpgradeMessage("cooling")
  557. end
  558.  
  559. self.buttonUpg4 = self:AddButton(self.guiTopWidth / 2 - 75, self.guiHeight - 50 - 150, 150, 150)
  560. self.buttonUpg4.alpha = 0
  561. self.buttonUpg4.Paint = function(btn, w, h)
  562. surface_SetDrawColor(Color(255, 255, 255, btn.alpha * 255))
  563. surface.SetMaterial(matUpgradeStorage)
  564. surface_DrawTexturedRect(btn.x, btn.y, w, h)
  565. draw.NoTexture()
  566. end
  567. self.buttonUpg4.OnClick = function()
  568. SendUpgradeMessage("storage")
  569. end
  570.  
  571. self.upgradeButtons = {
  572. self.buttonUpg1,
  573. self.buttonUpg2,
  574. self.buttonUpg3,
  575. self.buttonUpg4,
  576. }
  577.  
  578. if not self.info.enableHeat then
  579. table.remove(self.upgradeButtons, 3)
  580. end
  581.  
  582. self.clicks = {}
  583.  
  584. self.smoothProgress = 0
  585. self.smoothHeat = 0
  586. self.smoothHeatColor = Color(0, 0, 0, 40)
  587. self.smoothMoney = 0
  588. self.smoothPoints = 0
  589. self.smoothXP = 0
  590. self.smoothHealth = self:Health()
  591. self.smoothBroken = 0
  592. self.smoothLookAway = 0
  593.  
  594. self.tooltipLookAway = buildTooltipData(Color(255, 150, 0), "Please look away once\nbefore clicking any further.")
  595. end
  596.  
  597. function ENT:BuildUpgradeTooltip(upgrade, current, statStr, prefix, suffix)
  598. local data = self:GetUpgradeData(upgrade)
  599. local stat = data.stats[current]
  600. local price = data.prices[current]
  601. local priceLabel = (price == nil) and MCLICKERS.language.textUpgradeMaxed or (MCLICKERS.formatPoints(price))
  602.  
  603. return {
  604. data.name, "\n",
  605. Color(0, 255, 0), prefix or "", stat, suffix or "",
  606. Color(255, 255, 255), " ", statStr, "\n",
  607. Color(100, 200, 255), priceLabel, "\n",
  608. Color(0, 255, 0), current .. " / " .. #data.stats
  609. }
  610. end
  611.  
  612. function ENT:UpdateTooltips()
  613. self.buttonUpg1:SetTooltip(unpack(self:BuildUpgradeTooltip("autoClick", self:GetUpgradeAutoClick(), MCLICKERS.language.unitAutoClick)))
  614. self.buttonUpg2:SetTooltip(unpack(self:BuildUpgradeTooltip("clickPower", self:GetUpgradeClickPower(), MCLICKERS.language.unitClickPower)))
  615. self.buttonUpg3:SetTooltip(unpack(self:BuildUpgradeTooltip("cooling", self:GetUpgradeCooling(), MCLICKERS.language.unitCooling, "-")))
  616. self.buttonUpg4:SetTooltip(unpack(self:BuildUpgradeTooltip("storage", self:GetUpgradeStorage(), MCLICKERS.language.unitStorage, nil, "x")))
  617.  
  618. self.buttonWithdraw:SetTooltip(MCLICKERS.language.textWithdraw, "\n", Color(0, 255, 0), "+" .. DarkRP.formatMoney(self:GetMoney()))
  619.  
  620. if not self.info.indestructible then
  621. local repairPrice = math.ceil(self.info.repairHealthCost * (1 - (self:Health() / self:GetMaxHealth())))
  622. self.buttonHealth:SetTooltip(MCLICKERS.language.textRepair, "\n", Color(255, 100, 0), MCLICKERS.formatPoints(repairPrice))
  623. end
  624.  
  625. if self:GetBroken() then
  626. local data = { MCLICKERS.language.textRepair .. "\n" }
  627. if CurTime() < self:GetRepairWaitTime() then
  628. data[#data + 1] = Color(100, 200, 255)
  629. data[#data + 1] = string.format(MCLICKERS.language.textRepairWait, math.ceil(self:GetRepairWaitTime() - CurTime())) .. "\n"
  630. end
  631.  
  632. data[#data + 1] = Color(255, 100, 0)
  633. data[#data + 1] = DarkRP.formatMoney(self.info.repairBrokenCost)
  634.  
  635. self.buttonRepair:SetTooltip(unpack(data))
  636. end
  637. end
  638.  
  639. function ENT:GetCursorPosition()
  640. local lp = LocalPlayer()
  641. local trace = util.TraceLine({
  642. start = lp:EyePos(),
  643. endpos = lp:EyePos() + LocalPlayer():GetAimVector() * MCLICKERS.clickRange,
  644. filter = lp
  645. })
  646. if trace.Entity ~= self then return 0, 0 end
  647.  
  648. local rayVec = util.IntersectRayWithPlane(lp:EyePos(), lp:GetAimVector(), self.guiWorldPos, self.guiWorldAng:Up())
  649. if not rayVec then return 0, 0 end
  650.  
  651. local dist = lp:EyePos():Distance(rayVec)
  652. if dist > MCLICKERS.clickRange then return 0, 0 end
  653.  
  654. local localRayVec = WorldToLocal(rayVec, Angle(), self.guiWorldPos, self.guiWorldAng)
  655.  
  656. local cursorFractX = localRayVec.x / self.boundsWidth
  657. local cursorFractY = -localRayVec.y / self.boundsHeight
  658.  
  659. if cursorFractX < 0 or cursorFractX > 1 or cursorFractY < 0 or cursorFractY > 1 then
  660. return -1, -1
  661. end
  662.  
  663. return cursorFractX * self.guiWidth, cursorFractY * self.guiHeight
  664. end
  665.  
  666. function ENT:AddButton(x, y, width, height)
  667. self.buttons = self.buttons or {}
  668.  
  669. local button = setmetatable({
  670. x = x,
  671. y = y,
  672. width = width,
  673. height = height,
  674. entity = self
  675. }, buttonMeta)
  676.  
  677. self.buttons[#self.buttons + 1] = button
  678.  
  679. return button
  680. end
  681.  
  682. local lastClick
  683. function ENT:SendClick()
  684. if self:GetLookAway() then return end
  685.  
  686. if lastClick then
  687. if CurTime() - lastClick < MCLICKERS.clickDelay then
  688. return false
  689. end
  690. end
  691. lastClick = CurTime()
  692.  
  693. net.Start("money_clicker_click")
  694. net.WriteEntity(self)
  695. net.SendToServer()
  696.  
  697. return true
  698. end
  699.  
  700. function ENT:Think()
  701. base_gmodentity.Think(self)
  702.  
  703. if not self.lastThink then self.lastThink = CurTime() end
  704. local elapsed = CurTime() - self.lastThink
  705. self.lastThink = CurTime()
  706.  
  707. local cursorX, cursorY = self:GetCursorPosition()
  708. self.cursorX = cursorX
  709. self.cursorY = cursorY
  710.  
  711. for _, button in ipairs(self.buttons) do
  712. if button.alpha < 0.01 then continue end
  713. button:Think()
  714. end
  715.  
  716. if self.menuOpened then
  717. if self.menuX > self.guiWidth - 0.01 then
  718. self.menuX = self.guiWidth
  719. else
  720. self.menuX = self.menuX + (self.guiWidth - self.menuX) * 5 * elapsed
  721. end
  722.  
  723. self.colorR = self.colorR + (self.colSecondary.r - self.colorR) * 1.5 * elapsed
  724. self.colorG = self.colorG + (self.colSecondary.g - self.colorG) * 1.5 * elapsed
  725. self.colorB = self.colorB + (self.colSecondary.b - self.colorB) * 1.5 * elapsed
  726. else
  727. if CurTime() > self.menuTime then
  728. if self.menuX < 0.01 then
  729. self.menuX = 0
  730. else
  731. self.menuX = self.menuX + (0 - self.menuX) * 5 * elapsed
  732. end
  733.  
  734. self.colorR = self.colorR + (self.colPrimary.r - self.colorR) * 1.5 * elapsed
  735. self.colorG = self.colorG + (self.colPrimary.g - self.colorG) * 1.5 * elapsed
  736. self.colorB = self.colorB + (self.colPrimary.b - self.colorB) * 1.5 * elapsed
  737. end
  738. end
  739.  
  740. if self.menuOpened then
  741. if self.menuX > self.guiWidth - 10 then
  742. self.menuContentAlpha = self.menuContentAlpha + (1.0 - self.menuContentAlpha) * 2 * elapsed
  743. end
  744. else
  745. self.menuContentAlpha = self.menuContentAlpha + (0.0 - self.menuContentAlpha) * 8 * elapsed
  746. end
  747.  
  748. for _, btn in ipairs(self.upgradeButtons) do
  749. btn.disabled = not self.menuOpened
  750. btn.alpha = self.menuContentAlpha
  751. end
  752.  
  753. local color = self:GetColor()
  754. if floor(abs(self.colorR - color.r)) ~= 0 or floor(abs(self.colorG - color.g)) ~= 0 or floor(abs(self.colorB - color.b)) ~= 0 then
  755. self:SetColor(Color(self.colorR, self.colorG, self.colorB))
  756. end
  757.  
  758. if not self.menuOpened then
  759. if LocalPlayer():KeyDown(IN_USE) and not self.oldClickDown and not self:IsOverheating() and not self:GetBroken() then
  760. local cx = self.clickTopCenterX
  761. local cy = self.clickTopCenterY
  762. local radius = self.clickTopRadius
  763.  
  764. if self.side then
  765. cx = self.clickSideCenterX
  766. cy = self.clickSideCenterY
  767. radius = self.clickSideRadius
  768. end
  769.  
  770. local dx = cx - cursorX
  771. local dy = cy - cursorY
  772. local dist = math.sqrt((dx * dx) + (dy * dy))
  773.  
  774. if dist <= radius then
  775. if not self:GetLookAway() then
  776. if self:SendClick() then
  777. self.clicks[#self.clicks + 1] = {
  778. x = cursorX,
  779. y = cursorY,
  780. time = CurTime(),
  781. duration = 0.3
  782. }
  783.  
  784. surface.PlaySound(MCLICKERS.SOUND_CLICK)
  785. end
  786. end
  787. end
  788. end
  789. end
  790.  
  791. self.oldClickDown = LocalPlayer():KeyDown(IN_USE)
  792.  
  793. if self.lastTooltipUpdate == nil or CurTime() - self.lastTooltipUpdate >= 0.5 then
  794. self:UpdateTooltips()
  795. self.lastTooltipUpdate = CurTime()
  796. end
  797. end
  798.  
  799. function ENT:DrawOverlayTooltip(x, y, font, tooltipData, alpha, alignment)
  800. if x == nil or y == nil or not tooltipData then return end
  801.  
  802. alpha = alpha or 1
  803. alignment = alignment or TEXT_ALIGN_LEFT
  804. if alpha < 0.01 then return end
  805.  
  806. surface.SetFont(font)
  807. local tw, th = surface.GetTextSize(tooltipData.text)
  808. surface_SetDrawColor(0, 0, 0, 200 * alpha)
  809.  
  810. local offX = alignment == TEXT_ALIGN_LEFT and 0 or (alignment == TEXT_ALIGN_RIGHT and tw or (tw / 2))
  811. local tx = math.Clamp(x - offX - 15, 0, self.guiWidth - tw - 30)
  812. local ty = math.Clamp(y - th / 2, 0, self.guiHeight - th - 5)
  813. surface_DrawRect(tx, ty, tw + 30, th + 5)
  814.  
  815. drawFormattedTextData(tooltipData.data, tx + tw / 2 + 15, ty, 255 * alpha, TEXT_ALIGN_CENTER)
  816. end
  817.  
  818. function ENT:DrawOverlay()
  819. local elapsed = FrameTime()
  820.  
  821. cam.Start3D2D(self.guiWorldPos, self.guiWorldAng, 0.05)
  822. local w, h = self.guiWidth, self.guiHeight
  823.  
  824. draw.NoTexture()
  825.  
  826. local headerBar = self.smoothSide and 30 or 40
  827. local clickCenterX = self.smoothSide and self.clickSideCenterX or self.clickTopCenterX
  828. local clickCenterY = self.smoothSide and self.clickSideCenterY or self.clickTopCenterY
  829. local clickRadius = self.smoothSide and self.clickSideRadius or self.clickTopRadius
  830.  
  831.  
  832. local progress = self:GetProgress() / 100
  833.  
  834. -- Ensure a smooth transition from 1 to 0
  835. if self.smoothProgress > progress then
  836. self.smoothProgress = (self.smoothProgress + (1 + progress - self.smoothProgress) * 5 * elapsed) % 1
  837. if self.smoothProgress >= 0.9999 then self.smoothProgress = 0 end
  838.  
  839. if not self.prevCycled then
  840. surface.PlaySound(MCLICKERS.SOUND_CYCLE)
  841.  
  842. self.prevCycled = true
  843. end
  844. else
  845. self.smoothProgress = self.smoothProgress + math.max(progress - self.smoothProgress, 0) * 5 * elapsed
  846.  
  847. self.prevCycled = false
  848. end
  849.  
  850. -- Smooth transition for heat
  851. self.smoothHeat = self.smoothHeat + (self:GetHeat() - self.smoothHeat) * 5 * elapsed
  852.  
  853. -- Smooth transition money and points
  854. self.smoothMoney = self.smoothMoney + (self:GetMoney() - self.smoothMoney) * 2.5 * elapsed
  855. self.smoothPoints = self.smoothPoints + (self:GetPoints() - self.smoothPoints) * 2.5 * elapsed
  856. self.smoothXP = self.smoothXP + (self:GetStoredXP() - self.smoothXP) * 2.5 * elapsed
  857. self.smoothHealth = self.smoothHealth + (self:Health() - self.smoothHealth) * 2.5 * elapsed
  858. self.smoothBroken = self.smoothBroken + ((self:GetBroken() and 1 or 0) - self.smoothBroken) * 2.5 * elapsed
  859.  
  860. if self:IsOverheating() then
  861. lerpColor(self.smoothHeatColor, ColorAlpha(self.colSecondary, 255), 2.5 * elapsed)
  862. else
  863. lerpColor(self.smoothHeatColor, Color(0, 0, 0, 40), 2.5 * elapsed)
  864. end
  865.  
  866. local money = math.Round(self.smoothMoney)
  867. local points = math.Round(self.smoothPoints)
  868. local xp = math.Round(self.smoothXP)
  869.  
  870.  
  871. if math.Round(self.menuX) < w then
  872. surface_SetDrawColor(self.colPrimary)
  873. surface_DrawRect(0, 0, w, h)
  874. end
  875.  
  876. if math.Round(self.menuX) < w then
  877.  
  878. local heatFract = self.smoothHeat / 100
  879. if heatFract > 0 then
  880. local heat = {}
  881. local heatCenterX = clickCenterX
  882. local heatCenterY = clickCenterY
  883. local heatRadius = clickRadius - 2
  884. local heatSeg = 12
  885. local angDiff = 90 - 180 * heatFract
  886.  
  887.  
  888. local a = rad(-90 + angDiff)
  889. table_insert(heat, {
  890. x = heatCenterX + sin(a) * heatRadius,
  891. y = heatCenterY + cos(a) * heatRadius,
  892. u = sin(a) / 2 + 0.5, v = cos(a) / 2 + 0.5 })
  893.  
  894. for i = -90 + angDiff, 90 - angDiff, heatSeg do
  895. local a = rad(-i)
  896. table_insert(heat, {
  897. x = heatCenterX + sin(a) * heatRadius,
  898. y = heatCenterY + cos(a) * heatRadius,
  899. u = sin(a) / 2 + 0.5, v = cos(a) / 2 + 0.5 })
  900. end
  901.  
  902. local a = rad(90 - angDiff)
  903. table_insert(heat, {
  904. x = heatCenterX + sin(a) * heatRadius,
  905. y = heatCenterY + cos(a) * heatRadius,
  906. u = sin(a) / 2 + 0.5, v = cos(a) / 2 + 0.5 })
  907.  
  908. surface_SetDrawColor(self.smoothHeatColor)
  909. surface.DrawPoly(heat)
  910.  
  911. surface_SetDrawColor(self.colPrimary)
  912. surface.SetMaterial(matHeat)
  913. surface_DrawTexturedRect(heatCenterX - heatRadius, heatCenterY - heatRadius, heatRadius * 2, heatRadius * 2)
  914. draw.NoTexture()
  915. end
  916.  
  917. self.buttonRepair.alpha = self.smoothBroken
  918. self.buttonRepair.disabled = self.smoothBroken < 0.01
  919. self.buttonRepair.width = clickRadius
  920. self.buttonRepair.height = clickRadius
  921. self.buttonRepair.x = clickCenterX - self.buttonRepair.width / 2
  922. self.buttonRepair.y = clickCenterY - self.buttonRepair.height / 2
  923.  
  924.  
  925. if self.smoothSide then
  926. local leftOffset = clickRadius * 2 + 70
  927. local rightOffset = 40
  928. local barWidth = self.smoothProgress * (self.guiWidth - rightOffset - leftOffset)
  929. surface_SetDrawColor(Color(0, 0, 0, 40))
  930. surface_DrawRect(leftOffset, clickCenterY - 3, self.guiWidth - rightOffset - leftOffset, 6)
  931.  
  932. surface_SetDrawColor(self.colSecondary)
  933. surface_DrawRect(leftOffset, clickCenterY - 3, barWidth, 6)
  934.  
  935. drawCircle(leftOffset + barWidth, clickCenterY, 12, 24, self.colSecondary)
  936.  
  937. drawArc(clickCenterX, clickCenterY, clickRadius + 5, 4, 0, 360, 6, Color(0, 0, 0, 40))
  938.  
  939. draw_DrawText(DarkRP.formatMoney(money), "MoneyClickerMoneySide", leftOffset + 16, clickCenterY - 46, self.colText, TEXT_ALIGN_LEFT)
  940. draw_DrawText(MCLICKERS.formatPoints(points), "MoneyClickerPointsSide", leftOffset + 16, clickCenterY + 16, self.colText, TEXT_ALIGN_LEFT)
  941.  
  942. if self.info.xpPerCycle and LevelSystemConfiguration then
  943. draw_DrawText(xp .. " XP", "MoneyClickerPointsSide", (leftOffset + 16 + self.guiWidth - rightOffset - 16) / 2, clickCenterY + 16, self.colText, TEXT_ALIGN_CENTER)
  944. end
  945.  
  946. draw_DrawText(self:GetOwnerName(), "MoneyClickerNameSide", self.guiWidth - rightOffset - 16, clickCenterY - 46, self.colText, TEXT_ALIGN_RIGHT)
  947. else
  948. local ang = self.smoothProgress * 360
  949. local radius = w / 2 - 100
  950. local thickness = 10
  951. local cx = w / 2
  952. local cy = h / 2 + 70
  953. drawArc(cx, cy, radius + thickness / 2, thickness, 0, 360, 6, Color(0, 0, 0, 40))
  954. drawArc(cx, cy, radius + thickness / 2, thickness, -90, -90 + math.ceil((ang + 2) * 10) / 10, 6, self.colSecondary)
  955.  
  956. local radAng = rad(-90 + ang)
  957. local dotX = cos(radAng) * radius
  958. local dotY = sin(radAng) * radius
  959. drawCircle(cx + dotX, cy + dotY, 16, 24, self.colSecondary)
  960.  
  961. local xpOffset = 0
  962.  
  963. if self.info.xpPerCycle and LevelSystemConfiguration then
  964. xpOffset = 20
  965. draw_DrawText(xp .. " XP", "MoneyClickerMoneySmall", w / 2, h / 2 + 180, self.colText, TEXT_ALIGN_CENTER)
  966. end
  967.  
  968. local textCol = ColorAlpha(self.colText, (1 - self.smoothBroken) * 255)
  969. draw_DrawText(MCLICKERS.language.textMoney, "MoneyClickerMoney", w / 2, h / 2 - 70 - xpOffset, textCol, TEXT_ALIGN_CENTER)
  970. draw_DrawText(DarkRP.formatMoney(money), "MoneyClickerMoneySmall", w / 2, h / 2 - xpOffset, textCol, TEXT_ALIGN_CENTER)
  971.  
  972. draw_DrawText(MCLICKERS.language.textPoints, "MoneyClickerPoints", w / 2, h / 2 + 80 - xpOffset * 2, textCol, TEXT_ALIGN_CENTER)
  973. draw_DrawText(MCLICKERS.formatPoints(points), "MoneyClickerPointsSmall", w / 2, h / 2 + 150 - xpOffset * 2, textCol, TEXT_ALIGN_CENTER)
  974.  
  975. draw_DrawText(self:GetOwnerName(), "MoneyClickerName", self.guiWidth / 2, headerBar + 60, self.colText, TEXT_ALIGN_CENTER)
  976. end
  977.  
  978. draw.NoTexture()
  979. for i = #self.clicks, 1, -1 do
  980. local click = self.clicks[i]
  981. local fract = math.Clamp((CurTime() - click.time) / click.duration, 0, 1)
  982.  
  983. drawCircle(
  984. click.x + (clickCenterX - click.x) * fract,
  985. click.y + (clickCenterY - click.y) * fract,
  986. fract * clickRadius, 12, Color(255, 255, 255, 50 * (1 - fract)))
  987.  
  988. if CurTime() - click.time >= click.duration then
  989. table.remove(self.clicks, i)
  990. end
  991. end
  992. end
  993.  
  994. self.buttonHealth:Paint(self.buttonHealth.width, self.buttonHealth.height)
  995. self.buttonHealth:PaintOver(self.buttonHealth.width, self.buttonHealth.height)
  996.  
  997. self.buttonRepair:Paint(self.buttonRepair.width, self.buttonRepair.height)
  998. self.buttonRepair:PaintOver(self.buttonRepair.width, self.buttonRepair.height)
  999.  
  1000. surface_SetDrawColor(self.colSecondary)
  1001. surface_DrawRect(0, 0, self.menuX, h)
  1002.  
  1003. surface_SetDrawColor(Color(0, 0, 0, 80))
  1004. surface_DrawRect(0, 0, w, headerBar)
  1005.  
  1006. if self.smoothSide then
  1007. draw_DrawText(MCLICKERS.language.textPoints .. ": " .. MCLICKERS.formatPoints(points), "MoneyClickerPointsSide", w / 2, headerBar + 70, ColorAlpha(self.colText, 255 * self.menuContentAlpha), TEXT_ALIGN_CENTER)
  1008. else
  1009. draw_DrawText(MCLICKERS.language.textPoints .. ": " .. MCLICKERS.formatPoints(points), "MoneyClickerPointsSide", w / 2, headerBar + 80, ColorAlpha(self.colText, 255 * self.menuContentAlpha), TEXT_ALIGN_CENTER)
  1010. end
  1011.  
  1012. draw_DrawText(self:GetClickerName(), "MoneyClickerTitle", 96, headerBar + 17, self.colText, TEXT_ALIGN_LEFT)
  1013. self.buttonMenu.y = headerBar + 23
  1014. self.buttonWithdraw.y = headerBar + 23
  1015.  
  1016. if self.smoothSide then
  1017. for i, btn in ipairs(self.upgradeButtons) do
  1018. btn.x = 80 + (self.guiWidth - 80) / #self.upgradeButtons * (i - 1)
  1019. btn.y = 150
  1020.  
  1021. btn.width = 50
  1022. btn.height = 50
  1023. end
  1024.  
  1025. self.buttonHealth.width = 36
  1026. self.buttonHealth.height = 36
  1027. self.buttonHealth.x = self.guiWidth - self.buttonHealth.width - 50
  1028. self.buttonHealth.y = self.guiHeight - self.buttonHealth.height - 22
  1029. else
  1030. local bx = 1
  1031. local by = 1
  1032. for i, btn in ipairs(self.upgradeButtons) do
  1033. local maxRow = math.min(#self.upgradeButtons - (by - 1) * 2, 2)
  1034. btn.x = self.guiWidth / (maxRow * 2) * (-(i % 2) * 2 + 3) - 75
  1035. btn.y = by * 250 - 60
  1036.  
  1037. if i % 2 == 0 then
  1038. by = by + 1
  1039. end
  1040.  
  1041. btn.width = 150
  1042. btn.height = 150
  1043. end
  1044.  
  1045. self.buttonHealth.width = 80
  1046. self.buttonHealth.height = 80
  1047. self.buttonHealth.x = self.guiWidth - self.buttonHealth.width - 30
  1048. self.buttonHealth.y = self.guiHeight - self.buttonHealth.height - 30
  1049. end
  1050.  
  1051. for _, button in ipairs(self.buttons) do
  1052. if button.alpha < 0.01 then continue end
  1053. if button.manualPainting then continue end
  1054.  
  1055. button:Paint(button.width, button.height)
  1056. end
  1057.  
  1058. for _, button in ipairs(self.buttons) do
  1059. if button.alpha < 0.01 then continue end
  1060. if button.manualPainting then continue end
  1061.  
  1062. button:PaintOver(button.width, button.height)
  1063. end
  1064.  
  1065. if self:GetLookAway() then
  1066. self.smoothLookAway = self.smoothLookAway + (1 - self.smoothLookAway) * 2.5 * elapsed
  1067. else
  1068. self.smoothLookAway = self.smoothLookAway + (0 - self.smoothLookAway) * 2.5 * elapsed
  1069. end
  1070. self:DrawOverlayTooltip(clickCenterX, clickCenterY, "MoneyClickerTooltip", self.tooltipLookAway, self.smoothLookAway, TEXT_ALIGN_CENTER)
  1071.  
  1072. cam.End3D2D()
  1073. end
  1074.  
  1075. function ENT:Draw(flags)
  1076. render.SuppressEngineLighting(true)
  1077. base_gmodentity.Draw(self, flags)
  1078. local lp = LocalPlayer()
  1079.  
  1080. local dist = LocalPlayer():GetPos():Distance(self:GetPos())
  1081. if dist > 150 then
  1082. render.SuppressEngineLighting(false)
  1083. surface.SetAlphaMultiplier(1)
  1084. return
  1085. end
  1086.  
  1087. local upDot = (lp:EyePos() - self:LocalToWorld(self.guiTopPos)):GetNormalized():Dot(self:GetUp())
  1088. local forwardDot = (lp:EyePos() - self:LocalToWorld(self.guiSidePos)):GetNormalized():Dot(self:GetForward())
  1089. local trigger = upDot < 0.2 and forwardDot > 0
  1090. if not trigger then
  1091. local upTrace = util.TraceLine({
  1092. start = self:GetPos(),
  1093. endpos = self:GetPos() + self:GetUp() * 15,
  1094. filter = self
  1095. })
  1096. trigger = upTrace.Hit
  1097. if trigger and IsValid(upTrace.Entity) and upTrace.Entity:IsPlayer() then
  1098. trigger = false
  1099. end
  1100. end
  1101.  
  1102. if not trigger then
  1103. local downTrace = util.TraceLine({
  1104. start = self:GetPos(),
  1105. endpos = self:GetPos() - self:GetUp() * 5,
  1106. filter = self
  1107. })
  1108. if IsValid(downTrace.Entity) and downTrace.Entity:GetClass() == "money_clicker" then
  1109. trigger = true
  1110. end
  1111. end
  1112.  
  1113. if self.side ~= trigger then
  1114. self.side = trigger
  1115. self.sideAnimTime = 0
  1116. end
  1117. self.sideAnimTime = math.min(self.sideAnimTime + 0.01, 1)
  1118.  
  1119. if self.sideAnimTime > 0.5 then
  1120. self.smoothSide = self.side
  1121.  
  1122. if self.side then
  1123. self.guiWidth = self.guiSideWidth
  1124. self.guiHeight = self.guiSideHeight
  1125.  
  1126. self.boundsWidth = self.boundsSideWidth
  1127. self.boundsHeight = self.boundsSideHeight
  1128.  
  1129. self.guiAng = self.guiSideAng
  1130. self.guiPos = self.guiSidePos
  1131. else
  1132. self.guiWidth = self.guiTopWidth
  1133. self.guiHeight = self.guiTopHeight
  1134.  
  1135. self.boundsWidth = self.boundsTopWidth
  1136. self.boundsHeight = self.boundsTopHeight
  1137.  
  1138. self.guiAng = self.guiTopAng
  1139. self.guiPos = self.guiTopPos
  1140. end
  1141. end
  1142.  
  1143. self.guiWorldPos = self:LocalToWorld(self.guiPos)
  1144. self.guiWorldAng = self:LocalToWorldAngles(self.guiAng)
  1145.  
  1146. surface.SetAlphaMultiplier((1 - math.Clamp((dist - 125) / 25, 0, 1)) * (1 - sin(math.pi * self.sideAnimTime)))
  1147.  
  1148. local dot = (lp:EyePos() - self.guiWorldPos):Dot(self.guiWorldAng:Up())
  1149. if dot > 0 then
  1150. self:DrawOverlay()
  1151. end
  1152.  
  1153. render.SuppressEngineLighting(false)
  1154.  
  1155. surface.SetAlphaMultiplier(1)
  1156. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement