Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. ENT.Type = "anim"
  4. ENT.Base = "base_anim"
  5. ENT.PrintName = "Builder_Barricade"
  6. ENT.Category = "Builder-Hammer"
  7. ENT.Builder_PickUp = false
  8. ENT.IsBuilder = true
  9.  
  10. local EntName = "builder_barricade"
  11. local net_receive = "builder_"..ENT.PrintName
  12.  
  13. ENT.Spawnable = true
  14. ENT.AdminOnly = false
  15.  
  16. if SERVER then
  17.  
  18. util.AddNetworkString( "Builder_Can_Damage" )
  19.  
  20. function ENT:Initialize()
  21.  
  22. self.Entity:SetModel( "models/props_lab/blastdoor001c.mdl" )
  23.  
  24. self:PhysicsInit( SOLID_VPHYSICS )
  25. self:SetMoveType( MOVETYPE_VPHYSICS )
  26. self:SetSolid( SOLID_VPHYSICS )
  27.  
  28. local phys = self:GetPhysicsObject()
  29.  
  30. if phys:IsValid() then
  31.  
  32. phys:Wake()
  33.  
  34. end
  35.  
  36. self:SetMaterial( "models/wireframe" )
  37. self:SetColor(Color(0, 0, 0, 255))
  38.  
  39. self.Ent_Health = 300
  40.  
  41. self:DrawShadow()
  42.  
  43. self.CanBuilderDo = 0
  44. self.MaxGoal = 100
  45.  
  46. end
  47.  
  48. function ENT:SpawnFunction( ply, tr )
  49.  
  50. local ent = ents.Create(EntName)
  51. ent:SetPos( ply:GetEyeTrace().HitPos + ply:GetEyeTrace().HitNormal * 32 )
  52. ent:Spawn()
  53. ent:Activate()
  54.  
  55. return ent
  56.  
  57. end
  58.  
  59. function ENT:Think()
  60. return false
  61. end
  62.  
  63. function ENT:OnTakeDamage( dmg )
  64. if Builder.GetScore(self) >= Builder.GetGoal(self) then
  65. self:SetColor(Color(255, 255, 255, 255))
  66. local ply = dmg:GetAttacker()
  67. local inflictor = dmg:GetInflictor()
  68. if type(inflictor) == "Entity" then return end
  69. if self.Ent_Health <= 0 then
  70. local effectdata = EffectData()
  71. effectdata:SetStart( self:GetPos() )
  72. effectdata:SetOrigin( self:GetPos() )
  73. effectdata:SetScale( 1 )
  74. util.Effect( "Explosion", effectdata )
  75. self:Dmger(ply)
  76. self:Remove()
  77. return
  78. end
  79. self.Ent_Health = self.Ent_Health - dmg:GetDamage()
  80. net.Start("Builder_Can_Damage")
  81. net.WriteString("Builder_Can_Damage")
  82. net.WriteString(tostring(self.Ent_Health))
  83. net.Send(ply)
  84. end
  85. end
  86.  
  87. function ENT:Use( btn, ply )
  88. if Builder.GetScore(self) >= Builder.GetGoal(self) then
  89. self:SetMaterial( "" )
  90. self.Builder_PickUp = true
  91. end
  92. end
  93.  
  94. function ENT:StartTouch( entity )
  95. return false
  96. end
  97.  
  98. function ENT:EndTouch( entity )
  99. return false
  100. end
  101.  
  102. function ENT:Touch( entity )
  103. return false
  104. end
  105.  
  106. end
  107.  
  108. if CLIENT then
  109.  
  110. ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
  111.  
  112. surface.CreateFont( "BuilderText",
  113. {
  114. font = "Arial",
  115. size = 21,
  116. weight = 400
  117. })
  118.  
  119.  
  120. function ENT:Initialize()
  121.  
  122. self.Complete = self.Complete or 0
  123. self.Goal = self.Goal or 100
  124.  
  125. net.Receive(net_receive.."_"..self:EntIndex(), function()
  126. self.Complete = net.ReadString()
  127. self.Goal = net.ReadString()
  128. end)
  129.  
  130. net.Receive("Builder_Can_Damage", function()
  131. local n_candmg = net.ReadString()
  132. local n_hp = net.ReadString()
  133. --print(n_hp)
  134. self.BarricadeHP = n_hp
  135. if n_candmg == "Builder_Can_Damage" then
  136. self.CanDmg = true
  137. end
  138. end)
  139.  
  140. end
  141.  
  142. function ENT:Draw()
  143.  
  144. self:DrawModel()
  145.  
  146. local ply = LocalPlayer()
  147. local tr = ply:GetEyeTrace()
  148. local ent = tr.Entity
  149.  
  150. if ent:EntIndex() == self:EntIndex() and ent:GetClass() == "builder_barricade" then
  151. if tonumber(self.Complete) >= 100 and Builder.GCV("Builder_Complete") == "1" then return end
  152.  
  153. if tonumber(self.Complete) < tonumber(self.Goal) then
  154. AddWorldTip( "",tostring(self.Complete).."/"..tostring(self.Goal).."% Complete!", "", self:GetPos(), self )
  155. end
  156.  
  157. if self.CanDmg == true and tonumber(self.BarricadeHP) >= 1 and tonumber(self.Complete) >= tonumber(self.Goal) then
  158. AddWorldTip( "", "Health: "..tonumber(self.BarricadeHP), "", self:GetPos(), self )
  159. end
  160. end
  161.  
  162. end
  163.  
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement