Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.39 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.         if (phys:IsValid()) then
  55.             phys:Wake()
  56.         end
  57.     end
  58.  
  59.     function ENT:PhysicsCollide(data, physobj)
  60.         if (data.Speed > 60 and data.DeltaTime > 0.2) then
  61.             self:EmitSound(self.ImpactSound)
  62.         end
  63.     end
  64.  
  65.     function ENT:Use(activator, caller)
  66.         if IsValid(activator) and activator:IsPlayer() then
  67.        
  68. // DEADMAN
  69.            
  70.             if self.AmmoLeft == nil then
  71.     local a = self.AmmoType
  72.     if a == "ar2" then
  73.         self.AmmoLeft = 3000
  74.     elseif a == "grenades" then
  75.         self.AmmoLeft = 20
  76.     end
  77. end
  78.  
  79.  
  80. if self.AmmoType == "ar2" then
  81.     self.AmmoLeft = self.AmmoLeft - 100
  82.     activator:GiveAmmo(self.AmmoCount, self.AmmoType)
  83. elseif self.AmmoType == "grenades" then
  84.  
  85. local SwepsList = {}
  86.  
  87. for _, swep in pairs(activator:GetWeapons()) do
  88.     local actualSwepString = string.Explode("[", tostring(swep))[3] -- keep only "weapon_crossbow]"
  89.     actualSwepString = string.Replace(actualSwepString, "]", "" ) -- removing the "]"
  90.       table.insert(SwepsList, actualSwepString)
  91. end
  92.  
  93. local plyHaveGrenade = false
  94. for _, swep in (SwepsList) do
  95.     if swep == "thermal detonator" then
  96.         plyHaveGrenade = true
  97.     end
  98. end
  99.     if plyHaveGrenade then
  100.         self.AmmoLeft = self.AmmoLeft - 1
  101.         activator:GiveAmmo(self.AmmoCount, self.AmmoType)
  102.     end
  103. end
  104.  
  105.             if self.AmmoLeft <= 0 then -- Deadman
  106.                 self:SetNW2Bool("ShouldRemove", true)
  107.             end -- Deadman
  108.         end
  109. // DEADMAN
  110.     end
  111.  
  112.     local bul = {}
  113.     local randvec = Vector(0, 0, 0)
  114.     bul.Tracer = 3
  115.     bul.Num = 1
  116.     bul.TracerName = "Tracer"
  117.     bul.Spread = Vector(0, 0, 0)
  118.  
  119.     local cv_dc = GetConVar("sv_tfa_ammo_detonation_chain")
  120.     local cv_dm = GetConVar("sv_tfa_ammo_detonation_mode")
  121.     function ENT:OnTakeDamage(dmginfo)
  122.         if not IsValid(self) then return end
  123.         local at = dmginfo:GetInflictor()
  124.         local shouldtakedamage = true
  125.  
  126.         if IsValid(at) then
  127.             local base = at.Base
  128.  
  129.             if (base and string.find(base, "tfa_ammo_base")) or string.find(at:GetClass(), "tfa_ammo_") and not cv_dc:GetBool() then
  130.                 shouldtakedamage = false
  131.             end
  132.         end
  133.  
  134.         if dmginfo:GetDamage() < 1 then
  135.             shouldtakedamage = false
  136.         end
  137.  
  138.         self.Attacker = at
  139.  
  140.         if shouldtakedamage then
  141.             self:SetHealth(self:Health() - dmginfo:GetDamage())
  142.         end
  143.  
  144.         self:EmitSound(self.ImpactSound)
  145.         local phy = self:GetPhysicsObject()
  146.  
  147.         if IsValid(phy) then
  148.             local f = dmginfo:GetDamageForce()
  149.             local p = dmginfo:GetDamagePosition()
  150.  
  151.             if f and p then
  152.                 phy:ApplyForceOffset(f / 4, p)
  153.             end
  154.         end
  155.     end
  156.  
  157.     function ENT:Think()
  158.         if self:GetNW2Bool("ShouldRemove", false) then
  159.             self:Remove()
  160.  
  161.             return false
  162.         end
  163.  
  164.         if not cv_dc:GetBool() then return true end
  165.  
  166.         if self:Health() <= 0 then
  167.             self:EmitSound(self.ImpactSound)
  168.             local adm = cv_dm:GetInt()
  169.             bul.AmmoType = self.AmmoType
  170.             bul.Damage = self.Damage
  171.             bul.Force = math.Max(self.Damage / 25, 0.1)
  172.             bul.Attacker = self
  173.  
  174.             if IsValid(self.Attacker) then
  175.                 bul.Attacker = self.Attacker
  176.             end
  177.  
  178.             local upang = self:GetAngles():Up()
  179.             bul.Dir = upang + randvec * 0.75
  180.             local numbuls = math.random(math.Round(self.AmmoCount * 0.25), math.Round(self.AmmoCount * 0.75))
  181.             local i = 1
  182.  
  183.             if adm == 2 then
  184.                 bul.Damage = bul.Damage / 2
  185.             end
  186.  
  187.             bul.Dir = (upang + randvec * 0.75):GetNormalized()
  188.             bul.Src = self:GetPos()
  189.             self:FireBullets(bul)
  190.  
  191.             if adm ~= 1 then
  192.                 while i <= math.Clamp(numbuls, 1, 35) do
  193.                     randvec.x = math.Rand(-1, 1)
  194.                     randvec.y = math.Rand(-1, 1)
  195.                     randvec.z = math.Rand(-1, 1)
  196.                     bul.Dir = (upang + randvec * 0.75):GetNormalized()
  197.                     bul.Src = self:GetPos()
  198.                     self:FireBullets(bul)
  199.                     i = i + 1
  200.                 end
  201.             end
  202.  
  203.             local effectdata = EffectData()
  204.             effectdata:SetOrigin(self:GetPos())
  205.             effectdata:SetMagnitude(0.1)
  206.             effectdata:SetScale(0.5)
  207.  
  208.             if adm == 1 then
  209.                 bul.Damage = bul.Damage * 3 / 4
  210.             end
  211.  
  212.             if adm > 0 then
  213.                 util.BlastDamage(bul.Attacker, bul.Attacker, bul.Src, (bul.Damage * 6 + 128) / 2, bul.Damage * 2)
  214.                 util.Effect("Explosion", effectdata)
  215.             end
  216.  
  217.             if adm ~= 1 then
  218.                 util.Effect("cball_explode", effectdata)
  219.             end
  220.  
  221.             self:SetNW2Bool("ShouldRemove", true)
  222.         end
  223.     end
  224. end
  225.  
  226. if CLIENT then
  227.     function ENT:Initialize()
  228.         self.Class = self:GetClass()
  229.     end
  230.  
  231.     function ENT:Draw()
  232.         self:DrawModel()
  233.  
  234.         if self.TextPosition and self.TextAngles and self.DrawText then
  235.             local pos = self:GetPos() + (self:GetUp() * self.TextPosition.z) + (self:GetRight() * self.TextPosition.x) + (self:GetForward() * self.TextPosition.y)
  236.             local ang = self:GetAngles()
  237.             ang:RotateAroundAxis(ang:Right(), self.TextAngles.x)
  238.             ang:RotateAroundAxis(ang:Up(), self.TextAngles.y)
  239.             ang:RotateAroundAxis(ang:Forward(), self.TextAngles.z)
  240.  
  241.             if not self.Text then
  242.                 self.Text = string.upper(self.AmmoType)
  243.             end
  244.  
  245.             cam.Start3D2D(pos, ang, .07 * self.TextScale)
  246.             draw.SimpleText(self.Text, "DermaLarge", self.TextOffX, self.TextOffY, self.TextColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  247.             cam.End3D2D()
  248.         end
  249.     end
  250. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement