• Comparing tables.
    2 replies, posted
[code]--Place weapon on body --Max Primaries Allowed local MaxPrimaries = 1 --Max SecondariesAllowed local MaxSecondaries = 2 --Current amount of primaries equipped local CurrentPrimaries = 0 --Current amount of secondaries equipped local CurrentSecondaries = 0 --Primaries that will be counted and drawn local AllowedPrimaries = {"weapon_mad_ak472", "ls_mad_sniper","weapon_mad_m42", "weapon_mad_mac102", "weapon_mad_mp52", "weapon_mad_pumpshotgun2", "weapons_pumpshotgun"}; --Secondaries that will be counted and drawn local AllowedSecondaries = {"weapon_fiveseven2", "weapon_mad_deagle2", "weapon_mad_glock2", "weapon_taser", "weapon_mad_deagle2", "weapon_mad_p2282"}; --Currently equipped primaries local EquipedPrimaries = {} --Currently equipped secondaries local EquipedSecondaries = {} --Uncounted items local NoCount = {"arrest_stick", "door_ram", "gmod_tool", "keys", "lockpick", "med_kit", "pocket", "stun_stick", "unarrest_stick", "weaponchecker", "weapon_physgun", "weapon_physcannon", "gmod_camera"} --Check Table function allows us to compared 2 or more tables. if CLIENT then local function BeginClientHook() local pl = LocalPlayer(); --Check Table function allows us to compared 2 or more tables. local function CheckTable(table1, table2) pl:PrintMessage(HUD_PRINTCONSOLE, "Function good ") for k,v in pairs (table1) do local CPrim = 0 local CSec = 0 pl:PrintMessage(HUD_PRINTCONSOLE, "First table") for wepk,wepv in pairs (table2) do pl:PrintMessage(HUD_PRINTCONSOLE, "Second table") if v == wepv then CPrim = CPrim + 1 end if CPrim == k then PrintMessage(HUD_PRINTCONSOLE, "worked") table.remove(v, k) end end end end --Check Primaries CheckTable(EquipedPrimaries, pl:GetWeapons()) CheckTable(EquipedSecondaries, pl:GetWeapons()) end hook.Add( "Think", "RunEveryFrame", BeginClientHook) end hook.Add( "InitPostEntity", "DefinePlayerPostEntity", BeginClientHook ) [/code]It's pretty basic I need to compare 2 tables, the problem is that the 'for statement' for the tables(table1, table2) don't work. However, "function good" does show up. So, I don't know what breaks. Please help?
You're gonna have to explain what you're trying to do.
I'm trying to check if a player removed a certain weapon, so I need to compare two tables(pl:GetWeapons, EquipedPrimaries). Problem is the for statement won't work.
Sorry, you need to Log In to post a reply to this thread.