Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This addon needs FPP plugin (falcos prop protection)
- local fontName = "BaseWars.MoneyPrinter"
- ENT.Base = "bw_base_electronics"
- ENT.Model = "models/props_lab/powerbox01a.mdl" --Model.
- ENT.Skin = 0
- ENT.Capacity = 1000000000000
- ENT.Money = 0
- ENT.MaxPaper = 0
- ENT.PrintInterval = 1
- ENT.PrintAmount = 3
- ENT.MaxLevel = 1
- ENT.UpgradeCost = 1000
- ENT.PrintColor = Color(0,174,0) --Color of the model
- ENT.PrintName = "Bank" --Title
- ENT.IsPrinter = true
- ENT.IsValidRaidable = false
- local Clamp = math.Clamp
- function ENT:GSAT(vartype, slot, name, min, max)
- self:NetworkVar(vartype, slot, name)
- local getVar = function(minMax)
- if self[minMax] and isfunction(self[minMax]) then return self[minMax](self) end
- if self[minMax] and isnumber(self[minMax]) then return self[minMax] end
- return minMax or 0
- end
- self["Get" .. name] = function(self)
- return tonumber(self.dt[name])
- end
- self["Set" .. name] = function(self, var)
- if isstring(self.dt[name]) then
- self.dt[name] = tostring(var)
- else
- self.dt[name] = var
- end
- end
- self["Add" .. name] = function(_, var)
- local Val = self["Get" .. name](self) + var
- if min and max then
- Val = Clamp(Val or 0, getVar(min), getVar(max))
- end
- if isstring(self["Get" .. name](self)) then
- self["Set" .. name](self, Val)
- else
- self["Set" .. name](self, Val)
- end
- end
- self["Take" .. name] = function(_, var)
- local Val = self["Get" .. name](self) - var
- if min and max then
- Val = Clamp(Val or 0, getVar(min), getVar(max))
- end
- if isstring(self["Get" .. name](self)) then
- self["Set" .. name](self, Val)
- else
- self["Set" .. name](self, Val)
- end
- end
- end
- function ENT:StableNetwork()
- self:GSAT("String", 2, "Capacity")
- self:SetCapacity("0")
- self:GSAT("String", 3, "Money", 0, "GetCapacity")
- self:SetMoney("0")
- self:GSAT("Int", 4, "Paper", 0, "MaxPaper")
- self:GSAT("Int", 5, "Level", 0, "MaxLevel")
- end
- if SERVER then
- AddCSLuaFile()
- function ENT:Init()
- self.time = CurTime()
- self.time_p = CurTime()
- self:SetCapacity(""..self.Capacity)
- self:SetPaper(self.MaxPaper)
- self:SetHealth(self.PresetMaxHealth or 100)
- self.rtb = 0
- self.FontColor = color_white
- self.BackColor = color_black
- self:SetColor(self.PrintColor)
- self:SetNWInt("UpgradeCost", self.UpgradeCost)
- self:SetLevel(1)
- end
- function ENT:SetUpgradeCost(val)
- self.UpgradeCost = val
- self:SetNWInt("UpgradeCost", val)
- end
- function ENT:Upgrade(ply)
- if ply then
- local lvl = self:GetLevel()
- local plyM = ply:GetMoney()
- local calcM = self:GetNWInt("UpgradeCost") * lvl
- if plyM < calcM then
- ply:Notify(BaseWars.LANG.UpgradeNoMoney, BASEWARS_NOTIFICATION_ERROR)
- return end
- if lvl >= self.MaxLevel then
- ply:Notify(BaseWars.LANG.UpgradeMaxLevel, BASEWARS_NOTIFICATION_ERROR)
- return end
- ply:TakeMoney(calcM)
- self.CurrentValue = (self.CurrentValue or 0) + calcM
- end
- self:AddLevel(1)
- end
- function ENT:ThinkFunc()
- if self.Disabled or self:BadlyDamaged() then return end
- local added
- local level = self:GetLevel() ^ 1.3
- for k, v in pairs( ents.FindByClass( "bw_printer_*" ) ) do
- if v:CPPIGetOwner() == self:CPPIGetOwner() then
- if self:GetMoney() < self.Capacity then
- local allmoney = v:GetMoney()
- v:TakeMoney(allmoney)
- self:AddMoney(allmoney)
- print(allmoney)
- else print("too Much Money")
- end
- end
- end
- for k, v in pairs( ents.FindByClass( "bw_base_moneyprinter" ) ) do
- if v:CPPIGetOwner() == self:CPPIGetOwner() then
- if self:GetMoney() < self.Capacity then
- local allmoney = v:GetMoney()
- v:TakeMoney(allmoney)
- self:AddMoney(allmoney)
- end
- end
- end
- if CurTime() >= self.PrintInterval * 2 + self.time_p and added then
- self.time_p = CurTime()
- end
- end
- function ENT:ReturnPly(ply)
- return ply, ply:UniqueID()
- end
- function ENT:PlayerTakeMoney(ply)
- 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
- local money = self:GetMoney()
- local Res, Msg = hook.Run("BaseWars_PlayerCanEmptyPrinter", ply, self, money)
- if Res == false then
- if Msg then
- ply:Notify(Msg, BASEWARS_NOTIFICATION_ERROR)
- end
- return end
- self:TakeMoney(money)
- ply:GiveMoney(money)
- hook.Run("BaseWars_PlayerEmptyPrinter", ply, self, money)
- end
- function ENT:UseFuncBypass(activator, caller, usetype, value)
- if self.Disabled then return end
- if activator:IsPlayer() and caller:IsPlayer() and self:GetMoney() > 0 then
- self:PlayerTakeMoney(activator)
- end
- end
- function ENT:SetDisabled(a)
- self.Disabled = a and true or false
- self:SetNWBool("printer_disabled", a and true or false)
- end
- else
- function ENT:Initialize()
- self.FontColor = Color(255,174,0)
- if not self.FontColor then self.FontColor = Color(255,174,0) end
- if not self.BackColor then self.BackColor = color_black end
- end
- local WasPowered
- if CLIENT then
- function ENT:DrawDisplay(pos, ang, scale)
- local w, h = 222 * 2, 136 * 2
- local disabled = self:GetNWBool("printer_disabled")
- local Pw = self:IsPowered()
- local Lv = self:GetLevel()
- local Cp = self:GetCapacity()
- draw.RoundedBox(0, -260, 1500, 530, 300, Pw and self.BackColor or color_black)
- if not Pw then return end
- if disabled then
- draw.DrawText(self.PrintName, fontName .. ".Huge", w / 2, h / 2 - 48, self.FontColor, TEXT_ALIGN_CENTER)
- draw.DrawText("NOT WORKING!", fontName .. ".Huge", w / 2, h / 2 - 32, Color(255,0,0), TEXT_ALIGN_CENTER)
- return end
- draw.DrawText(self.PrintName, fontName, w / 2-220, 1500, self.FontColor, TEXT_ALIGN_CENTER)
- if disabled then return end
- local money = tonumber(self:GetMoney()) or 0
- local cap = tonumber(Cp) or 0
- local moneyPercentage = math.Round( money / cap * 100 ,1)
- draw.DrawText( moneyPercentage .."%" , fontName .. ".Big", w - 4-400, 71+1500, self.FontColor, TEXT_ALIGN_RIGHT)
- local currentMoney = BaseWars.LANG.CURRENCY .. BaseWars.NumberFormat(money)
- local maxMoney = BaseWars.LANG.CURRENCY .. BaseWars.NumberFormat(cap)
- local font = fontName .. ".Big"
- if #currentMoney > 16 then
- font = fontName .. ".MedBig"
- end
- if #currentMoney > 20 then
- font = fontName .. ".Med"
- end
- local fh = draw.GetFontHeight(font)
- local StrW,StrH = surface.GetTextSize("")
- local moneyW,moneyH = surface.GetTextSize(currentMoney)
- draw.DrawText(currentMoney.." / $2 Billion" , font,
- w/2 - StrW/2 - moneyW-235 , (font == fontName .. ".Big" and 106 or 105 + fh / 4)+1500, self.FontColor, TEXT_ALIGN_LEFT)
- local NextCost = BaseWars.LANG.CURRENCY .. BaseWars.NumberFormat(self:GetLevel() * self:GetNWInt("UpgradeCost"))
- if self:GetLevel() >= self.MaxLevel then
- NextCost = "---"
- end
- local timeRemaining = 0
- timeRemaining = math.Round( (cap - money) / (self.PrintAmount * Lv / self.PrintInterval) )
- if timeRemaining > 0 then
- local PrettyHours = math.floor(timeRemaining/3600)
- local PrettyMinutes = math.floor(timeRemaining/60) - PrettyHours*60
- local PrettySeconds = timeRemaining - PrettyMinutes*60 - PrettyHours*3600
- local PrettyTime = (PrettyHours > 0 and PrettyHours.."h " or "") .. (PrettyMinutes > 0 and PrettyMinutes.."min " or "") .. PrettySeconds .." sec"
- end
- local BoxX = 94
- local BoxW = 255
- draw.RoundedBox(0, BoxX-225, 74+1600, BoxW , 24, self.FontColor)
- if cap > 0 and cap ~= math.huge then
- local moneyRatio = money / cap
- local maxWidth = math.floor(BoxW - 6)
- local curWidth = maxWidth * (1-moneyRatio)
- draw.RoundedBox(0, w - BoxX - curWidth + 6-235 , 76+1600, curWidth , 24 - 4, self.BackColor)
- end
- end
- function ENT:Calc3D2DParams()
- local pos = self:GetPos()
- local ang = self:GetAngles()
- pos = pos + ang:Up() * 90
- pos = pos + ang:Forward() * 14.5
- pos = pos + ang:Right() * 0
- ang:RotateAroundAxis(ang:Right(), -90)
- ang:RotateAroundAxis(ang:Up(), 90)
- return pos, ang, 0.1 / 2
- end
- end
- function ENT:Draw()
- self:DrawModel()
- if CLIENT then
- local pos, ang, scale = self:Calc3D2DParams()
- cam.Start3D2D(pos, ang, scale)
- pcall(self.DrawDisplay, self, pos, ang, scale)
- cam.End3D2D()
- end
- end
- if money > Cp then
- money = Cp
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement