Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if SERVER then
- AddCSLuaFile()
- SWEP.Weight = 5
- SWEP.AutoSwitchTo = true
- SWEP.AutoSwitchFrom = true
- end
- if CLIENT then
- SWEP.PrintName = "Teemo's Poison Dart"
- SWEP.Slot = 1
- SWEP.SlotPos = 1
- SWEP.DrawAmmo = true
- SWEP.DrawCrosshair = false
- end
- SWEP.Author = "Your Name"
- SWEP.Contact = "Your Email"
- SWEP.Purpose = "A deadly poison dart weapon"
- SWEP.Instructions = "Left click to fire a poison dart"
- SWEP.Category = "Your Category"
- SWEP.Spawnable = true
- SWEP.AdminOnly = false
- SWEP.ViewModelFOV = 70
- SWEP.ViewModelFlip = false
- SWEP.UseHands = true
- SWEP.ViewModel = "models/weapons/cstrike/c_pist_usp.mdl"
- SWEP.WorldModel = "models/weapons/w_pist_usp.mdl"
- SWEP.Primary.Sound = Sound("Weapon_USP.Single")
- SWEP.Primary.Damage = 10
- SWEP.Primary.NumShots = 1
- SWEP.Primary.Recoil = 0.5
- SWEP.Primary.Cone = 0.02
- SWEP.Primary.Delay = 0.15
- SWEP.Primary.ClipSize = 20
- SWEP.Primary.DefaultClip = 60
- SWEP.Primary.Automatic = true
- SWEP.Primary.Ammo = "Pistol"
- SWEP.Primary.Tracer = 1
- SWEP.Primary.TracerName = "Tracer"
- SWEP.Primary.Force = 10
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = "none"
- function SWEP:Initialize()
- self:SetHoldType("pistol")
- end
- if SERVER then
- SWEP.PoisonDamage = 5 -- Damage per tick of poison
- SWEP.PoisonInterval = 1 -- Time between poison ticks in seconds
- SWEP.PoisonDuration = 10 -- Duration of the poison debuff in seconds
- end
- function SWEP:PoisonTarget(target)
- if target:IsPlayer() or target:IsNPC() then
- target:SetNWBool("TeemoPoisoned", true)
- target:SetNWFloat("TeemoPoisonEndTime", CurTime() + self.PoisonDuration)
- target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
- end
- end
- function SWEP:Think()
- local owner = self:GetOwner()
- if not IsValid(owner) then return end
- local trace = owner:GetEyeTrace()
- local target = trace.Entity
- if IsValid(target) and not target:IsWorld() and not owner:IsSameTeam(target) then
- self:PoisonTarget(target)
- end
- if target:GetNWBool("TeemoPoisoned", false) and target:GetNWFloat("TeemoPoisonEndTime", 0) > CurTime() then
- if target:GetNWFloat("TeemoPoisonNextTick", 0) <= CurTime() then
- target:TakeDamage(self.PoisonDamage, owner, self)
- target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
- end
- else
- target:SetNWBool("TeemoPoisoned", false)
- target:SetNWFloat("TeemoPoisonEndTime", 0)
- target:SetNWFloat("TeemoPoisonNextTick", 0)
- end
- end
- function SWEP:Holster()
- self:EndPoison()
- return true
- end
- function SWEP:OnRemove()
- self:EndPoison()
- end
- function SWEP:EndPoison()
- for _, target in pairs(player.GetAll()) do
- target:SetNWBool("TeemoPoisoned", false)
- target:SetNWFloat("TeemoPoisonEndTime", 0)
- target:SetNWFloat("TeemoPoisonNextTick", 0)
- end
- end
- function Player:GetNWBool(name, default)
- return self:GetNWVarProxy(name, default)
- end
- function SWEP:DrawHUD()
- local target = self:GetOwner():GetEyeTrace().Entity
- if IsValid(target) and not target:IsWorld() and not self:GetOwner():IsSameTeam(target) then
- draw.SimpleText("Poison Target: " .. target:GetName(), "DermaDefault", ScrW() / 2, ScrH() / 2 - 50, Color(255, 0, 0), TEXT_ALIGN_CENTER)
- end
- if self:GetOwner():GetNWBool("TeemoPoisoned", false) then
- draw.SimpleText("Poisoned!", "DermaDefault", ScrW() / 2, ScrH() / 2 + 50, Color(0, 255, 0), TEXT_ALIGN_CENTER)
- end
- end
- function SWEP:Initialize()
- self:SetHoldType("pistol")
- end
- function SWEP:PrimaryAttack()
- if not self:CanPrimaryAttack() then return end
- local bullet = {}
- bullet.Num = self.Primary.NumShots
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector(self.Primary.Cone, self.Primary.Cone, 0)
- bullet.Tracer = self.Primary.Tracer
- bullet.TracerName = self.Primary.TracerName
- bullet.Force = self.Primary.Force
- bullet.Damage = self.Primary.Damage
- bullet.AmmoType = self.Primary.Ammo
- self:FireBullets(bullet)
- self:EmitSound(self.Primary.Sound)
- self:TakePrimaryAmmo(1)
- self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
- end
- function SWEP:SecondaryAttack()
- -- Secondary fire mode code here
- end
- function SWEP:Reload()
- -- Reload code here
- end
- if SERVER then
- SWEP.PoisonDamage = 5 -- Damage per tick of poison
- SWEP.PoisonInterval = 1 -- Time between poison ticks in seconds
- SWEP.PoisonDuration = 10 -- Duration of the poison debuff in seconds
- end
- function SWEP:PoisonTarget(target)
- if target:IsPlayer() or target:IsNPC() then
- target:SetNWBool("TeemoPoisoned", true)
- target:SetNWFloat("TeemoPoisonEndTime", CurTime() + self.PoisonDuration)
- target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
- end
- end
- function SWEP:Think()
- local owner = self:GetOwner()
- if not IsValid(owner) then return end
- local trace = owner:GetEyeTrace()
- local target = trace.Entity
- if IsValid(target) and not target:IsWorld() and not owner:IsSameTeam(target) then
- self:PoisonTarget(target)
- end
- if target:GetNWBool("TeemoPoisoned", false) and target:GetNWFloat("TeemoPoisonEndTime", 0) > CurTime() then
- if target:GetNWFloat("TeemoPoisonNextTick", 0) <= CurTime() then
- target:TakeDamage(self.PoisonDamage, owner, self)
- target:SetNWFloat("TeemoPoisonNextTick", CurTime() + self.PoisonInterval)
- end
- else
- target:SetNWBool("TeemoPoisoned", false)
- target:SetNWFloat("TeemoPoisonEndTime", 0)
- target:SetNWFloat("TeemoPoisonNextTick", 0)
- end
- end
- function SWEP:DrawHUD()
- local target = self:GetOwner():GetEyeTrace().Entity
- if IsValid(target) and not target:IsWorld() and not self:GetOwner():IsSameTeam(target) then
- local w = ScrW()
- local h = ScrH()
- local x, y = w/2, h/2
- surface.SetDrawColor(255, 255, 255, 255)
- surface.DrawLine(x-20, y, x-10, y)
- surface.DrawLine(x+10, y, x+20, y)
- surface.DrawLine(x, y-20, x, y-10)
- surface.DrawLine(x, y+10, x, y+20)
- end
- end
- function SWEP:Initialize()
- self:SetHoldType("pistol")
- end
- function SWEP:PrimaryAttack()
- if not self:CanPrimaryAttack() then return end
- local bullet = {}
- bullet.Num = self.Primary.NumShots
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector(self.Primary.Cone, self.Primary.Cone, 0)
- bullet.Tracer = self.Primary.Tracer
- bullet.TracerName = self.Primary.TracerName
- bullet.Force = self.Primary.Force
- bullet.Damage = self.Primary.Damage
- bullet.AmmoType = self.Primary.Ammo
- self:FireBullets(bullet)
- self:EmitSound(self.Primary.Sound)
- self:TakePrimaryAmmo(1)
- self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
- end
- function SWEP:SecondaryAttack()
- -- Secondary fire mode code here
- end
- function SWEP:Reload()
- -- Reload code here
- end
- if CLIENT then
- local TeemoIcon = Material("vgui/hud/teemo_icon")
- function SWEP:DrawHUD()
- surface.SetDrawColor(255, 255, 255, 255)
- surface.SetMaterial(TeemoIcon)
- surface.DrawTexturedRect(20, ScrH() - 120, 100, 100)
- local owner = self:GetOwner()
- if not IsValid(owner) then return end
- local target = owner:GetEyeTrace().Entity
- if not IsValid(target) or target:IsWorld() or owner:IsSameTeam(target) then return end
- local x, y = ScrW() / 2, ScrH() / 2
- local w, h = 200, 40
- draw.RoundedBox(8, x - w / 2, y - h / 2, w, h, Color(0, 0, 0, 200))
- local poisonEndTime = target:GetNWFloat("TeemoPoisonEndTime", 0)
- local timeLeft = math.max(0, poisonEndTime - CurTime())
- local numTicks = math.ceil(timeLeft / self.PoisonInterval)
- local totalDamage = self.PoisonDamage * numTicks
- local text = string.format("Poisoned: %d damage over %d seconds", totalDamage, math.ceil(timeLeft))
- draw.SimpleText(text, "DermaDefault", x, y, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
- end
- end
- function SWEP:PrimaryAttack()
- self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
- if SERVER then
- local bullet = {}
- bullet.Num = 1
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector(0, 0, 0)
- bullet.Tracer = 1
- bullet.TracerName = "Tracer"
- bullet.Force = 10
- bullet.Damage = self.Primary.Damage
- self.Owner:FireBullets(bullet)
- end
- self:EmitSound("Weapon_AR2.Single")
- self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
- local animTime = self.Owner:GetViewModel():SequenceDuration()
- timer.Simple(animTime, function()
- if IsValid(self) then
- self:SendWeaponAnim(ACT_VM_IDLE)
- end
- end)
- end
- if CLIENT then
- local TeemoIcon = Material("vgui/hud/teemo_icon")
- function SWEP:DrawHUD()
- surface.SetDrawColor(255, 255, 255, 255)
- surface.SetMaterial(TeemoIcon)
- surface.DrawTexturedRect(20, ScrH() - 120, 100, 100)
- if self:IsPoisoned() then
- local totalDamage = self.PoisonDamage * self.PoisonDuration / self.PoisonInterval
- local timeLeft = self.PoisonEndTime - CurTime()
- local text = string.format("Poisoned: %d damage over %d seconds", totalDamage, math.ceil(timeLeft))
- draw.DrawText(text, "Trebuchet24", 130, ScrH() - 70, Color(255, 255, 255), TEXT_ALIGN_LEFT)
- end
- end
- function SWEP:ViewModelDrawn()
- local vm = self.Owner:GetViewModel()
- local attachment = vm:GetAttachment(1)
- if not attachment then return end
- local pos = attachment.Pos
- local ang = attachment.Ang
- pos = pos + ang:Forward() * 2 + ang:Right() * -3 + ang:Up() * -3
- cam.Start3D2D(pos, ang, 0.02)
- surface.SetDrawColor(255, 255, 255, 255)
- surface.SetMaterial(TeemoIcon)
- surface.DrawTexturedRect(0, 0, 150, 150)
- cam.End3D2D()
- end
- end
- function SWEP:GetPoisoned()
- return self:GetNWBool("IsPoisoned", false)
- end
- function SWEP:SecondaryAttack()
- -- Check if the poison is already active
- if self:GetPoisoned() then return end
- -- Set the poison duration and activate the poison
- self.PoisonDuration = 5
- self:SetPoisoned(true)
- -- Play the poison sound
- self:EmitSound("teemo/poison.wav")
- -- Create the poison effect
- local effectData = EffectData()
- effectData:SetOrigin(self.Owner:GetShootPos())
- util.Effect("TeemoPoison", effectData)
- -- Set the next time the poison will tick
- self.NextPoisonTick = CurTime() + self.PoisonInterval
- end
- function SWEP:Think()
- -- Check if the poison is active
- if self:GetPoisoned() then
- -- Check if it's time for the poison to tick
- if CurTime() >= self.NextPoisonTick then
- -- Deal damage to the target
- local target = self.Owner:GetEyeTrace().Entity
- if IsValid(target) and target:IsPlayer() or target:IsNPC() then
- local damageInfo = DamageInfo()
- damageInfo:SetAttacker(self.Owner)
- damageInfo:SetInflictor(self)
- damageInfo:SetDamage(self.PoisonDamage)
- target:TakeDamageInfo(damageInfo)
- end
- -- Reduce the poison duration and set the next poison tick time
- self.PoisonDuration = self.PoisonDuration - self.PoisonInterval
- self.NextPoisonTick = CurTime() + self.PoisonInterval
- end
- -- Check if the poison has run its course
- if self.PoisonDuration <= 0 then
- self:SetPoisoned(false)
- end
- end
- end
- function SWEP:Think()
- local owner = self:GetOwner()
- if self:IsPoisoned(owner) then
- -- Apply poison damage here
- end
- end
- -- Register the SWEP with Garry's Mod
- weapons.Register(SWEP, "weapon_teemo_poison_shooter", true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement