Hello, I'm looking for a way to make a weapon set the user's hp back to 100 after they kill their target. I've been looking around and it seems like I would have to use eye traces to make this work. The way the weapon I want to implement this on is coded that will not work.
Here is the code for the weapon:
[CODE]sound.Add(
{
name = "ZMP_BANG1.Fire",
channel = CHAN_WEAPON,
volume = 1.0,
soundlevel = 100,
pitchstart = 95,
pitchend = 105,
sound = "weapons/nyan/bang1.wav"
})
sound.Add(
{
name = "ZMP_BANG2.Fire",
channel = CHAN_WEAPON,
volume = 1.0,
soundlevel = 100,
pitchstart = 95,
pitchend = 105,
sound = "weapons/nyan/bang2.wav"
})
sound.Add(
{
name = "ZMP_BANG3.Fire",
channel = CHAN_WEAPON,
volume = 1.0,
soundlevel = 100,
pitchstart = 95,
pitchend = 105,
sound = "weapons/nyan/bang3.wav"
})
sound.Add(
{
name = "ZMP_BANG4.Fire",
channel = CHAN_WEAPON,
volume = 1.0,
soundlevel = 100,
pitchstart = 95,
pitchend = 105,
sound = "weapons/nyan/bang4.wav"
})
AddCSLuaFile()
AddCSLuaFile( "effects/rb007_bond_tracer.lua" )
AddCSLuaFile( "effects/rb007_bond_bounce.lua" )
SWEP.Slot = 2
SWEP.SlotPos = 5
SWEP.DrawWeaponInfoBox = false
SWEP.Base = "weapon_base"
SWEP.PrintName = "Bond Gun"
SWEP.Category = "Robotboy655's Weapons"
SWEP.ViewModel = "models/weapons/c_smg1.mdl"
SWEP.WorldModel = "models/weapons/w_smg1.mdl"
SWEP.Spawnable = true
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.ViewModelFOV = 54
SWEP.UseHands = true
SWEP.DrawAmmo = false
SWEP.HoldType = "smg"
SWEP.Primary.ClipSize = 100
SWEP.Primary.Delay = 0.1
SWEP.Primary.Damage = 30
SWEP.Primary.DefaultClip = 100
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "007_bond"
SWEP.Secondary.ClipSize = 5
SWEP.Secondary.Delay = 0.5
SWEP.Secondary.Damage = 20
SWEP.Secondary.DefaultClip = 5
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "rb007_bond"
game.AddAmmoType( { name = "rb007_bond" } )
if ( CLIENT ) then language.Add( "rb007_bond_ammo", "Annoying Ammo" ) end
/* --------------------------------- TTT ---------------------------------- */
SWEP.EquipMenuData = {
type = "item_weapon",
desc = [[The Nyan Gun. Provides:
* Blown cover
* Annoying sounds
* Kind of a lot of ammo
* Annoyingly small damage]]
}
SWEP.Icon = "nyan/ttt_icon.png"
SWEP.Kind = WEAPON_EQUIP2
SWEP.LimitedStock = true
if ( GAMEMODE.Name == "Trouble in Terrorist Town" ) then
SWEP.Primary.Damage = 3
SWEP.Primary.ClipSize = 999
SWEP.Primary.DefaultClip = 999
SWEP.Primary.ClipMax = 999
SWEP.Slot = 6
end
function SWEP:IsEquipment() return false end
/* ------------------------------ END OF TTT ------------------------------ */
function SWEP:SetupDataTables()
self:NetworkVar( "Float", 1, "NextIdle" )
end
function SWEP:Initialize()
self:SetHoldType( self.HoldType )
end
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
if ( self.Owner:IsNPC() ) then
self:EmitSound( "weapons/nyan/nya" .. math.random( 1, 2 ) .. ".wav", 100, math.random( 60, 80 ) )
else
if ( self.LoopSound ) then
self.LoopSound:ChangeVolume( 1, 0.1 )
else
self.LoopSound = CreateSound( self.Owner, Sound( "weapons/nyan/bond_fire.wav" ) )
if ( self.LoopSound ) then self.LoopSound:Play() end
end
if ( self.BeatSound ) then self.BeatSound:ChangeVolume( 0, 0.1 ) end
end
if ( IsFirstTimePredicted() ) then
local bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( 0.01, 0.01, 0 )
bullet.Tracer = 1
bullet.Force = 5
bullet.Damage = self.Primary.Damage
//bullet.AmmoType = "Ar2AltFire" -- For some extremely stupid reason this breaks the tracer effect
bullet.TracerName = "rb007_bond_tracer"
self.Owner:FireBullets( bullet )
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
if ( GAMEMODE.Name == "Trouble in Terrorist Town" ) then
self:TakePrimaryAmmo( 1 )
end
end
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
self:Idle()
end
function SWEP:GetHeadshotMultiplier()
return 1
end
function SWEP:SecondaryAttack()
--if ( GAMEMODE.Name == "Trouble in Terrorist Town" ) then return end // Disable it
-- local owner = self.Owner
--local owner_pos = owner:GetPos()
if ( !self:CanSecondaryAttack() ) then return end
if ( IsFirstTimePredicted() ) then
self.Owner:EmitSound( "weapons/nyan/bang" .. math.random( 1, 4 ) .. ".wav", 100, math.random( 85, 100 ) )
local bullet = {}
bullet.Num = 3
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( 0.12, 0.12, 0 )
bullet.Tracer = 1
bullet.Force = 10
bullet.Damage = self.Secondary.Damage
//bullet.AmmoType = "Ar2AltFire"
bullet.TracerName = "rb007_bond_tracer"
self.Owner:FireBullets( bullet )
self:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
end
self:SetNextPrimaryFire( CurTime() + self.Secondary.Delay )
self:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
self:Idle()
end
function SWEP:Reload()
if ( GAMEMODE.Name == "Trouble in Terrorist Town" ) then return end // Disable it
if ( !self.Owner:KeyPressed( IN_RELOAD ) ) then return end
if ( self:GetNextPrimaryFire() > CurTime() ) then return end
if ( SERVER ) then
local ang = self.Owner:EyeAngles()
local ent = ents.Create( "ent_nyan_bomb" )
if ( IsValid( ent ) ) then
ent:SetPos( self.Owner:GetShootPos() + ang:Forward() * 28 + ang:Right() * 24 - ang:Up() * 8 )
ent:SetAngles( ang )
ent:SetOwner( self.Owner )
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() phys:AddVelocity( ent:GetForward() * 1337 ) end
end
end
self:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self:EmitSound( "weapons/nyan/nya" .. math.random( 1, 2 ) .. ".wav", 100, math.random( 60, 80 ) )
self:SetNextPrimaryFire( CurTime() + 1 )
self:SetNextSecondaryFire( CurTime() + 1 )
self:Idle()
end
function SWEP:DoImpactEffect( trace, damageType )
local effectdata = EffectData()
effectdata:SetStart( trace.HitPos )
effectdata:SetOrigin( trace.HitNormal + Vector( math.Rand( -0.5, 0.5 ), math.Rand( -0.5, 0.5 ), math.Rand( -0.5, 0.5 ) ) )
util.Effect( "rb007_bond_bounce", effectdata )
return true
end
function SWEP:FireAnimationEvent( pos, ang, event )
return true
end
function SWEP:KillSounds()
if ( self.BeatSound ) then self.BeatSound:Stop() self.BeatSound = nil end
if ( self.LoopSound ) then self.LoopSound:Stop() self.LoopSound = nil end
timer.Destroy( "rb007_bond" .. self:EntIndex() )
end
function SWEP:OnRemove()
self:KillSounds()
end
function SWEP:OnDrop()
self:KillSounds()
end
function SWEP:Deploy()
self:SendWeaponAnim( ACT_VM_DRAW )
self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() )
if ( CLIENT ) then return true end
self:Idle()
self.BeatSound = CreateSound( self.Owner, Sound( "weapons/nyan/bond_idle.wav" ) )
if ( self.BeatSound ) then self.BeatSound:Play() end
return true
end
function SWEP:Holster()
self:KillSounds()
return true
end
function SWEP:Think()
if ( self:GetNextIdle() > 0 && CurTime() > self:GetNextIdle() ) then
self:DoIdleAnimation()
self:Idle()
end
if ( self.Owner:IsPlayer() && ( self.Owner:KeyReleased( IN_ATTACK ) || !self.Owner:KeyDown( IN_ATTACK ) ) ) then
if ( self.LoopSound ) then self.LoopSound:ChangeVolume( 0, 0.1 ) end
if ( self.BeatSound ) then self.BeatSound:ChangeVolume( 1, 0.1 ) end
end
end
function SWEP:DoIdleAnimation()
self:SendWeaponAnim( ACT_VM_IDLE )
end
function SWEP:Idle()
self:SetNextIdle( CurTime() + self:GetAnimationTime() )
end
function SWEP:GetA
You can hook onto to player death, get the attacker's weapon class, if it's the weapon class of the weapon you want, set the attacker's health to 100.
[code]
hook.Add("PlayerDeath", "Example", function(victim, weapon, attacker) -- Weapon is the weapon used to kill the victim.
if weapon:GetClass() == "WEAPONS LUA CLASS FILE NAME HERE" then -- weapon_ttt_m16 would be an example, checking for the weapon class
attacker:SetHealth(100) -- Setting attacker health to 100.
end
end )
[/code]
I believe it would be something like that. Sorry for no indentation, TAB doesn't work for some reason.
Sorry, you need to Log In to post a reply to this thread.