Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. AddCSLuaFile("cl_init.lua")
  2. AddCSLuaFile("shared.lua")
  3. include("shared.lua")
  4.  
  5. util.AddNetworkString("blackpearls:HardWare:PrinterMenu")
  6.  
  7. function ENT:Initialize()
  8. self:SetModel(self.Model)
  9. self:PhysicsInit(SOLID_VPHYSICS)
  10. self:SetMoveType(MOVETYPE_VPHYSICS)
  11. self:SetSolid(SOLID_VPHYSICS)
  12. self:SetUseType(SIMPLE_USE)
  13.  
  14. local phys = self:GetPhysicsObject()
  15. if (IsValid(phys)) then
  16. phys:Wake()
  17. end
  18.  
  19. self:SetMoney(0)
  20. self:SetStorage(1000)
  21. self:SetTemp(25)
  22. self:SetPrinterBattery(100)
  23. self:SetCooling(100)
  24. self:SetMoneyRate(15)
  25. self:SetCoolingRate(1)
  26. self:SetTempRate(1)
  27. self:SetPrintTime(CurTime() + 2)
  28. self:SetPrinterHealth(100)
  29. end
  30.  
  31. function ENT:AcceptInput( _event, _a, _p )
  32. if (_event == "Use" && _p:IsPlayer()) then
  33. if not IsValid(_p) then return end
  34. net.Start("blackpearls:HardWare:PrinterMenu")
  35. net.WriteEntity(self)
  36. net.Send(_p)
  37. end
  38. end
  39.  
  40. function ENT:PrintMoney()
  41. if IsValid(self) then
  42. self:SetMoney(math.Clamp(self:GetMoney() + self:GetMoneyRate(), 0, self:GetStorage() ))
  43. end
  44. end
  45.  
  46. function ENT:PrintTemp()
  47. if IsValid(self) then
  48. local temp = self:GetTemp() + self:GetTempRate()
  49. self:SetTemp(math.Clamp(temp, 0, 50 ))
  50. if self:GetTemp() >= 50 then
  51. self:Explode()
  52. end
  53. end
  54. end
  55.  
  56. function ENT:PrintCooling()
  57. if IsValid(self) and self:GetCooling() >= 1 then
  58. local temp = self:GetCoolingRate() * 1.2
  59. self:SetTemp(math.Clamp(self:GetTemp() - temp, 0, 50 ))
  60. local cooling = self:GetCooling() - self:GetCoolingRate()
  61. self:SetCooling(math.Clamp(cooling, 0, 50 ))
  62. end
  63. end
  64.  
  65. function ENT:PrintBattery()
  66. if IsValid(self) then
  67. local battery = self:GetPrinterBattery() - 1
  68. self:SetPrinterBattery(math.Clamp(battery, 0, 100 ))
  69. end
  70. end
  71.  
  72. function ENT:Think()
  73. self:PrintMoney()
  74. self:PrintTemp()
  75. self:PrintBattery()
  76. self:PrintCooling()
  77.  
  78. if self:WaterLevel() > 1 then
  79. self:Explode()
  80. end
  81.  
  82. self:NextThink( CurTime() + 2 )
  83. return true
  84. end
  85.  
  86. function ENT:Explode()
  87. local vPoint = self:GetPos()
  88. local effectdata = EffectData()
  89. effectdata:SetOrigin( vPoint )
  90. util.Effect( "Explosion", effectdata )
  91. for k, v in pairs( player.GetAll() ) do
  92. if v:GetPos():Distance(self:GetPos()) < 110 then
  93. v:TakeDamage( 100, self, nil )
  94. end
  95. end
  96. self:Remove()
  97. end
  98.  
  99. util.AddNetworkString( "BP:HardWarePrinter:FunctionGlobal" )
  100.  
  101. net.Receive( "BP:HardWarePrinter:FunctionGlobal", function(len, caller)
  102. if not IsValid(caller) and not caller:IsPlayer() then return end
  103. local printer, func = net.ReadEntity(), net.ReadString()
  104. if not IsValid(printer) or printer:GetClass() != "hardware_printer" then return end
  105.  
  106. if func == "Money" then
  107. if printer:GetMoney() <= 0 or printer:CPPIGetOwner() != caller then return end
  108. caller:addMoney(printer:GetMoney())
  109. DarkRP.notify(caller, 0, 4, "Tu à recupéré "..string.Comma(printer:GetMoney()).." € dans ton imprimante.")
  110. printer:SetMoney(0)
  111. elseif func == "Name" then
  112. if printer:CPPIGetOwner() == NULL or printer:CPPIGetOwner() == nil then
  113. printer:CPPISetOwner(caller)
  114.  
  115. DarkRP.notify(caller, 0, 4, "Tu viens d'acheter une nouvelle imprimante.")
  116. else
  117. DarkRP.notify(caller, 1, 4, "Le printer est déjà acheté !")
  118. end
  119. elseif func == "CPU" then
  120. if printer:CPPIGetOwner() != caller then return end
  121.  
  122. local cpunumber = net.ReadInt(32)
  123. local cpu = hardWare_printer_CPU[cpunumber]
  124.  
  125. if printer:GetCPUName() == cpu.name then
  126. DarkRP.notify(caller, 1, 4, "Tu à déjà ce cpu : "..cpu.name..".")
  127. return
  128. elseif printer:GetCPUID() == cpunumber then
  129. DarkRP.notify(caller, 1, 4, "Tu ne peut pas retrograder ton imprimante.")
  130. return
  131. end
  132.  
  133. printer:SetCPUID(cpunumber)
  134. printer:SetMoneyRate(cpu.moneyrate)
  135. printer:SetCoolingRate(cpu.coolingrate)
  136. printer:SetTempRate(cpu.temprate)
  137. printer:SetBatteryRate(cpu.batteryrate)
  138.  
  139. caller:addMoney(-cpu.price)
  140.  
  141. DarkRP.notify(caller, 0, 4, "Tu viens d'acheter un cpu à "..string.Comma(cpu.price).."€, "..cpu.name..".")
  142. elseif func == "SSD" then
  143. if printer:CPPIGetOwner() != caller then return end
  144.  
  145. local ssdumber = net.ReadInt(32)
  146. local ssd = hardWare_printer_SSD[ssdumber]
  147.  
  148. if printer:GetSSDName() == ssd.name then
  149. DarkRP.notify(caller, 1, 4, "Tu à déjà ce ssd : "..ssd.name..".")
  150. return
  151. elseif printer:GetSSDID() < ssdumber then
  152. DarkRP.notify(caller, 1, 4, "Tu ne peut pas retrograder ton imprimante.")
  153. return
  154. end
  155.  
  156. printer:SetStorage(ssd.storage)
  157. printer:SetSSDID(ssdumber)
  158.  
  159. caller:addMoney(-ssd.price)
  160.  
  161. DarkRP.notify(caller, 0, 4, "Tu viens d'acheter un ssd à "..string.Comma(ssd.price).."€, "..ssd.name..".")
  162. end
  163. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement