Table/Single Pickup Help

Hi There im new to facepunch so please tell me if im doing something wrong but im trying to make a pickup that only lets you pickup 1 primary weapon and 1 secondary weapon but i think ive done it wrong, im not to sure on how to make it check the first entry of every record in the table because i think its only checking a certain record!

My Code:



AddCSLuaFile()

ENT.Base = "gms_base_entity"
ENT.PrintName = "AK12"

ENT.Model = "models/weapons/world/rifles/ak12.mdl"

if ( CLIENT ) then return end

PrimaryWeapons={} 
PrimaryWeapons[1]="fas2_m4a1" 
PrimaryWeapons[2]="fas2_sks" 
PrimaryWeapons[3]="fas2_ak12" 
PrimaryWeapons[4]="fas2_ak47" 
PrimaryWeapons[5]="fas2_an94" 
PrimaryWeapons[6]="fas2_ak74" 
PrimaryWeapons[7]="fas2_famas" 
PrimaryWeapons[8]="fas2_g36c" 
PrimaryWeapons[9]="fas2_g3" 
PrimaryWeapons[10]="fas2_galil" 
PrimaryWeapons[11]="fas2_uzi" 
PrimaryWeapons[12]="fas2_ks23" 
PrimaryWeapons[13]="fas2_mac11" 
PrimaryWeapons[14]="fas2_m14" 
PrimaryWeapons[15]="fas2_m21" 
PrimaryWeapons[16]="fas2_m24" 
PrimaryWeapons[17]="fas2_m3s90" 
PrimaryWeapons[18]="fas2_m82" 
PrimaryWeapons[19]="fas2_mp5a5" 
PrimaryWeapons[20]="fas2_mp5k" 
PrimaryWeapons[21]="fas2_mp5sd6" 
PrimaryWeapons[22]="fas2_pp19" 
PrimaryWeapons[23]="fas2_rem870" 
PrimaryWeapons[24]="fas2_rpk" 
PrimaryWeapons[25]="fas2_rk95" 
PrimaryWeapons[26]="fas2_sg550" 
PrimaryWeapons[27]="fas2_sg552" 
PrimaryWeapons[28]="fas2_sr25" 
PrimaryWeapons[29]="fas2_toz34" 

SecondaryWeapons={} 
SecondaryWeapons[1]="fas2_glock20" 
SecondaryWeapons[2]="fas2_deagle" 
SecondaryWeapons[3]="fas2_m1911"
SecondaryWeapons[4]="fas2_p226"
SecondaryWeapons[5]="fas2_ragingbull"

ToolPickups={} 
ToolPickups[1]="fas2_dv2"  
ToolPickups[2]="fas2_machete"

AmmoPickups={} 
AmmoPickups[1]="fas2_ammobox"

HealthPickups={} 
HealthPickups[1]="fas2_ifak"




function ENT:OnUse( ply )
if ply:HasWeapon( PrimaryWeapons[1] ) then
PrintMessage( HUD_PRINTTALK, "You Already Have A Primary Weapon!")
else
		ply:Give( "fas2_ak12" )
	self:Remove()
	end
end


it lets me pick it up fine and that (this is going with my custom gamemode) thanks for the help!



function ENT:Use( ply )
	for k, v in pairs( PrimaryWeapons ) do
		if ply:HasWeapon( v ) then
			ply:PrintMessage( HUD_PRINTTALK, "You Already Have A Primary Weapon!")
			return
		end
	end

	ply:Give( "fas2_ak12" )
	self:Remove()
end


  • OnUse doesn’t exist
  • You want to put these tables in the GAMEMODE table don’t just have global variables lying around like that
  • Figure out how to use loops