Hi all, I'm trying to learn how to create a particle effect when a player attacks. I'm trying to create a revive tool, and I want there to be a laser that comes out from the weapon while the player is holding left click to revive.
Anyway, here's my code.
[lua]
// Precache particle effects
game.AddParticles("particles/vortigaunt_fx.pcf")
PrecacheParticleSystem("vortigaunt_beam_charge")
SWEP.Category = "Hue's Weapons"
SWEP.Author = "HueBear"
SWEP.Purpose = "Revive players."
SWEP.Instructions = [[
Hold left-click to revive
Hold right-click to self-heal
]]
// SWEP structure (found at http://wiki.garrysmod.com/page/Structures/SWEP) \\
SWEP.PrintName = "Revive Me!"
SWEP.Slot = 5
SWEP.SlotPos = 0
// Rendering info \\
SWEP.DrawAmmo = true
SWEP.DrawCrosshair = true
SWEP.Weight = 30
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = false
// HoldType of weapon (see http://wiki.garrysmod.com/page/Hold_Types) \\
SWEP.HoldType = "crossbow"
// View/World Model
SWEP.ViewModelFOV = 60
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/v_crossbow.mdl"
SWEP.WorldModel = "models/weapons/w_crossbow.mdl"
// Base / spawning information \\
SWEP.Base = "weapon_base"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
// SWEP primary structure \\
SWEP.Primary.Ammo = "Pistol"
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 2
SWEP.Primary.Automatic = true
SWEP.Primary.Sound = "ambient/energy/electric_loop.wav"
// Bullet information \\
SWEP.Primary.NumShots = 1
SWEP.Primary.Damage = 0
SWEP.Primary.Spread = .025
SWEP.Primary.Delay = .25
SWEP.Primary.Recoil = 10
SWEP.Primary.Effect = "vortigaunt_beam_charge"
// SWEP:Initialize \\
function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
self:SetWeaponHoldType( self.HoldType )
end
function SWEP:PrimaryAttack()
// Make sure the player can attack1 \\
if (!self:CanPrimaryAttack()) then return end
// Play the ressing-laser sound \\
if (self.PlaySound) then
self.PlaySound:ChangeVolume( 1, 0.1 )
else
self.PlaySound = CreateSound(self.Owner, self.Primary.Sound)
if (self.PlaySound) then self.PlaySound:Play() end
end
// Projects the bullet and decides the recoil / bullet spread \\
local bullet = {}
bullet.Num = self.Primary.NumShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(self.Primary.Spread * 0.1, self.Primary.Spread * 0.1, 0)
bullet.Tracer = 0
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
--self.Owner:FireBullets(bullet)
-- self:TakePrimaryAmmo(self.Primary.NumShots)
self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
ParticleEffectAttach(self.Primary.Effect, PATTACH_CUSTOMORIGIN, self, 0)
end
// Stop all sounds (keeps from looping infinitely)
function SWEP:KillSounds()
if (self.PlaySound) then
self.PlaySound:Stop()
self.PlaySound = nil
end
end
function SWEP:OnRemove()
self:KillSounds()
end
function SWEP:OnDrop()
self:KillSounds()
end
// Turn the volume to 0 when the player releases attack1. \\
function SWEP:Think()
if (self.Owner:IsPlayer() && self.Owner:KeyReleased(IN_ATTACK)) then
if (self.PlaySound) then self.PlaySound:ChangeVolume (0, 0.1) end
end
end
[/lua]
As you can see, I have no idea what I'm doing
Sorry, you need to Log In to post a reply to this thread.