C4/bomb

Im just wondering if there is a c4 or bomb SWEP that will plant a bomb after like 10 or 15 sec and the timer is 60 or more i dont want the one where you type in the numbers and drop it i want it so it says planting bomb or c4 and it plants on walls, the ground or other peoples props if anyone has one that would be great

This board is for helping with development, so you’ll need to build it primarily on your own. You could try and subscribe an existing C4 addon on your server, find it’s classname - and use it that way.

Something like this, http://steamcommunity.com/sharedfiles/filedetails/?id=125963951 :?

@Edit: Forget what I said. How come there is not a single C4 SWEP on workshop :v:?

Thats why I’m asking because there isn’t any on the workshop is there anyway that one can be made

Look at TTT, figure out how it’s coded and make your own.

Here’s an explosion helper function which runs the function over and over again to allow for magnitudes higher than 100 ( As told by Valve Developer Wiki to do in the event you want LARGE kick-back ).

Note: This doesn’t create much of an effect for blast radius. You should look into creating effects, or you could use “env_ar2explosion” which creates a dust-cloud. It’s used the same way as below without the magnitude. You could find the likenesses in the Valve Developer Wiki and split the below function up in order to create explosions but only use one in the loop. Spores act differently, if you want a demo on that let me know.
[lua]//
// CreateExplosion - with proper magnitude dispersement, damage, etc… - Josh ‘Acecool’ Moser
//
function CreateExplosion( _pos, _magnitude, _radius, _damage, _inflictorWeapon, _inflictorPlayer )
// Generate the damage from the explosion.
util.BlastDamage( _inflictorWeapon or game.GetWorld( ), _inflictorPlayer or game.GetWorld( ), _pos, _radius or _magnitude, _damage or 0 )

// Ensure that the entire magnitude is dispensed in 100 increments/intervals. 100 is the max, but they do stack.
local _times = math.ceil( _magnitude / 100 );	
for i = 0, _times - 1 do
	local _mag = ( _magnitude - ( i * 100 ) )

	// Generate the explosion / force of the explosion.
	local explosion = CreateEntity( "env_explosion" )
	
	// No damage just force, push players, disorient players if pushed
	explosion:SetKeyValue( "spawnflags", 1 + 2 + 16 );

	// Mag is clamped from 1 to 100 anyway
	explosion:SetKeyValue( "iMagnitude", math.Clamp( _mag, 1, 100 ) );

	// Radius or magnitude
	explosion:SetKeyValue( "iRadiusOverride", _radius or _magnitude );

	explosion:SetPos( _pos );
	explosion:Spawn( );

	// Touch-Off
	explosion:Fire( "Explode", "", 0 );

	// Remove it from the world
	explosion:Fire( "Kill", "", 0 );
end

end[/lua]

ya can you give me a demo please you confused me so much

[editline]27th December 2013[/editline]

Also can that work for my molotov

Definitely.

Server-side it would need to be called. So, in the SWEP when you plant the ENTITY, the entity would count down. At the end of the count-down, the entity would explode and remove itself.

It would use: CreateExplosion( _pos, _magnitude, _radius, _damage, _inflictorWeapon, _inflictorPlayer )

[lua]
_pos is the Vector position where the blast should occur.
_magnitude is how much force the explosion happens with. 100 pushes a little, 20000 can move vehicles, etc…
_radius this is how large around the entire damaging aspect and magnitude aspect of the blast effect should be
_damage is the amount of damage caused at the exact position of the center of the blast, it drops off exponentially moving towards the edge of the radius. It sometimes exceeds past, sometimes it does not. Balance these.
_inflictorWeapon is the ENTITY which caused the blast.
_inflictorPlayer is the PLAYER who planted the bomb.
CreateExplosion( _pos, _magnitude, _radius, _damage, _inflictorWeapon, _inflictorPlayer )[/lua]

An example of usage:
SWEP, code from FLECHETTE gun:
[lua]/---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------
/
function SWEP:PrimaryAttack()

self.Weapon:SetNextPrimaryFire( CurTime() + 0.1 )

self:EmitSound( ShootSound )
self:ShootEffects( self )

-- The rest is only done on the server
if (!SERVER) then return end

local Forward = self.Owner:EyeAngles():Forward()

// THIS is what you need to do, except instead of hunter_flechette, it needs to be your C4.
// In addition to spawning it, you should set the owner so the player gets credit for the kills.
local ent = ents.Create( "hunter_flechette" )
if ( IsValid( ent ) ) then

		ent:SetPos( self.Owner:GetShootPos() + Forward * 32 )
		ent:SetAngles( self.Owner:EyeAngles() )
	ent:Spawn()
	ent:SetOwner( self.Owner ); // Set the owner so credit for kills is given.
	ent:SetVelocity( Forward * 2000 )
	
end

ent:SetOwner( self.Owner )

end[/lua]

ENT:
[lua]function ENT:Initialize()
self:SetModel( “models/Zombie/Classic.mdl” ) // Should be the c4 model
timer.Simple( 3, function( )
if ( IsValid( self ) ) then
// _pos = Position the entity is currently positioned
// _magnitude = 28000 which should rock some cars if nearby, and fling stuff around
// _radius = 600 - not too large, not too small. Play with this.
// _damage = 1500 - IT’s a BOMB
// _inflictorWeapon = self, self points to the entire ENT record, meaning the entity itself
// _inflictorPlayer = self.Owner - this is a reference to the player we set after we spawned the bomb
CreateExplosion( self:GetPos( ), 28000, 600, 1500, self, self.Owner );
self:Remove( );
end
end );
end

function ENT:SetOwner( owner )
self.Owner = owner
end[/lua]

Please keep in mind that this is VERY LIMITED code for the example. I simply threw in the PrimaryAttack function from the Flechette gun located in your garrys mod lua / weapons directory.

This gives you an example of how to use a SWEP to spawn an entity.

The ENT code shows how to start a timer, and at the end of the timer explode and then remove itself IF the entity still exists. If it didn’t exist, an error would show up trying to remove NULL entity. We wouldn’t want an explosion if it was defused either; you write all of that code. SetOwner was a simple function added so that self.Owner would be set within the entity code ensuring the player that planted the bomb got full credit for the kills.

Let me know if this helps, I am expanding lesson plans as I go and this wasn’t on the list at all aside from providing a helper function. If you’re still confused, I’d be willing to create a simple base weapon which spawns a simple c4 model which uses this function. Let me know.

And yes, it could work for a molotov in terms of an “explosion” but not for fire, spreading fire, etc. I’d recommend using something different for that.

Can you create a simple base weapon that spawn a simple c4 model for me so i can test out this and see if this is what. I think that I am getting what you are saying. Im a noob when it comes to SWEPs.