Advertisement
Guest User

Base

a guest
Feb 25th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.36 KB | None | 0 0
  1. ENT.Type = "anim"
  2. ENT.Base = "base_anim"
  3. ENT.PrintName = "AmmoBase"
  4. ENT.Category = "TFA Ammunition"
  5. ENT.Spawnable = false
  6. ENT.AdminSpawnable = false
  7. ENT.Class = ""
  8. ENT.MyModel = "models/props_junk/popcan01a.mdl"
  9. ENT.ImpactSound = "Default.ImpactSoft"
  10. ENT.AmmoCount = 100
  11. ENT.AmmoType = "357"
  12. ENT.TextPosition = Vector(-2.5, -3.3, 4)
  13. ENT.TextAngles = Vector(48, -90, 0)
  14. ENT.TextColor = Color(240, 35, 35, 255)
  15. ENT.DrawText = false
  16. ENT.ShouldDrawShadow = true
  17. ENT.ImpactSound = "Default.ImpactSoft"
  18. ENT.DamageThreshold = 80
  19. ENT.ExplosionOffset = Vector(0, 0, 10)
  20. ENT.Damage = 30
  21. ENT.TextOffX = 30
  22. ENT.TextOffY = -20
  23. ENT.TextScale = 1
  24.  
  25. if SERVER then
  26.     AddCSLuaFile()
  27.  
  28.     function ENT:SpawnFunction(ply, tr, classname)
  29.         if (not tr.Hit) then return end
  30.         local pos = tr.HitPos + tr.HitNormal * 4
  31.         local ent = ents.Create(classname)
  32.         ent:SetPos(pos)
  33.         ent:Spawn()
  34.         ent:Activate()
  35.         ent.Class = classname
  36.         ent.Spawner = ply
  37.  
  38.         return ent
  39.     end
  40.  
  41.     function ENT:Initialize()
  42.         local model = self.MyModel
  43.         self.Class = self:GetClass()
  44.         self:SetModel(model)
  45.         self:PhysicsInit(SOLID_VPHYSICS)
  46.         self:SetMoveType(MOVETYPE_VPHYSICS)
  47.         self:SetSolid(SOLID_VPHYSICS)
  48.         self:DrawShadow(self.ShouldDrawShadow)
  49.         self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  50.         self:SetUseType(SIMPLE_USE)
  51.         self:SetHealth(self.DamageThreshold)
  52.         self:SetNW2Bool("ShouldRemove", false)
  53.         local phys = self:GetPhysicsObject()
  54.  
  55.         if (phys:IsValid()) then
  56.             phys:Wake()
  57.         end
  58.     end
  59.  
  60.     function ENT:PhysicsCollide(data, physobj)
  61.         if (data.Speed > 60 and data.DeltaTime > 0.2) then
  62.             self:EmitSound(self.ImpactSound)
  63.         end
  64.     end
  65.  
  66.     function ENT:Use(activator, caller)
  67.         if IsValid(activator) and activator:IsPlayer() then
  68.             activator:GiveAmmo(self.AmmoCount, self.AmmoType)
  69.             self:SetNW2Bool("ShouldRemove", true)
  70.         end
  71.     end
  72.  
  73.     local bul = {}
  74.     local randvec = Vector(0, 0, 0)
  75.     bul.Tracer = 3
  76.     bul.Num = 1
  77.     bul.TracerName = "Tracer"
  78.     bul.Spread = Vector(0, 0, 0)
  79.  
  80.     local cv_dc = GetConVar("sv_tfa_ammo_detonation_chain")
  81.     local cv_dm = GetConVar("sv_tfa_ammo_detonation_mode")
  82.     function ENT:OnTakeDamage(dmginfo)
  83.         if not IsValid(self) then return end
  84.         local at = dmginfo:GetInflictor()
  85.         local shouldtakedamage = true
  86.  
  87.         if IsValid(at) then
  88.             local base = at.Base
  89.  
  90.             if (base and string.find(base, "tfa_ammo_base")) or string.find(at:GetClass(), "tfa_ammo_") and not cv_dc:GetBool() then
  91.                 shouldtakedamage = false
  92.             end
  93.         end
  94.  
  95.         if dmginfo:GetDamage() < 1 then
  96.             shouldtakedamage = false
  97.         end
  98.  
  99.         self.Attacker = at
  100.  
  101.         if shouldtakedamage then
  102.             self:SetHealth(self:Health() - dmginfo:GetDamage())
  103.         end
  104.  
  105.         self:EmitSound(self.ImpactSound)
  106.         local phy = self:GetPhysicsObject()
  107.  
  108.         if IsValid(phy) then
  109.             local f = dmginfo:GetDamageForce()
  110.             local p = dmginfo:GetDamagePosition()
  111.  
  112.             if f and p then
  113.                 phy:ApplyForceOffset(f / 4, p)
  114.             end
  115.         end
  116.     end
  117.  
  118.     function ENT:Think()
  119.         if self:GetNW2Bool("ShouldRemove", false) then
  120.             self:Remove()
  121.  
  122.             return false
  123.         end
  124.  
  125.         if not cv_dc:GetBool() then return true end
  126.  
  127.         if self:Health() <= 0 then
  128.             self:EmitSound(self.ImpactSound)
  129.             local adm = cv_dm:GetInt()
  130.             bul.AmmoType = self.AmmoType
  131.             bul.Damage = self.Damage
  132.             bul.Force = math.Max(self.Damage / 25, 0.1)
  133.             bul.Attacker = self
  134.  
  135.             if IsValid(self.Attacker) then
  136.                 bul.Attacker = self.Attacker
  137.             end
  138.  
  139.             local upang = self:GetAngles():Up()
  140.             bul.Dir = upang + randvec * 0.75
  141.             local numbuls = math.random(math.Round(self.AmmoCount * 0.25), math.Round(self.AmmoCount * 0.75))
  142.             local i = 1
  143.  
  144.             if adm == 2 then
  145.                 bul.Damage = bul.Damage / 2
  146.             end
  147.  
  148.             bul.Dir = (upang + randvec * 0.75):GetNormalized()
  149.             bul.Src = self:GetPos()
  150.             self:FireBullets(bul)
  151.  
  152.             if adm ~= 1 then
  153.                 while i <= math.Clamp(numbuls, 1, 35) do
  154.                     randvec.x = math.Rand(-1, 1)
  155.                     randvec.y = math.Rand(-1, 1)
  156.                     randvec.z = math.Rand(-1, 1)
  157.                     bul.Dir = (upang + randvec * 0.75):GetNormalized()
  158.                     bul.Src = self:GetPos()
  159.                     self:FireBullets(bul)
  160.                     i = i + 1
  161.                 end
  162.             end
  163.  
  164.             local effectdata = EffectData()
  165.             effectdata:SetOrigin(self:GetPos())
  166.             effectdata:SetMagnitude(0.1)
  167.             effectdata:SetScale(0.5)
  168.  
  169.             if adm == 1 then
  170.                 bul.Damage = bul.Damage * 3 / 4
  171.             end
  172.  
  173.             if adm > 0 then
  174.                 util.BlastDamage(bul.Attacker, bul.Attacker, bul.Src, (bul.Damage * 6 + 128) / 2, bul.Damage * 2)
  175.                 util.Effect("Explosion", effectdata)
  176.             end
  177.  
  178.             if adm ~= 1 then
  179.                 util.Effect("cball_explode", effectdata)
  180.             end
  181.  
  182.             self:SetNW2Bool("ShouldRemove", true)
  183.         end
  184.     end
  185. end
  186.  
  187. if CLIENT then
  188.     function ENT:Initialize()
  189.         self.Class = self:GetClass()
  190.     end
  191.  
  192.     function ENT:Draw()
  193.         self:DrawModel()
  194.  
  195.         if self.TextPosition and self.TextAngles and self.DrawText then
  196.             local pos = self:GetPos() + (self:GetUp() * self.TextPosition.z) + (self:GetRight() * self.TextPosition.x) + (self:GetForward() * self.TextPosition.y)
  197.             local ang = self:GetAngles()
  198.             ang:RotateAroundAxis(ang:Right(), self.TextAngles.x)
  199.             ang:RotateAroundAxis(ang:Up(), self.TextAngles.y)
  200.             ang:RotateAroundAxis(ang:Forward(), self.TextAngles.z)
  201.  
  202.             if not self.Text then
  203.                 self.Text = string.upper(self.AmmoType)
  204.             end
  205.  
  206.             cam.Start3D2D(pos, ang, .07 * self.TextScale)
  207.             draw.SimpleText(self.Text, "DermaLarge", self.TextOffX, self.TextOffY, self.TextColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  208.             cam.End3D2D()
  209.         end
  210.     end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement