So I'm trying to make a grenade launcher, but when I'm having 2 problems:
The main one is that the entity spawns under the earth/map.
The second one is that it won't reload.
Also how do I get the pipebomb to explode in 4 seconds, or on touch of a player?
Here's the shared of the SWEP (modified chair throw swep):
[lua]if (SERVER) then
AddCSLuaFile ("shared.lua");
SWEP.Weight = 8;
end
if (CLIENT) then
SWEP.PrintName = "A35 Grenade Launcer";
SWEP.Slot = 4;
SWEP.SlotPos = 3;
SWEP.DrawAmmo = true;
SWEP.DrawCrosshair = true;
end
SWEP.Author = "Dakarun";
SWEP.Contact = "None for you";
SWEP.Purpose = "Blow stuff up";
SWEP.Instructions = "Mouse 1: Shoot, Mouse 2: Ironsight";
SWEP.Primary.ClipSize = 6;
SWEP.Primary.DefaultClip = 24;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "SMG1_Grenade";
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = true;
SWEP.Secondary.Ammo = "none";
SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;
SWEP.ViewModel = "models/weapons/v_rpg.mdl";
SWEP.WorldModel = "models/weapons/w_gl35_xm1014.mdl";
local ShootSound = Sound ("NPC_Combine.GrenadeLaunch");
function SWEP:Initialize()
if ( SERVER ) then
self:SetWeaponHoldType(ar2)
end
end
function SWEP:launch_grenade(range)
if ( !self:CanPrimaryAttack() ) then return end
self.Weapon:EmitSound (ShootSound);
self.BaseClass.ShootEffects (self);
if (!SERVER) then return end;
local ent = ents.Create ("sent_pipebomb");
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 14));
ent:SetAngles (self.Owner:EyeAngles());
ent:SetOwner(self.Owner)
ent:Input("settimer",self.Owner,self.Owner,"4")
ent:Spawn();
local phys = ent:GetPhysicsObject();
phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * range);
self:TakePrimaryAmmo( 1 )
end
function SWEP:PrimaryAttack()
self:launch_grenade(1000);
self.Weapon:SetNextPrimaryFire( CurTime() + 0.9 )
self.Owner:ViewPunch( Angle( -5, 0, 0 ) )
end
function SWEP:SecondaryAttack()
end
function SWEP:Reload()
end[/lua]
Here is the Init:
[lua]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
function ENT:Initialize()
self.Entity:SetModel( "models/dakarun/pipebomb_teamblue.mdl" )
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Entity:SetColor(255, 255, 255, 255)
local obj = self.Entity:GetPhysicsObject()
/*if obj and phys:IsValid() then
obj:Wake()
obj:SetMass( 10 )
end*/
end
function ENT:PhysicsCollide( data, physobj)
local Radius = 10
local Damage = 20
local ent = ents.FindInSphere( self.Entity:GetPos(), Radius)
for k , v in pairs(ent) do
if v and v:IsValid() then
v:TakeDamage( Damage )
end
end
self.Entity:Remove()
end
function ENT:Explode()
local explode = ents.Create( "env_explosion" ) //creates the explosion
explode:SetPos( eyetrace.HitPos )
//this creates the explosion through your self.Owner:GetEyeTrace, which is why I put eyetrace in front
explode:SetOwner( self.Owner ) // this sets you as the person who made the explosion
explode:Spawn() //this actually spawns the explosion
explode:SetKeyValue( "iMagnitude", "220" ) //the magnitude
explode:Fire( "Explode", 0, 0 )
explode:EmitSound( "BaseGrenade.Explode", 400, 400 ) //the sound for the explosion, and how far away it can be heard
end
function ENT:Effect()
local vPoint = self.Entity:GetPos()
local effectdata = EffectData()
effectdata:SetStart( vPoint )
effectdata:SetEnd( vPoint )
effectdata:SetScale( 1 )
util.Effect( "trails/laser", effectdata )
end
[/lua]
The cl_init:
[lua]function ENT:Draw()
self.Entity:DrawModel( ture )
end[/lua]
Here is the entitys shared:
[lua]ENT.Type = "anim"
ENT.PrintName = "Pipebomb"
ENT.Author = "Dakarun"
ENT.Spawnable = false
ENT.AdminSpawnable = false[/lua]
explode:SetPos( self.GetPos )
is missing from init
Thanks, but it still spawns under ground.
Sorry, you need to Log In to post a reply to this thread.