TTT Choosing a View/World model on each order

I am working on a Traitor gun that spawns you with a random gun each time its ordered. The view and world models need to be the exact same and also declared after the purchase of the gun to ensure they are random. My issue is that they are not paired together properly as sometimes I will get a AK47 view model but a Mac10 world model. I dont get any lua errors or anything, just incorrect world and view models. So if you guys could help me get this to choose the correct and corresponding world and view models on item purchase, I would be grateful.



SWEP.UseHands			= true
SWEP.ViewModelFlip		= false
SWEP.ViewModelFOV		= 64

SWEP.Primary.Sound = Sound( "Weapon_M4A1.Single" )

SWEP.IronSightsPos = Vector(-7.58, -9.2, 0.55)
SWEP.IronSightsAng = Vector(2.599, -1.3, -3.6)

-- Tables with the gun types
viewm = {
"models/weapons/v_rif_ak47.mdl", "models/weapons/cstrike/c_pist_glock18.mdl", "models/weapons/cstrike/c_rif_m4a1.mdl",
"models/weapons/cstrike/c_smg_mac10.mdl", "models/weapons/cstrike/c_pist_fiveseven.mdl", "models/weapons/cstrike/c_pist_deagle.mdl",
"models/weapons/cstrike/c_snip_scout.mdl", "models/weapons/cstrike/c_shot_xm1014.mdl", "models/weapons/cstrike/c_mach_m249para.mdl"
}
worldm = {
"models/weapons/w_rif_ak47.mdl", "models/weapons/w_pist_glock18.mdl", "models/weapons/w_rif_m4a1.mdl",
"models/weapons/w_smg_mac10.mdl", "models/weapons/w_pist_fiveseven.mdl", "models/weapons/w_pist_deagle.mdl",
"models/weapons/w_snip_scout.mdl", "models/weapons/w_shot_xm1014.mdl", "models/weapons/w_mach_m249para.mdl"
}

-- Simple error message
if #viewm ~= #worldm then
PrintMessage( HUD_PRINTCHAT, "WARNING: TTT Trapped Gun does not have equal world and view model tables!!!")
end

-- Randomizes on order.
hook.Add("TTTOrderedEquipment", "RandomizeWeapon", function(ply, equipment, is_item)
itemnum = math.random( #viewm )
view = viewm[itemnum]
world = worldm[itemnum]
print("View model is " .. view)
print("World model is " .. world)


end)

SWEP.ViewModel			= view
SWEP.WorldModel			= world


You could do something like
if viewm == “models/weapons/v_rif_ak47.mdl” then worldm = “models/weapons/w_rif_ak47.mdl”

And you would only make it randomly pick from viewm.

If its just changing the model but not the functionality ( if functionality then do differently ):

something like this could simplify things:
[lua]local _weapons = {
{ view = “models/weapons/v_rif_ak47.mdl”, world = “models/weapons/w_rif_ak47.mdl” };
{ view = “models/weapons/cstrike/c_pist_glock18.mdl”, world = “models/weapons/w_pist_glock18.mdl” };
{ view = “models/weapons/cstrike/c_rif_m4a1.mdl”, world = “models/weapons/w_rif_m4a1.mdl” };

// ... ETC

};

local _models = table.Random( _weapons );
local _vm = _models.view;
local _wm = _models.world;[/lua]

Thanks but my issue is that it takes the correct world and virw models, I have it print the names to console so I know that works. My issue is that I seem to be declaring the view and world models of the SWEP not early enough so it just chooses random models. I need a reliable way to randomize my table and have the SWEP use the models that were chosen.

Example:
Ply buys the gun, console says that the world/view models should be a 57. But the actual world:/view model is for the AK