Help with explosions?

I feel I’m dangerously close to creating my first custom TTT wep but I’m hung up on getting the explosion to do damage. The purpose of the weapon is to act like a remote-activated C4. The player can spawn the prop into the world (which right now looks like a glowstick) and after 10 seconds, he can right click to detonate it. The blast isn’t meant to go through walls like typical C4, but if any of you have played with the melon mine or tripwire, I want the blast to be similar to that.

Can anyone give advise on how to make env_explosion do damage? I looked on valve’s website and it says there’s a bug that causes it not to do damage if it is parented (which I assume it is)

Here’s the code, most of it just modified from the example given by badking.



if SERVER then
   AddCSLuaFile( "shared.lua" )
end

if CLIENT then
   SWEP.PrintName = "Remote C4"
   SWEP.Slot      = 6 -- add 1 to get the slot number key

   SWEP.ViewModelFOV  = 72
   SWEP.ViewModelFlip = true
end

-- Always derive from weapon_tttbase.
SWEP.Base				= "weapon_tttbase"

--- Standard GMod values

SWEP.HoldType			= "Grenade"
SWEP.FiresUnderwater= true
SWEP.DrawCrosshair = false
SWEP.DrawAmmo = false

SWEP.Author = "Blurrred"
SWEP.Purpose = "A remote explosion."
SWEP.Instructions = "Left-click to plant the bomb, wait at least 10 seconds, right click to detonate."


SWEP.Primary.Delay       = 0.08
SWEP.Primary.Recoil      = 0
SWEP.Primary.Automatic   = false
SWEP.Primary.Damage      = 100
SWEP.Primary.Cone        = 0
SWEP.Primary.Ammo        = "none"
SWEP.Primary.ClipSize    = 1
SWEP.Primary.ClipMax     = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Sound       = Sound("BaseExplosionEffect.Sound" )


SWEP.ViewModel  = "models/weapons/v_c4.mdl"
SWEP.WorldModel = "models/weapons/w_c4.mdl"

local PlantSound = Sound("Grenade.Blip")

function SWEP:plant_bomb(model_file)
	local tr = self.Owner:GetEyeTrace()
	self:EmitSound(PlantSound)
	self.BaseClass.ShootEffects(self)
	
	if(!SERVER) then return end

	local ent = ents.Create("prop_physics")
	ent:SetModel(model_file)

	bomb = ent

	ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
	ent:SetAngles(self.Owner:EyeAngles())
	ent:Spawn()
	
	local phys = ent:GetPhysicsObject()

	if !(phys && IsValid(phys)) then ent:Remove() return end

	phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() *  math.pow(tr.HitPos:Length(), 1))
	
	cleanup.Add(self.Owner, "props", ent)
 
	undo.Create ("Thrown_SWEP_Entity")
		undo.AddEntity (ent)
		undo.SetPlayer (self.Owner)
	undo.Finish()

end

function SWEP:PrimaryAttack()
	if ( !self:CanPrimaryAttack() ) then return end
	
	self:plant_bomb("downloads/models/glowstick/stick.mdl")
	self:TakePrimaryAmmo(1)

	canExplode = 1
	self:SetNextSecondaryFire( CurTime() + 10 )
end

function SWEP:SecondaryAttack(ent)
	if(canExplode == 1) then
	ent = bomb
	local explode = ents.Create("env_explosion")
	explode:SetPos(ent:GetLocalPos())
	explode:SetOwner(self.Owner)
	explode:Spawn()
	explode:SetKeyValue("iMagnitude", "2200")
	explode:Fire("Explode", 0, 0)
	explode:EmitSound("BaseExplosionEffect.Sound", 400, 400)
	bomb:Remove()
	canExplode = 0
	else
	print("No bomb in world")
	end

end


In addition, although not an immediate concern, I’d like to get the prop that spawns to stick to a wall and only spawn if there’s a wall/surface to stick to. If anyone could help me with either of these I would be greatly appreciative.

Oh, crap, my eyes.
Use [lua] or


 tags

My mistake, new here