• Making SWEP's and Adding Them To Gamemode
    6 replies, posted
Hello guys, I am having trouble getting my custom SWEP's into my custom gamemode. In my SWEP s folder ('entities/weapons/m4a1/') I have a shared.lua that contains all of my SWEP's information. Now, when calling the SWEP from my 'players.lua' file located directly in my gamemode's 'gamemode' folder, it comes out with the error 'NULL Ent in GiveNamedItem!', and the SWEP's 'shared.lua' comes out with the error 'attempt to index global 'SWEP' (a nil value).' How would I fix this? Thanks! //players.lua local ply = FindMetaTable( "Player" ) include ("entities/weapons/m4a1/shared.lua") function ply:SetPlayerTeam ( n ) if (n == 'TEAM_SWAT') then self:SetPlayerColor( Vector( 0, 0, 1 ) ) self:SetModel("models/player/police.mdl") self:SetRunSpeed( 250 ) self:SetWalkSpeed( 175 ) self:SetJumpPower( 200 ) self:Give("m4a1") self:SetupHands() end if (n == 'TEAM_TERR') then self:SetPlayerColor(Vector(1, 0, 0)) self:SetModel("models/player/police.mdl") self:SetRunSpeed( 275 ) self:SetWalkSpeed( 180 ) self:SetJumpPower( 200 ) self:SetupHands() end end --shared.lua <-- located at entities/weapons/m4a1/ SWEP.Author = "Ratchet" SWEP.Contact = "N/A" SWEP.Purpose = "Used in 'SWAT' gamemode." SWEP.Instructions = "LeftMouse = Primary Fire" SWEP.Category = "Weapons" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = Model("v_rif_m4a1.mdl") SWEP.WorldModel = Model("w_rif_m4a1.mdl") SWEP.HoldType = "crossbow" SWEP.Primary.ClipSize = 36 SWEP.Primary.DefaultClip = 36 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "SMG1" local ShootSound = Sound( "Metal.SawbladeStick" ) if (!SERVER) then          AddCSLuaFile ("shared.lua")          SWEP.Weight = 5          SWEP.AutoSwitchTo = false     SWEP.AutoSwitchFrom = false elseif (!CLIENT) then          SWEP.PrintName = "SWAT M4A1"          SWEP.Slot = 4     SWEP.SlotPos = 1     SWEP.DrawAmmo = true     SWEP.DrawCrosshair = false end function SWEP:PrimaryAttack()     self:EmitSound( ShootSound ) end function SWEP:Initialize() self:SetHoldType(self.HoldType) end
Rename entities/weapons/m4a1/shared.lua to entities/weapons/m4a1.lua and remove include ("entities/weapons/m4a1/shared.lua")
I still only receive the 'NULL Ent in GiveNamedItem!' error.
Do you not need AddCSLuaFile()?
Removing that didn't fix my problem. I still get the 'NULL Ent in GiveNamedItem!' error.
No. I mean add AddCSLuaFile() to the top of your SWEP page. Exactly how I typed it. Pretty sure that will fix it/might fix it as I have that on my SWEPS.
Just tried that. Still have the same problem occurring.
Sorry, you need to Log In to post a reply to this thread.