• Please help with my SWEP
    2 replies, posted
My swep can't boot in garry's mod. Here is the error : [CODE][ERROR] addons/ammo giver/lua/autorun/ammo_giver.lua:1: attempt to index global 'SWEP' (a nil value) 1. unknown - addons/ammo giver/lua/autorun/ammo_giver.lua:1 [/CODE] Here is the code: [CODE]SWEP.PrintName = "Ammo giver" SWEP.Author = "PLYSHKA" SWEP.Instructions = "Giving ammo" SWEP.HoldType = "pistol" SWEP.Category = "AmmoGivers" SWEP.Spawnable = true SWEP.AdminOnly = false SWEP.UseHands = true SWEP.ViewModel = "models/weapons/c_crossbow.mdl" SWEP.WorldModel = "models/weapons/w_crossbow.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Slot = 0 SWEP.SlotPos = 2 SWEP.DrawAmmo = false /*--------------------------------------------------------- PrimaryAttack 1 ---------------------------------------------------------*/ function SWEP:PrimaryAttack() self:SetNextPrimaryFire( CurTime() + 0.1 ) self:ShootEffects( self ) if (!SERVER) then return end local Forward = self.Owner:EyeAngles():Forward() local ent1 = ents.Create( "ai_weapon_pistol" ) local ent2 = ents.Create( "ai_weapon_357" ) local ent3 = ents.Create( "ai_weapon_crossbow" ) local ent4 = ents.Create( "ai_weapon_rpg" ) local ent5 = ents.Create( "ai_weapon_ar2" ) local ent6 = ents.Create( "ai_weapon_smg1" ) local ent7 = ents.Create( "ai_weapon_shotgun" ) if ( IsValid(ent1,ent2,ent3,ent4,ent5,ent6,ent7) ) then ent1:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent1:SetAngles( self.Owner:EyeAngles() ) ent1:Spawn() ent1:SetVelocity( Forward * 2000 ) ent1:SetOwner( self.Owner ) ent2:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent2:SetAngles( self.Owner:EyeAngles() ) ent2:Spawn() ent2:SetVelocity( Forward * 2000 ) ent2:SetOwner( self.Owner ) ent3:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent3:SetAngles( self.Owner:EyeAngles() ) ent3:Spawn() ent3:SetVelocity( Forward * 2000 ) ent3:SetOwner( self.Owner ) ent4:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent4:SetAngles( self.Owner:EyeAngles() ) ent4:Spawn() ent4:SetVelocity( Forward * 2000 ) ent4:SetOwner( self.Owner ) ent5:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent5:SetAngles( self.Owner:EyeAngles() ) ent5:Spawn() ent5:SetVelocity( Forward * 2000 ) ent5:SetOwner( self.Owner ) ent6:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent6:SetAngles( self.Owner:EyeAngles() ) ent6:Spawn() ent6:SetVelocity( Forward * 2000 ) ent6:SetOwner( self.Owner ) ent7:SetPos( self.Owner:GetShootPos() + Forward * 100 ) ent7:SetAngles( self.Owner:EyeAngles() ) ent7:Spawn() ent7:SetVelocity( Forward * 2000 ) ent7:SetOwner( self.Owner ) end end /*--------------------------------------------------------- SecondaryAttack ---------------------------------------------------------*/ function SWEP:SecondaryAttack() -- Right click does nothing.. end /*--------------------------------------------------------- Name: ShouldDropOnDie ---------------------------------------------------------*/ function SWEP:ShouldDropOnDie() return false end[/CODE]
It doesn't go in lua/autorun, it goes in lua/weapons. Also, you know there are commands to just [URL="http://wiki.garrysmod.com/page/Player/GiveAmmo"]give the player the ammo[/URL] rather than spawning ammo with a velocity that should get it onto them?
Thank you very much! This is helped. The problem is solved.
Sorry, you need to Log In to post a reply to this thread.