if (SERVER) then
AddCSLuaFile ("shared.lua");
end
if (CLIENT) then
SWEP.PrintName = "EXD2";
SWEP.Slot = 2;
SWEP.SlotPos = 4;
SWEP.DrawAmmo = true;
SWEP.DrawCrosshair = true;
end
SWEP.Author = "HeLLFox_15"
SWEP.Contact = "youremail@gmail.com"
SWEP.Purpose = "Blow peaple up."
SWEP.Instructions = "Primary to fire a bullet, Secondary to make an explosion where you are pointing"
SWEP.Category = "HeLLFox_15-SWEPS"
SWEP.Spawnable = false;
SWEP.AdminSpawnable = true;
SWEP.ViewModel = "models/weapons/v_357.mdl";
SWEP.WorldModel = "models/weapons/w_357.mdl";
SWEP.Weight = 5;
SWEP.AutoSwitchTo = false;
SWEP.AutoSwitchFrom = false;
SWEP.Primary.ClipSize = 8;
SWEP.Primary.DefaultClip = 20;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "357";
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = "none";
SWEP.Sound = Sound ("weapon_357.Single")
SWEP.Damage = 50
SWEP.Spread = 0.02
SWEP.NumBul = 1
SWEP.Delay = 0.6
SWEP.Force = 3
function SWEP:Deploy()
return true
end
function SWEP:Holster()
return true
end
function SWEP:Think()
end
function SWEP:SecondaryAttack() // when secondary attack happens
// Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
local eyetrace = self.Owner:GetEyeTrace();
// this gets where you are looking. The SWep is making an explosion where you are LOOKING, right?
self.Weapon:EmitSound ( self.Sound )
// this makes the sound, which I specified earlier in the code
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
//this makes the shooting animation for the 357
local explodea = ents.Create("env_ar2explosion")
explodea:SetPos( eyetrace.HitPos )
explodea:SetOwner( self.Owner )
explodea:Spawn()
explodea:SetKeyValue("iMagnitude","575")
explodea:Fire("Explode", 0, 0 )
explodea:EmitSound("weapon_AWP.Single", 400, 400 )
for _,trga in pairs( ents.FindInSphere(eyetrace.HitPos,258) ) do
if( trga:IsValid() ) then
constraint.RemoveAll(trga)
trga:PhysWake()
if( trga:IsPlayer() and trga ~= self.Owner ) then
if( ( trga:Health() - 50 ) <= 0 ) then
trga:Kill()
else
trga:SetHealth( trga:Health() - 50 )
end
end
trga:SetVelocity( ( trga:GetPos() - eyetrace.HitPos ) * 9000 )
local phys = trga:GetPhysicsObject()
local vecforceapl = ( trga:GetPos() - eyetrace.HitPos ) * ( 9000 * phys:GetMass() )
constraint.RemoveAll(trga)
phys:EnableMotion(true)
phys:ApplyForceCenter( vecforceapl )
phys:AddVelocity( vecforceapl )
end
end
self.Weapon:SetNextPrimaryFire( CurTime() + self.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Delay )
//this sets the delay for the next primary and secondary fires.
self:TakePrimaryAmmo(1) //removes 1 ammo from our clip
end //telling Gmod that it's the end of the function
function SWEP:PrimaryAttack() //when +attack1 happens
// Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {} //creates a table for the properties of the bullet
bullet.Num = self.NumBul //number of bullets you are shooting
bullet.Src = self.Owner:GetShootPos() // Source, where you are standing
bullet.Dir = self.Owner:GetAimVector() // direction of bullet, where you are looking
bullet.Spread = Vector( self.Spread, self.Spread, 0 ) // spread of bullet, how accurate it is
bullet.Tracer = 0 // this is the beam behind the bullet.
bullet.Force = 99999999 // how powerful it is
bullet.Damage = 99999999 //how much damage it does to people
bullet.AmmoType = self.Primary.Ammo //what type of ammo you are using
self.Owner:FireBullets( bullet ) //actually shoots the bullet.
self.Weapon:EmitSound ( self.Sound )
// this makes the sound, which I specified earlier in the code
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
//this makes the shooting animation for the 357
self.Weapon:SetNextPrimaryFire( CurTime() + self.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Delay )
//this sets the delay for the next primary and secondary fires.
self:TakePrimaryAmmo(1) //removes 1 ammo from our clip
end //end our function
function SWEP:Reload()
self.Weapon:DefaultReload( ACT_VM_RELOAD ) //animation for reloading
end
The first problem is that some times it makes props fly out of the map ( or breaks world entities ), and that creates this server crashing error...
"This does not give any errors into the console just crashes instantly"
The second one is this...
Can't find factory for entity: env_ar2explosion
[@weapons\weapon_exd2\shared.lua:72] Tried to use a NULL entity!
Can't find factory for entity: env_ar2explosion
[@weapons\weapon_exd2\shared.lua:72] Tried to use a NULL entity!
Can't find factory for entity: env_ar2explosion
[@weapons\weapon_exd2\shared.lua:72] Tried to use a NULL entity!
And the third is this...
L 07/27/2011 - 12:06:32: Log file started (file "logs\L0727002.log") (game "C:\srcds\orangebox\garrysmod") (version "4616")
L 07/27/2011 - 12:08:04: "HeLLFox_15<2><STEAM_0:1:20305110><>" connected, address "99.237.202.61:27005"
L 07/27/2011 - 12:08:04: "HeLLFox_15<2><STEAM_0:1:20305110><>" STEAM USERID validated
L 07/27/2011 - 12:08:05: server_cvar: "sv_tags" "alltalk,garrysmod125,gm:sandbox,gravhull,scriptenforcer,wiresvn2463"
L 07/27/2011 - 12:08:50: "HeLLFox_15<2><STEAM_0:1:20305110><>" entered the game
L 07/27/2011 - 12:10:09: Lua Error: [@addons\hellfox_15-sweps\lua\weapons\weapon_exd2\shared.lua:96] Tried to use invalid object (type IPhysicsObject) (Object was NULL or not of the right type)
L 07/27/2011 - 12:10:43: Log file closed
The weapon works and does what it is supposed to ( except the server crashing bit ), but I would like it to not crash servers and to give less or no errors.
Please and thank you.