Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.44 KB | None | 0 0
  1. local fontName = "BaseWars.MoneyPrinter"
  2.  
  3. ENT.Base = "bw_base_electronics"
  4.  
  5. ENT.Model = "models/props_lab/reciever01a.mdl"
  6. ENT.Skin = 0
  7.  
  8. ENT.Capacity = 10000
  9. ENT.Money = 0
  10. ENT.MaxPaper = 2500
  11. ENT.PrintInterval = 1
  12. ENT.PrintAmount = 8
  13. ENT.MaxLevel = 25
  14. ENT.UpgradeCost = 1000
  15.  
  16. ENT.PrintName = "Basic Printer"
  17.  
  18. ENT.IsPrinter = true
  19. ENT.IsValidRaidable = false
  20.  
  21. ENT.MoneyPickupSound = Sound("mvm/mvm_money_pickup.wav")
  22. ENT.UpgradeSound = Sound("replay/rendercomplete.wav")
  23.  
  24. local Clamp = math.Clamp
  25. function ENT:GSAT(slot, name, min, max)
  26.  
  27. self:NetworkVar("Int", slot, name)
  28.  
  29. local getVar = function(minMax)
  30.  
  31. if self[minMax] and isfunction(self[minMax]) then return self[minMax](self) end
  32. if self[minMax] and isnumber(self[minMax]) then return self[minMax] end
  33.  
  34. return minMax or 0
  35.  
  36. end
  37.  
  38. self["Add" .. name] = function(_, var)
  39.  
  40. local Val = self["Get" .. name](self) + var
  41.  
  42. if min and max then
  43.  
  44. Val = Clamp(tonumber(Val) or 0, getVar(min), getVar(max))
  45.  
  46. end
  47.  
  48. self["Set" .. name](self, Val)
  49.  
  50. end
  51.  
  52. self["Take" .. name] = function(_, var)
  53.  
  54. local Val = self["Get" .. name](self) - var
  55.  
  56. if min and max then
  57.  
  58. Val = Clamp(tonumber(Val) or 0, getVar(min), getVar(max))
  59.  
  60. end
  61.  
  62. self["Set" .. name](self, Val)
  63.  
  64. end
  65.  
  66. end
  67.  
  68. function ENT:StableNetwork()
  69.  
  70. self:GSAT(2, "Capacity")
  71.  
  72. self:GSAT(3, "Money", 0, "GetCapacity")
  73. self:GSAT(4, "Paper", 0, "MaxPaper")
  74. self:GSAT(5, "Level", 0, "MaxLevel")
  75.  
  76. end
  77.  
  78. if SERVER then
  79.  
  80. AddCSLuaFile()
  81.  
  82. function ENT:Init()
  83.  
  84. self.time = CurTime()
  85. self.time_p = CurTime()
  86.  
  87. self:SetCapacity(self.Capacity)
  88. self:SetPaper(self.MaxPaper)
  89.  
  90. self:SetHealth(self.PresetMaxHealth or 100)
  91.  
  92. self.rtb = 0
  93.  
  94. self.FontColor = color_white
  95. self.BackColor = color_black
  96.  
  97. self:SetNWInt("UpgradeCost", self.UpgradeCost)
  98.  
  99. self:SetLevel(1)
  100. end
  101.  
  102. function ENT:SetUpgradeCost(val)
  103.  
  104. self.UpgradeCost = val
  105. self:SetNWInt("UpgradeCost", val)
  106.  
  107. end
  108.  
  109. function ENT:Upgrade(ply, supress)
  110.  
  111. local lvl = self:GetLevel()
  112. local calcM = self:GetNWInt("UpgradeCost") * lvl
  113.  
  114. if ply then
  115.  
  116. local plyM = ply:GetMoney()
  117.  
  118. if plyM < calcM then
  119.  
  120. if not supress then ply:Notify(BaseWars.LANG.UpgradeNoMoney, BASEWARS_NOTIFICATION_ERROR) end
  121.  
  122. return false end
  123.  
  124. if lvl >= self.MaxLevel then
  125.  
  126. if not supress then ply:Notify(BaseWars.LANG.UpgradeMaxLevel, BASEWARS_NOTIFICATION_ERROR) end
  127.  
  128. return false end
  129.  
  130. ply:TakeMoney(calcM)
  131.  
  132. end
  133.  
  134. self.CurrentValue = (self.CurrentValue or 0) + calcM
  135.  
  136. self:AddLevel(1)
  137. self:EmitSound(self.UpgradeSound)
  138.  
  139. return true
  140.  
  141. end
  142.  
  143. function ENT:ThinkFunc()
  144.  
  145. if self.Disabled or self:BadlyDamaged() then return end
  146. local added
  147.  
  148. local level = self:GetLevel() ^ 1.3
  149.  
  150. if CurTime() >= self.PrintInterval + self.time and self:GetPaper() > 0 then
  151.  
  152. local m = self:GetMoney()
  153. self:AddMoney(math.Round(self.PrintAmount * level))
  154. self.time = CurTime()
  155.  
  156. local moneybag = ents.Create( "money" );
  157. moneybag:SetModel( "models/props/cs_assault/Money.mdl" );
  158. moneybag:SetPos( self:GetPos() + Vector(0, 0, 5) );
  159. moneybag:SetAngles(self:GetAngles())
  160. moneybag:Spawn();
  161. moneybag:SetColor(Color(200,255,200,255))
  162. moneybag:SetMoveType( MOVETYPE_VPHYSICS )
  163.  
  164. -- scripted_ents.Get("Money"):SpawnFunction(ply, ply:GetEyeTrace(), "Money"):SetValue(m)
  165. -- local money = ents.Create( "physics_prop" )
  166. -- money:setNWInt('Value',0)
  167. -- money:SetModel("models/props/cs_assault/money.mdl")
  168. -- money:SetPos( Vector( 0, 0, -20 ) )
  169. -- money:SetParent( self )
  170. -- money:SetValue(m)
  171. -- money:spawn()
  172. -- money:activate()
  173. self:TakeMoney(money)
  174.  
  175.  
  176.  
  177. end
  178.  
  179. if CurTime() >= self.PrintInterval * 2 + self.time_p and added then
  180.  
  181. self.time_p = CurTime()
  182. self:TakePaper(1)
  183.  
  184. end
  185.  
  186. end
  187.  
  188. function ENT:PlayerTakeMoney(ply)
  189.  
  190. local money = self:GetMoney()
  191.  
  192. local Res, Msg = hook.Run("BaseWars_PlayerCanEmptyPrinter", ply, self, money)
  193. if Res == false then
  194.  
  195. if Msg then
  196.  
  197. ply:Notify(Msg, BASEWARS_NOTIFICATION_ERROR)
  198.  
  199. end
  200.  
  201. return end
  202.  
  203. self:TakeMoney(money)
  204.  
  205. ply:GiveMoney(money)
  206. ply:EmitSound(self.MoneyPickupSound)
  207.  
  208. hook.Run("BaseWars_PlayerEmptyPrinter", ply, self, money)
  209.  
  210. end
  211.  
  212. function ENT:UseFuncBypass(activator, caller, usetype, value)
  213.  
  214. if self.Disabled then return end
  215.  
  216. if activator:IsPlayer() and caller:IsPlayer() and self:GetMoney() > 0 then
  217.  
  218. self:PlayerTakeMoney(activator)
  219.  
  220. end
  221.  
  222. end
  223.  
  224. function ENT:SetDisabled(a)
  225.  
  226. self.Disabled = a and true or false
  227. self:SetNWBool("printer_disabled", a and true or false)
  228.  
  229. end
  230.  
  231. else
  232.  
  233. function ENT:Initialize()
  234.  
  235. if not self.FontColor then self.FontColor = color_white end
  236. if not self.BackColor then self.BackColor = color_black end
  237.  
  238. end
  239.  
  240. surface.CreateFont(fontName, {
  241.  
  242. font = "Roboto",
  243. size = 20,
  244. weight = 800,
  245.  
  246. })
  247.  
  248. surface.CreateFont(fontName .. ".Huge", {
  249.  
  250. font = "Roboto",
  251. size = 64,
  252. weight = 800,
  253.  
  254. })
  255.  
  256.  
  257. surface.CreateFont(fontName .. ".Big", {
  258.  
  259. font = "Roboto",
  260. size = 32,
  261. weight = 800,
  262.  
  263. })
  264.  
  265. surface.CreateFont(fontName .. ".MedBig", {
  266.  
  267. font = "Roboto",
  268. size = 24,
  269. weight = 800,
  270.  
  271. })
  272.  
  273. surface.CreateFont(fontName .. ".Med", {
  274.  
  275. font = "Roboto",
  276. size = 18,
  277. weight = 800,
  278.  
  279. })
  280.  
  281.  
  282. local WasPowered
  283. if CLIENT then
  284. function ENT:DrawDisplay(pos, ang, scale)
  285.  
  286. local w, h = 216 * 2, 136 * 2
  287. local disabled = self:GetNWBool("printer_disabled")
  288. local Pw = self:IsPowered()
  289. local Lv = self:GetLevel()
  290. local Cp = self:GetCapacity()
  291.  
  292. draw.RoundedBox(4, 0, 0, w, h, Pw and self.BackColor or color_black)
  293.  
  294. if not Pw then return end
  295.  
  296. if disabled then
  297.  
  298. draw.DrawText(BaseWars.LANG.PrinterBeen, fontName, w / 2, h / 2 - 48, self.FontColor, TEXT_ALIGN_CENTER)
  299. draw.DrawText(BaseWars.LANG.Disabled, fontName .. ".Huge", w / 2, h / 2 - 32, Color(255,0,0), TEXT_ALIGN_CENTER)
  300.  
  301. return end
  302. draw.DrawText(self.PrintName, fontName, w / 2, 4, self.FontColor, TEXT_ALIGN_CENTER)
  303.  
  304. if disabled then return end
  305.  
  306. --Level
  307. surface.SetDrawColor(self.FontColor)
  308. surface.DrawLine(0, 30, w, 30)--draw.RoundedBox(0, 0, 30, w, 1, self.FontColor)
  309. draw.DrawText(string.format(BaseWars.LANG.LevelText, Lv):upper(), fontName .. ".Big", 4, 32, self.FontColor, TEXT_ALIGN_LEFT)
  310. surface.DrawLine(0, 68, w, 68)--draw.RoundedBox(0, 0, 68, w, 1, self.FontColor)
  311.  
  312. draw.DrawText(BaseWars.LANG.Cash, fontName .. ".Big", 4, 72, self.FontColor, TEXT_ALIGN_LEFT)
  313. -- draw.RoundedBox(0, 0, 72 + 32, w, 1, self.FontColor)
  314.  
  315. local money = tonumber(self:GetMoney()) or 0
  316. local cap = tonumber(Cp) or 0
  317.  
  318. local moneyPercentage = math.Round( money / cap * 100 ,1)
  319. --Percentage done
  320. draw.DrawText( moneyPercentage .."%" , fontName .. ".Big", w - 4, 71, self.FontColor, TEXT_ALIGN_RIGHT)
  321.  
  322. --Money/Maxmoney
  323. local currentMoney = string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(money))
  324. local maxMoney = string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(cap))
  325. local font = fontName .. ".Big"
  326. if #currentMoney > 16 then
  327.  
  328. font = fontName .. ".MedBig"
  329.  
  330. end
  331. if #currentMoney > 20 then
  332.  
  333. font = fontName .. ".Med"
  334.  
  335. end
  336. local fh = draw.GetFontHeight(font)
  337.  
  338. local StrW,StrH = surface.GetTextSize(" / ")
  339. draw.DrawText(" / " , font,
  340. w/2 - StrW/2 , (font == fontName .. ".Big" and 106 or 105 + fh / 4), self.FontColor, TEXT_ALIGN_LEFT)
  341.  
  342. local moneyW,moneyH = surface.GetTextSize(currentMoney)
  343. draw.DrawText(currentMoney , font,
  344. w/2 - StrW/2 - moneyW , (font == fontName .. ".Big" and 106 or 105 + fh / 4), self.FontColor, TEXT_ALIGN_LEFT)
  345.  
  346. draw.DrawText( maxMoney, font,
  347. w/2 + StrW/2 , (font == fontName .. ".Big" and 106 or 105 + fh / 4), self.FontColor, TEXT_ALIGN_Right)
  348.  
  349. --Paper
  350. local paper = math.floor(self:GetPaper())
  351. draw.DrawText(string.format(BaseWars.LANG.Paper, paper), fontName .. ".MedBig", 4, 94 + 49, self.FontColor, TEXT_ALIGN_LEFT)
  352. --draw.RoundedBox(0, 0, 102 + 37, w, 1, self.FontColor)
  353. surface.DrawLine(0, 102 + 37, w, 102 + 37)
  354.  
  355. local NextCost = string.format(BaseWars.LANG.CURFORMER, BaseWars.NumberFormat(self:GetLevel() * self:GetNWInt("UpgradeCost")))
  356.  
  357. if self:GetLevel() >= self.MaxLevel then
  358.  
  359. NextCost = BaseWars.LANG.MaxLevel
  360.  
  361. end
  362.  
  363. surface.DrawLine(0, 142 + 25, w, 142 + 25)--draw.RoundedBox(0, 0, 142 + 25, w, 1, self.FontColor)
  364. draw.DrawText(string.format(BaseWars.LANG.NextUpgrade, NextCost), fontName .. ".MedBig", 4, 84 + 78 + 10, self.FontColor, TEXT_ALIGN_LEFT)
  365. surface.DrawLine(0, 142 + 25, w, 142 + 25)--draw.RoundedBox(0, 0, 142 + 55, w, 1, self.FontColor)
  366.  
  367. --Time remaining counter
  368. local timeRemaining = 0
  369. timeRemaining = math.Round( (cap - money) / (self.PrintAmount * Lv / self.PrintInterval) )
  370.  
  371. if timeRemaining > 0 then
  372.  
  373. local PrettyHours = math.floor(timeRemaining/3600)
  374. local PrettyMinutes = math.floor(timeRemaining/60) - PrettyHours*60
  375. local PrettySeconds = timeRemaining - PrettyMinutes*60 - PrettyHours*3600
  376. local PrettyTime = (PrettyHours > 0 and PrettyHours..BaseWars.LANG.HoursShort or "") ..
  377. (PrettyMinutes > 0 and PrettyMinutes..BaseWars.LANG.MinutesShort or "") ..
  378. PrettySeconds..BaseWars.LANG.SecondsShort
  379.  
  380. draw.DrawText(string.format(BaseWars.LANG.UntilFull, PrettyTime), fontName .. ".Big", w-4 , 32, self.FontColor, TEXT_ALIGN_RIGHT)
  381. else
  382. draw.DrawText(BaseWars.LANG.Full, fontName .. ".Big", w-4 , 32, self.FontColor, TEXT_ALIGN_RIGHT)
  383. end
  384.  
  385.  
  386. --Money bar BG
  387. local BoxX = 88
  388. local BoxW = 265
  389. draw.RoundedBox(0, BoxX, 74, BoxW , 24, self.FontColor)
  390.  
  391. --Money bar gap
  392. if cap > 0 and cap ~= math.huge then
  393. local moneyRatio = money / cap
  394. local maxWidth = math.floor(BoxW - 6)
  395. local curWidth = maxWidth * (1-moneyRatio)
  396.  
  397. draw.RoundedBox(0, w - BoxX - curWidth + 6 , 76, curWidth , 24 - 4, self.BackColor)
  398.  
  399. end
  400.  
  401. end
  402.  
  403. function ENT:Calc3D2DParams()
  404.  
  405. local pos = self:GetPos()
  406. local ang = self:GetAngles()
  407.  
  408. pos = pos + ang:Up() * 3.09
  409. pos = pos + ang:Forward() * -7.35
  410. pos = pos + ang:Right() * 10.82
  411.  
  412. ang:RotateAroundAxis(ang:Up(), 90)
  413.  
  414. return pos, ang, 0.1 / 2
  415.  
  416. end
  417.  
  418. end
  419.  
  420. function ENT:Draw()
  421.  
  422. self:DrawModel()
  423.  
  424. if CLIENT then
  425.  
  426. local pos, ang, scale = self:Calc3D2DParams()
  427.  
  428. cam.Start3D2D(pos, ang, scale)
  429. pcall(self.DrawDisplay, self, pos, ang, scale)
  430. cam.End3D2D()
  431.  
  432. end
  433.  
  434. end
  435. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement