Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 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.         return ent
  38.     end
  39.  
  40.     function ENT:Initialize()
  41.         local model = self.MyModel
  42.         self.Class = self:GetClass()
  43.         self:SetModel(model)
  44.         self:PhysicsInit(SOLID_VPHYSICS)
  45.         self:SetMoveType(MOVETYPE_VPHYSICS)
  46.         self:SetSolid(SOLID_VPHYSICS)
  47.         self:DrawShadow(self.ShouldDrawShadow)
  48.         self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  49.         self:SetUseType(SIMPLE_USE)
  50.         self:SetHealth(self.DamageThreshold)
  51.         self:SetNW2Bool("ShouldRemove", false)
  52.         local phys = self:GetPhysicsObject()
  53.        
  54.         self.AmmoLeft = 3000 -- Deadman
  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.AmmoLeft = self.AmmoLeft - self.AmmoCount -- Deadman
  70.            
  71.             if self.AmmoLeft <= 0 then -- Deadman
  72.                 self:SetNW2Bool("ShouldRemove", true)
  73.             end -- Deadman
  74.         end
  75.     end
  76.  
  77.     local bul = {}
  78.     local randvec = Vector(0, 0, 0)
  79.     bul.Tracer = 3
  80.     bul.Num = 1
  81.     bul.TracerName = "Tracer"
  82.     bul.Spread = Vector(0, 0, 0)
  83.  
  84.     local cv_dc = GetConVar("sv_tfa_ammo_detonation_chain")
  85.     local cv_dm = GetConVar("sv_tfa_ammo_detonation_mode")
  86.     function ENT:OnTakeDamage(dmginfo)
  87.         if not IsValid(self) then return end
  88.         local at = dmginfo:GetInflictor()
  89.         local shouldtakedamage = true
  90.  
  91.         if IsValid(at) then
  92.             local base = at.Base
  93.  
  94.             if (base and string.find(base, "tfa_ammo_base")) or string.find(at:GetClass(), "tfa_ammo_") and not cv_dc:GetBool() then
  95.                 shouldtakedamage = false
  96.             end
  97.         end
  98.  
  99.         if dmginfo:GetDamage() < 1 then
  100.             shouldtakedamage = false
  101.         end
  102.  
  103.         self.Attacker = at
  104.  
  105.         if shouldtakedamage then
  106.             self:SetHealth(self:Health() - dmginfo:GetDamage())
  107.         end
  108.  
  109.         self:EmitSound(self.ImpactSound)
  110.         local phy = self:GetPhysicsObject()
  111.  
  112.         if IsValid(phy) then
  113.             local f = dmginfo:GetDamageForce()
  114.             local p = dmginfo:GetDamagePosition()
  115.  
  116.             if f and p then
  117.                 phy:ApplyForceOffset(f / 4, p)
  118.             end
  119.         end
  120.     end
  121.  
  122.     function ENT:Think()
  123.         if self:GetNW2Bool("ShouldRemove", false) then
  124.             self:Remove()
  125.  
  126.             return false
  127.         end
  128.  
  129.         if not cv_dc:GetBool() then return true end
  130.  
  131.         if self:Health() <= 0 then
  132.             self:EmitSound(self.ImpactSound)
  133.             local adm = cv_dm:GetInt()
  134.             bul.AmmoType = self.AmmoType
  135.             bul.Damage = self.Damage
  136.             bul.Force = math.Max(self.Damage / 25, 0.1)
  137.             bul.Attacker = self
  138.  
  139.             if IsValid(self.Attacker) then
  140.                 bul.Attacker = self.Attacker
  141.             end
  142.  
  143.             local upang = self:GetAngles():Up()
  144.             bul.Dir = upang + randvec * 0.75
  145.             local numbuls = math.random(math.Round(self.AmmoCount * 0.25), math.Round(self.AmmoCount * 0.75))
  146.             local i = 1
  147.  
  148.             if adm == 2 then
  149.                 bul.Damage = bul.Damage / 2
  150.             end
  151.  
  152.             bul.Dir = (upang + randvec * 0.75):GetNormalized()
  153.             bul.Src = self:GetPos()
  154.             self:FireBullets(bul)
  155.  
  156.             if adm ~= 1 then
  157.                 while i <= math.Clamp(numbuls, 1, 35) do
  158.                     randvec.x = math.Rand(-1, 1)
  159.                     randvec.y = math.Rand(-1, 1)
  160.                     randvec.z = math.Rand(-1, 1)
  161.                     bul.Dir = (upang + randvec * 0.75):GetNormalized()
  162.                     bul.Src = self:GetPos()
  163.                     self:FireBullets(bul)
  164.                     i = i + 1
  165.                 end
  166.             end
  167.  
  168.             local effectdata = EffectData()
  169.             effectdata:SetOrigin(self:GetPos())
  170.             effectdata:SetMagnitude(0.1)
  171.             effectdata:SetScale(0.5)
  172.  
  173.             if adm == 1 then
  174.                 bul.Damage = bul.Damage * 3 / 4
  175.             end
  176.  
  177.             if adm > 0 then
  178.                 util.BlastDamage(bul.Attacker, bul.Attacker, bul.Src, (bul.Damage * 6 + 128) / 2, bul.Damage * 2)
  179.                 util.Effect("Explosion", effectdata)
  180.             end
  181.  
  182.             if adm ~= 1 then
  183.                 util.Effect("cball_explode", effectdata)
  184.             end
  185.  
  186.             self:SetNW2Bool("ShouldRemove", true)
  187.         end
  188.     end
  189. end
  190.  
  191. if CLIENT then
  192.     function ENT:Initialize()
  193.         self.Class = self:GetClass()
  194.     end
  195.  
  196.     function ENT:Draw()
  197.         self:DrawModel()
  198.  
  199.         if self.TextPosition and self.TextAngles and self.DrawText then
  200.             local pos = self:GetPos() + (self:GetUp() * self.TextPosition.z) + (self:GetRight() * self.TextPosition.x) + (self:GetForward() * self.TextPosition.y)
  201.             local ang = self:GetAngles()
  202.             ang:RotateAroundAxis(ang:Right(), self.TextAngles.x)
  203.             ang:RotateAroundAxis(ang:Up(), self.TextAngles.y)
  204.             ang:RotateAroundAxis(ang:Forward(), self.TextAngles.z)
  205.  
  206.             if not self.Text then
  207.                 self.Text = string.upper(self.AmmoType)
  208.             end
  209.  
  210.             cam.Start3D2D(pos, ang, .07 * self.TextScale)
  211.             draw.SimpleText(self.Text, "DermaLarge", self.TextOffX, self.TextOffY, self.TextColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  212.             cam.End3D2D()
  213.         end
  214.     end
  215. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement