• I Have A Swep
    7 replies, posted
So I have a swep that fires a prop, but I need to it to recognize when there is no more ammo left to shoot. How would I do that? It keeps shooting even when the ammo says there is no ammo left in it.
[lua] function SWEP:CanPrimaryFire() return self:Clip1() > 0 end [/lua]
-snip- ninja'd
Any Ideas on how to make it reload without me having to throw it on the ground? [editline]8th August 2014[/editline] Also, that other code did not work [editline]8th August 2014[/editline] AddCSLuaFile() -- Swep information SWEP.PrintName = "Melon launcher" SWEP.Author = "Skatehawk11" SWEP.Instructions = "Left click to fire a explosive melon!" SWEP.Purpose = "defeat the enemy with your explosive melons!" SWEP.Category = "Skates SWEPS" -- Who can spawn it? SWEP.Spawnable = false SWEP.AdminOnly = false -- Clip SWEP.Primary.ClipSize = 10 SWEP.Primary.DefaultClip = 10 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Primary.Recoil = 1.5 -- Misc info SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Slot = 6 SWEP.SlotPos = 2 SWEP.DrawAmmo = true SWEP.DrawCrosshair = true SWEP.ViewModel = "models/weapons/v_rpg.mdl" SWEP.WorldModel = "models/weapons/w_rocket_launcher.mdl" local ShootSound = Sound("weapons/grenade_launcher1.wav") -- TTT Information SWEP.EquipMenuData = { type = "item_weapon", desc = [[ 1 shot explosive melon launcher to destoy the innocents. ]] } SWEP.Icon = "melon/ttt_icon.png" SWEP.Kind = WEAPON_EQUIP2 SWEP.CanBuy = { ROLE_TRAITOR } SWEP.LimitedStock = true if ( GAMEMODE.Name == "Trouble in Terrorist Town" ) then SWEP.Primary.Damage = 2000 SWEP.Primary.ClipSize = 10 SWEP.Primary.DefaultClip = 10 SWEP.Primary.ClipMax = 10 SWEP.Slot = 6 end function SWEP:IsEquipment() return false end function SWEP:CanPrimaryFire() return self:Clip1() > 0 end function SWEP:PrimaryAttack() self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Weapon:SetNextPrimaryFire( CurTime() + 9999999999999999999 ) if ( SERVER ) then self:EmitSound(ShootSound) local ang = self.Owner:EyeAngles() local ent = ents.Create( "ent_explosive_melon" ) self:TakePrimaryAmmo(1) if ( IsValid( ent ) ) then ent:SetPos( self.Owner:GetShootPos() + ang:Forward() * 50 + ang:Right() * 1 - ang:Up() * 1 ) ent:SetAngles( ang ) ent:SetOwner( self.Owner ) ent:Spawn() ent:Activate() end end end function SWEP:SecondaryAttack() // Nothing will happen end
DefaultClip gives you ammo when you pick it back up. To "Reload" you just call DefaultReload ( if you use the default system of ammo, etc ). If you're using a custom system, you need to set the ammo in the mag you're using, or swap the mag for a new one ( depending how you have it coded )... MOST sweps just use the Default system though.
Where would I call for the Default Reload?
weapon_base calls it right in Reload [code]--[[--------------------------------------------------------- Name: SWEP:Reload( ) Desc: Reload is being pressed -----------------------------------------------------------]] function SWEP:Reload() self.Weapon:DefaultReload( ACT_VM_RELOAD ); end[/code] If you're using the default functions such as TakePrimaryAmmo, TakeSecondaryAmmo, etc etc for each time you shoot, and you use the default ammo system, you should have no issue calling the DefaultReload. self.Weapon is deprecated, it is just self: now.
Thanks for the help Ace, I havent tested it out yet but I just want to thank you for taking the time to help scriptkiddies with their sweps and stuff :)
Sorry, you need to Log In to post a reply to this thread.