• Code For TTT weapon help
    5 replies, posted
This is a custom weapon I made but it isn't using up its ammo when fired so it has infinite shots. It's really op. if (SERVER) then AddCSLuaFile( "shared.lua" ) SWEP.Weight= 1 SWEP.AutoSwitchTo= true SWEP.AutoSwitchFrom= true end if ( CLIENT ) then SWEP.PrintName = "Headcrab Canister Launcher" SWEP.Slot = 6 SWEP.SlotPos = 1 SWEP.DrawAmmo= ture SWEP.DrawCrosshair= true end SWEP.Author = "Roachdaripper" SWEP.Contact= "roachdaripper1@gmail.com" SWEP.Purpose = "Roleplay" SWEP.Instructions = "Left click to launch a headcrab canister at your target." SWEP.Category = "Toybox Sweps" SWEP.Kind = WEAPON_PISTOL SWEP.Spawnable= false SWEP.AdminSpawnable= true SWEP.ViewModel = "models/weapons/v_357.mdl" SWEP.WorldModel = "models/weapons/w_357.mdl" SWEP.ViewModelFlip = false SWEP.Primary.ClipSize = 1 SWEP.Primary.DefaultClip = 1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = 1 SWEP.Secondary.DefaultClip = 1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.CanBuy = {ROLE_TRAITOR} SWEP.LimitedStock = true local ShootSoundFire = Sound( "Airboat.FireGunHeavy" ) local ShootSoundFail = Sound( "WallHealth.Deny" ) local YawIncrement = 20 local PitchIncrement = 10 if CLIENT then language.Add ("Undone_CrabLaunch", "Undone Headcrab Canister.") end function SWEP:PrimaryAttack(bSecondary) local tr = self.Owner:GetEyeTrace() self:ShootEffects(self) if (SERVER) then local aBaseAngle = tr.HitNormal:Angle() local aBasePos = tr.HitPos local bScanning = true local iPitch = 10 local iYaw = -180 local iLoopLimit = 0 local iProcessedTotal = 0 local tValidHits = {} while (bScanning == true && iLoopLimit < 500) do iYaw = iYaw + YawIncrement iProcessedTotal = iProcessedTotal + 1 if (iYaw >= 180) then iYaw = -180 iPitch = iPitch - PitchIncrement end local tLoop = util.QuickTrace( aBasePos, (aBaseAngle+Angle(iPitch,iYaw,0)):Forward()*40000 ) if (tLoop.HitSky || bSecondary) then table.insert(tValidHits,tLoop) end if (iPitch <= -80) then bScanning = false end iLoopLimit = iLoopLimit + 1 end local iHits = table.Count(tValidHits) if (iHits > 0) then local iRand = math.random(1,iHits) local tRand = tValidHits[iRand] local ent = ents.Create( "env_headcrabcanister" ) ent:SetPos( aBasePos ) ent:SetAngles( (tRand.HitPos-tRand.StartPos):Angle() ) ent:SetKeyValue( "HeadcrabType", math.random(0,2) ) ent:SetKeyValue( "HeadcrabCount", math.random(2,5) ) ent:SetKeyValue( "FlightSpeed", math.random(2500,6000) ) ent:SetKeyValue( "FlightTime", math.random(2,5) ) ent:SetKeyValue( "Damage", math.random(50,90) ) ent:SetKeyValue( "DamageRadius", math.random(300,512) ) ent:SetKeyValue( "SmokeLifetime", math.random(5,10) ) ent:SetKeyValue( "StartingHeight", 1000 ) local iSpawnFlags = 8192 if (bSecondary) then iSpawnFlags = iSpawnFlags + 4096 end //If Secondary, spawn impacted. ent:SetKeyValue( "spawnflags", iSpawnFlags ) ent:Spawn() ent:Input("FireCanister", self.Owner, self.Owner) undo.Create("CrabLaunch") undo.AddEntity( ent ) undo.SetPlayer( self.Owner ) undo.AddFunction(function(undo) for k, v in pairs(ents.FindByClass("npc_headcrab*"))do if (v:GetOwner() == ent) then v:Remove() end end end) undo.Finish() self:EmitSound( ShootSoundFire ) else self:EmitSound( ShootSoundFail ) end tLoop = nil tValidHits = nil end end function SWEP:SecondaryAttack() self:PrimaryAttack(true) end function SWEP:ShouldDropOnDie() return true end
You aren't subtracting ammo anywhere in your PrimaryAttack function.
Could you write a line of code? I have no idea how to do that
[url]http://wiki.garrysmod.com/page/Weapon/SetClip1[/url]
It should subtract ammo automatically shouldn't it? Try setting primary ammo to AirboatGun
[CODE]SWEP.DrawAmmo= ture[/CODE] Might wanna fix that.
Sorry, you need to Log In to post a reply to this thread.