When the gun runs out of ammo, it disappears? Can someone help me make it so it doesn't do that?
[CODE]-- Variables that are used on both client and server
SWEP.Category = ""
SWEP.Gun = ""
SWEP.Author = "Generic Default, Worshipper, Clavus, and Bob"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
SWEP.DrawCrosshair = true -- Hell no, crosshairs r 4 nubz!
SWEP.ViewModelFOV = 65 -- How big the gun will look
SWEP.ViewModelFlip = true -- True for CSS models, False for HL2 models
SWEP.Spawnable = false
SWEP.AdminSpawnable = false
SWEP.Primary.Sound = Sound("") -- Sound of the gun
SWEP.Primary.Round = ("") -- What kind of bullet?
SWEP.Primary.Cone = 0.2 -- Accuracy of NPCs
SWEP.Primary.Recoil = 10
SWEP.Primary.Damage = 10
SWEP.Primary.Spread = .01 --define from-the-hip accuracy (1 is terrible, .0001 is exact)
SWEP.Primary.NumShots = 1
SWEP.Primary.RPM = 0 -- This is in Rounds Per Minute
SWEP.Primary.ClipSize = 0 -- Size of a clip
SWEP.Primary.DefaultClip = 0 -- Default number of bullets in a clip
SWEP.Primary.KickUp = 0 -- Maximum up recoil (rise)
SWEP.Primary.KickDown = 0 -- Maximum down recoil (skeet)
SWEP.Primary.KickHorizontal = 0 -- Maximum side recoil (koolaid)
SWEP.Primary.Automatic = true -- Automatic/Semi Auto
SWEP.Primary.Ammo = "none" -- What kind of ammo
SWEP.Secondary.ClipSize = 0 -- Size of a clip
SWEP.Secondary.DefaultClip = 0 -- Default number of bullets in a clip
SWEP.Secondary.Automatic = false -- Automatic/Semi Auto
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.IronFOV = 0 -- How much you 'zoom' in. Less is more!
SWEP.Penetration = true
SWEP.Ricochet = true
SWEP.MaxRicochet = 1
SWEP.RicochetCoin = 1
SWEP.BoltAction = false
SWEP.Scoped = false
SWEP.ShellTime = .35
SWEP.Tracer = 0
SWEP.CanBeSilenced = false
SWEP.Silenced = false
SWEP.NextSilence = 0
SWEP.SelectiveFire = false
SWEP.NextFireSelect = 0
SWEP.IronSightsPos = Vector(0,0,0)
SWEP.IronSightsAng = Vector(0,0,0)
SWEP.SightsPos = Vector(0,0,0)
SWEP.SightsAng = Vector(0,0,0)
SWEP.RunSightsPos = Vector(0,0,0)
SWEP.RunSightsAng = Vector(0,0,0)
SWEP.VElements = {}
SWEP.WElements = {}
function SWEP:Initialize()
self.Reloadaftershoot = 0 -- Can't reload when firing
self:SetWeaponHoldType(self.HoldType)
self.Weapon:SetNetworkedBool("Reloading", false)
if SERVER and self.Owner:IsNPC() then
self:SetNPCMinBurst(3)
self:SetNPCMaxBurst(10) -- None of this really matters but you need it here anyway
self:SetNPCFireRate(1/(self.Primary.RPM/60))
self:SetCurrentWeaponProficiency( WEAPON_PROFICIENCY_VERY_GOOD )
end
if CLIENT then
-- // Create a new table for every weapon instance
self.VElements = table.FullCopy( self.VElements )
self.WElements = table.FullCopy( self.WElements )
self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
self:CreateModels(self.VElements) -- create viewmodels
self:CreateModels(self.WElements) -- create worldmodels
-- // init view model bone build function
if IsValid(self.Owner) and self.Owner:IsPlayer() then
if self.Owner:Alive() then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
-- // Init viewmodel visibility
if (self.ShowViewModel == nil or self.ShowViewModel) then
vm:SetColor(Color(255,255,255,255))
else
-- // however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing
vm:SetMaterial("Debug/hsv")
end
end
end
end
end
if CLIENT then
local oldpath = "vgui/hud/name" -- the path goes here
local newpath = string.gsub(oldpath, "name", self.Gun)
self.WepSelectIcon = surface.GetTextureID(newpath)
end
self.SightsPos = self.IronSightsPos
self.SightsAng = self.IronSightsAng
end
function SWEP:Deploy()
self:SetIronsights(false, self.Owner) -- Set the ironsight false
if self.Silenced then
self.Weapon:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
else
self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
end
self.Weapon:SetNetworkedBool("Reloading", false)
if !self.Owner:IsNPC() and self.Owner != nil then
if self.ResetSights and self.Owner:GetViewModel() != nil then
self.ResetSights = CurTime() + self.Owner:GetViewModel():SequenceDuration()
end
end
return true
end
function SWEP:Holster()
if CLIENT and IsValid(self.Owner) and not self.Owner:IsNPC() then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
end
end
return true
end
function SWEP:OnRemove()
if CLIENT and IsValid(self.Owner) and not self.Owner:IsNPC() then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
end
end
end
function SWEP:GetCapabilities()
return CAP_WEAPON_RANGE_ATTACK1, CAP_INNATE_RANGE_ATTACK1
end
function SWEP:Precache()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheModel(self.ViewModel)
util.PrecacheModel(self.WorldModel)
end
function SWEP:PrimaryAttack()
if self:CanPrimaryAttack() and self.Owner:IsPlayer() then
if !self.Owner:KeyDown(IN_SPEED) and !self.Owner:KeyDown(IN_RELOAD) then
self:ShootBulletInformation()
self.Weapon:TakePrimaryAmmo(1)
if self.Silenced then
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK_SILENCED )
self.Weapon:EmitSound(self.Primary.SilencedSound)
else
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:EmitSound(self.Primary.Sound)
end
local fx = EffectData()
fx:SetEntity(self.Weapon)
fx:SetOrigin(self.Owner:GetShootPos())
fx:SetNormal(self.Owner:GetAimVector())
fx:SetAttachment(self.MuzzleAttachment)
if GetConVar("M9KGasEffect") != nil then
if GetConVar("M9KGasEffect"):GetBool() then
util.Effect("m9k_rg_muzzle_rifle",fx)
end
end
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:MuzzleFlash()
self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
self:CheckWeaponsAndAmmo()
self.RicochetCoin = (math.random(1,4))
if self.BoltAction then self:BoltBack() end
end
elseif self:CanPrimaryAttack() and self.Owner:IsNPC() then
self:ShootBulletInformation()
self.Weapon:TakePrimaryAmmo(1)
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self.Weapon:EmitSound(self.Primary.Sound)
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:MuzzleFlash()
self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
self.RicochetCoin = (math.random(1,4))
end
end
function SWEP:CheckWeaponsAndAmmo()
if SERVER and self.Weapon != nil and (GetConVar("M9KWeaponStrip"):GetBool()) then
if self.Weapon:Clip1() == 0 && self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() ) == 0 then
timer.Simple(.1, function() if SERVER then if not IsValid(self) then return end
if self.Owner == nil then return end
self.Owner:StripWeapon(self.Gun)
end end)
end
end
end
/*---------------------------------------------------------
Name: SWEP:ShootBulletInformation()
Desc: This func add the damage, the recoil, the number of shots and the cone on the bullet.
---------------------------------------------------------*/
function SWEP:ShootBulletInformation()
local CurrentDamage
local CurrentRecoil
local CurrentCone
if (self:GetIronsights() == true) and self.Owner:KeyDown(IN_ATTACK2) then
CurrentCone = self.Primary.IronAccuracy
else
CurrentCone = self.Primary.Spread
end
local damagedice = math.Rand(.85,1.3)
CurrentDamage = self.Primary.Damage * damagedice
CurrentRecoil = self.Primary.Recoil
-- Player is aiming
if (self:GetIronsights() == true) and self.Owner:KeyDown(IN_ATTACK2) then
self:ShootBullet(CurrentDamage, CurrentRecoil / 6, self.Primary.NumShots, CurrentCone)
-- Player is not aiming
el
[code]
function SWEP:CheckWeaponsAndAmmo()
if SERVER and self.Weapon != nil and (GetConVar("M9KWeaponStrip"):GetBool()) then
if self.Weapon:Clip1() == 0 && self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() ) == 0 then
timer.Simple(.1, function() if SERVER then if not IsValid(self) then return end
if self.Owner == nil then return end
self.Owner:StripWeapon(self.Gun)
end end)
end
end
end
[/code]
Is the function you're looking for. Removing it could be one thing but if you look at line two there is a "M9KWeaponStrip" which is a console command, setting it to 0 will turn the auto-strip off(Which i recommend you to do).
Sorry, you need to Log In to post a reply to this thread.