Advertisement
HexGaming

Untitled

Jan 20th, 2018
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. -- This addon needs FPP plugin (falcos prop protection)
  2.  
  3. local fontName = "BaseWars.MoneyPrinter"
  4. ENT.Base = "bw_base_electronics"
  5.  
  6. ENT.Model = "models/props_lab/powerbox01a.mdl" --Model.
  7. ENT.Skin = 0
  8.  
  9. ENT.Capacity = 1000000000000
  10. ENT.Money = 0
  11. ENT.MaxPaper = 0
  12. ENT.PrintInterval = 1
  13. ENT.PrintAmount = 3
  14. ENT.MaxLevel = 1
  15. ENT.UpgradeCost = 1000
  16. ENT.PrintColor = Color(0,174,0) --Color of the model
  17. ENT.PrintName = "Bank" --Title
  18. ENT.IsPrinter = true
  19. ENT.IsValidRaidable = false
  20.  
  21. local Clamp = math.Clamp
  22. function ENT:GSAT(vartype, slot, name, min, max)
  23. self:NetworkVar(vartype, slot, name)
  24.  
  25. local getVar = function(minMax)
  26. if self[minMax] and isfunction(self[minMax]) then return self[minMax](self) end
  27. if self[minMax] and isnumber(self[minMax]) then return self[minMax] end
  28. return minMax or 0
  29. end
  30.  
  31. self["Get" .. name] = function(self)
  32. return tonumber(self.dt[name])
  33. end
  34.  
  35. self["Set" .. name] = function(self, var)
  36. if isstring(self.dt[name]) then
  37. self.dt[name] = tostring(var)
  38. else
  39. self.dt[name] = var
  40. end
  41. end
  42.  
  43. self["Add" .. name] = function(_, var)
  44. local Val = self["Get" .. name](self) + var
  45.  
  46. if min and max then
  47. Val = Clamp(Val or 0, getVar(min), getVar(max))
  48. end
  49.  
  50. if isstring(self["Get" .. name](self)) then
  51. self["Set" .. name](self, Val)
  52. else
  53. self["Set" .. name](self, Val)
  54. end
  55. end
  56.  
  57. self["Take" .. name] = function(_, var)
  58. local Val = self["Get" .. name](self) - var
  59.  
  60. if min and max then
  61. Val = Clamp(Val or 0, getVar(min), getVar(max))
  62. end
  63.  
  64. if isstring(self["Get" .. name](self)) then
  65. self["Set" .. name](self, Val)
  66. else
  67. self["Set" .. name](self, Val)
  68. end
  69. end
  70. end
  71.  
  72. function ENT:StableNetwork()
  73. self:GSAT("String", 2, "Capacity")
  74. self:SetCapacity("0")
  75. self:GSAT("String", 3, "Money", 0, "GetCapacity")
  76. self:SetMoney("0")
  77. self:GSAT("Int", 4, "Paper", 0, "MaxPaper")
  78. self:GSAT("Int", 5, "Level", 0, "MaxLevel")
  79. end
  80.  
  81. if SERVER then
  82.  
  83. AddCSLuaFile()
  84.  
  85. function ENT:Init()
  86.  
  87. self.time = CurTime()
  88. self.time_p = CurTime()
  89.  
  90. self:SetCapacity(""..self.Capacity)
  91. self:SetPaper(self.MaxPaper)
  92.  
  93. self:SetHealth(self.PresetMaxHealth or 100)
  94.  
  95. self.rtb = 0
  96.  
  97. self.FontColor = color_white
  98. self.BackColor = color_black
  99. self:SetColor(self.PrintColor)
  100. self:SetNWInt("UpgradeCost", self.UpgradeCost)
  101.  
  102. self:SetLevel(1)
  103. end
  104.  
  105. function ENT:SetUpgradeCost(val)
  106.  
  107. self.UpgradeCost = val
  108. self:SetNWInt("UpgradeCost", val)
  109.  
  110. end
  111.  
  112. function ENT:Upgrade(ply)
  113.  
  114. if ply then
  115.  
  116. local lvl = self:GetLevel()
  117.  
  118. local plyM = ply:GetMoney()
  119.  
  120. local calcM = self:GetNWInt("UpgradeCost") * lvl
  121.  
  122. if plyM < calcM then
  123.  
  124. ply:Notify(BaseWars.LANG.UpgradeNoMoney, BASEWARS_NOTIFICATION_ERROR)
  125.  
  126. return end
  127.  
  128. if lvl >= self.MaxLevel then
  129.  
  130. ply:Notify(BaseWars.LANG.UpgradeMaxLevel, BASEWARS_NOTIFICATION_ERROR)
  131.  
  132. return end
  133.  
  134. ply:TakeMoney(calcM)
  135. self.CurrentValue = (self.CurrentValue or 0) + calcM
  136.  
  137. end
  138.  
  139. self:AddLevel(1)
  140.  
  141.  
  142. end
  143.  
  144. function ENT:ThinkFunc()
  145.  
  146.  
  147.  
  148. if self.Disabled or self:BadlyDamaged() then return end
  149. local added
  150.  
  151. local level = self:GetLevel() ^ 1.3
  152.  
  153.  
  154. for k, v in pairs( ents.FindByClass( "bw_printer_*" ) ) do
  155. if v:CPPIGetOwner() == self:CPPIGetOwner() then
  156. if self:GetMoney() < self.Capacity then
  157. local allmoney = v:GetMoney()
  158. v:TakeMoney(allmoney)
  159. self:AddMoney(allmoney)
  160. print(allmoney)
  161. else print("too Much Money")
  162. end
  163. end
  164. end
  165.  
  166. for k, v in pairs( ents.FindByClass( "bw_base_moneyprinter" ) ) do
  167. if v:CPPIGetOwner() == self:CPPIGetOwner() then
  168. if self:GetMoney() < self.Capacity then
  169. local allmoney = v:GetMoney()
  170. v:TakeMoney(allmoney)
  171. self:AddMoney(allmoney)
  172. end
  173. end
  174. end
  175.  
  176.  
  177.  
  178. if CurTime() >= self.PrintInterval * 2 + self.time_p and added then
  179.  
  180. self.time_p = CurTime()
  181.  
  182. end
  183.  
  184. end
  185. function ENT:ReturnPly(ply)
  186. return ply, ply:UniqueID()
  187. end
  188. function ENT:PlayerTakeMoney(ply)
  189.  
  190.  
  191. if self:CPPIGetOwner() != self:ReturnPly(ply) and Basewars.Bank.IsPublic == false then ply:Notify("Money can take only the owner!", BASEWARS_NOTIFICATION_ERROR) return end
  192.  
  193. local money = self:GetMoney()
  194.  
  195. local Res, Msg = hook.Run("BaseWars_PlayerCanEmptyPrinter", ply, self, money)
  196. if Res == false then
  197.  
  198. if Msg then
  199.  
  200. ply:Notify(Msg, BASEWARS_NOTIFICATION_ERROR)
  201.  
  202. end
  203.  
  204. return end
  205.  
  206.  
  207. self:TakeMoney(money)
  208.  
  209. ply:GiveMoney(money)
  210.  
  211.  
  212. hook.Run("BaseWars_PlayerEmptyPrinter", ply, self, money)
  213.  
  214. end
  215.  
  216. function ENT:UseFuncBypass(activator, caller, usetype, value)
  217.  
  218. if self.Disabled then return end
  219.  
  220. if activator:IsPlayer() and caller:IsPlayer() and self:GetMoney() > 0 then
  221.  
  222. self:PlayerTakeMoney(activator)
  223.  
  224. end
  225.  
  226. end
  227.  
  228. function ENT:SetDisabled(a)
  229.  
  230. self.Disabled = a and true or false
  231. self:SetNWBool("printer_disabled", a and true or false)
  232.  
  233. end
  234.  
  235. else
  236.  
  237. function ENT:Initialize()
  238.  
  239. self.FontColor = Color(255,174,0)
  240. if not self.FontColor then self.FontColor = Color(255,174,0) end
  241. if not self.BackColor then self.BackColor = color_black end
  242.  
  243. end
  244.  
  245.  
  246. local WasPowered
  247. if CLIENT then
  248. function ENT:DrawDisplay(pos, ang, scale)
  249.  
  250. local w, h = 222 * 2, 136 * 2
  251. local disabled = self:GetNWBool("printer_disabled")
  252. local Pw = self:IsPowered()
  253. local Lv = self:GetLevel()
  254. local Cp = self:GetCapacity()
  255.  
  256. draw.RoundedBox(0, -260, 1500, 530, 300, Pw and self.BackColor or color_black)
  257.  
  258. if not Pw then return end
  259.  
  260. if disabled then
  261.  
  262. draw.DrawText(self.PrintName, fontName .. ".Huge", w / 2, h / 2 - 48, self.FontColor, TEXT_ALIGN_CENTER)
  263. draw.DrawText("NOT WORKING!", fontName .. ".Huge", w / 2, h / 2 - 32, Color(255,0,0), TEXT_ALIGN_CENTER)
  264.  
  265. return end
  266. draw.DrawText(self.PrintName, fontName, w / 2-220, 1500, self.FontColor, TEXT_ALIGN_CENTER)
  267.  
  268. if disabled then return end
  269.  
  270. local money = tonumber(self:GetMoney()) or 0
  271. local cap = tonumber(Cp) or 0
  272.  
  273. local moneyPercentage = math.Round( money / cap * 100 ,1)
  274.  
  275. draw.DrawText( moneyPercentage .."%" , fontName .. ".Big", w - 4-400, 71+1500, self.FontColor, TEXT_ALIGN_RIGHT)
  276.  
  277.  
  278. local currentMoney = BaseWars.LANG.CURRENCY .. BaseWars.NumberFormat(money)
  279. local maxMoney = BaseWars.LANG.CURRENCY .. BaseWars.NumberFormat(cap)
  280. local font = fontName .. ".Big"
  281. if #currentMoney > 16 then
  282.  
  283. font = fontName .. ".MedBig"
  284.  
  285. end
  286. if #currentMoney > 20 then
  287.  
  288. font = fontName .. ".Med"
  289.  
  290. end
  291. local fh = draw.GetFontHeight(font)
  292.  
  293. local StrW,StrH = surface.GetTextSize("")
  294. local moneyW,moneyH = surface.GetTextSize(currentMoney)
  295. draw.DrawText(currentMoney.." / $2 Billion" , font,
  296. w/2 - StrW/2 - moneyW-235 , (font == fontName .. ".Big" and 106 or 105 + fh / 4)+1500, self.FontColor, TEXT_ALIGN_LEFT)
  297.  
  298.  
  299.  
  300. local NextCost = BaseWars.LANG.CURRENCY .. BaseWars.NumberFormat(self:GetLevel() * self:GetNWInt("UpgradeCost"))
  301.  
  302. if self:GetLevel() >= self.MaxLevel then
  303.  
  304. NextCost = "---"
  305.  
  306. end
  307.  
  308. local timeRemaining = 0
  309. timeRemaining = math.Round( (cap - money) / (self.PrintAmount * Lv / self.PrintInterval) )
  310.  
  311. if timeRemaining > 0 then
  312.  
  313. local PrettyHours = math.floor(timeRemaining/3600)
  314. local PrettyMinutes = math.floor(timeRemaining/60) - PrettyHours*60
  315. local PrettySeconds = timeRemaining - PrettyMinutes*60 - PrettyHours*3600
  316. local PrettyTime = (PrettyHours > 0 and PrettyHours.."h " or "") .. (PrettyMinutes > 0 and PrettyMinutes.."min " or "") .. PrettySeconds .." sec"
  317.  
  318. end
  319.  
  320.  
  321.  
  322. local BoxX = 94
  323. local BoxW = 255
  324. draw.RoundedBox(0, BoxX-225, 74+1600, BoxW , 24, self.FontColor)
  325.  
  326.  
  327. if cap > 0 and cap ~= math.huge then
  328. local moneyRatio = money / cap
  329. local maxWidth = math.floor(BoxW - 6)
  330. local curWidth = maxWidth * (1-moneyRatio)
  331.  
  332. draw.RoundedBox(0, w - BoxX - curWidth + 6-235 , 76+1600, curWidth , 24 - 4, self.BackColor)
  333.  
  334. end
  335.  
  336. end
  337.  
  338. function ENT:Calc3D2DParams()
  339.  
  340. local pos = self:GetPos()
  341. local ang = self:GetAngles()
  342.  
  343. pos = pos + ang:Up() * 90
  344. pos = pos + ang:Forward() * 14.5
  345. pos = pos + ang:Right() * 0
  346.  
  347. ang:RotateAroundAxis(ang:Right(), -90)
  348. ang:RotateAroundAxis(ang:Up(), 90)
  349.  
  350. return pos, ang, 0.1 / 2
  351.  
  352. end
  353.  
  354. end
  355.  
  356. function ENT:Draw()
  357.  
  358. self:DrawModel()
  359.  
  360. if CLIENT then
  361.  
  362. local pos, ang, scale = self:Calc3D2DParams()
  363.  
  364. cam.Start3D2D(pos, ang, scale)
  365. pcall(self.DrawDisplay, self, pos, ang, scale)
  366. cam.End3D2D()
  367.  
  368. end
  369.  
  370. end
  371.  
  372. if money > Cp then
  373. money = Cp
  374. end
  375.  
  376.  
  377. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement