Switch to better weapon

Im trying to make it so when the player has a knife for example and he picks up a pistol it will switch to that ( like in counter stirke), but im cant find a function that will switch the players current weapons from the one he is holding. I would think the code would be sometihng like this

[Lua]
function GM:PlayerCanPickupWeapon(ply, entity)
local WepGroup_pistol = {
“weapon_glock”,
“weapon_deagle”,
}
local wep = ply:GetActiveWeapon()
if(wep:GetClass() == “weapon_knife”) && (table.HasValue(entity)) then
“Player switch gun to entity???” //What im trying to find
end
end
[/Lua]

If you are using SWEPs, use the AutoSwitchTo property.

This is what you are looking for: http://wiki.garrysmod.com/?title=Player.SelectWeapon

_nonSense -I would do it in the swep but say I had an M16 I dont want to swap to the pistol when its picked up,
thejjokerr - that sounds like it should work but my comp just got a virus so ill have to try it later.
Thanks

doesn’t SWEP.Weight determines if it should be autoswitched to or not? The more weight, the more important the weapon is. At least thats what I knew from .ctx scripting in dods, so you could try something similar. I would test SWEP.Weight to see if it does the job, then go through all your sweps and order them appropriately.

I recall reading that’s what it does: http://wiki.garrysmod.com/?title=SWEP#Server_side_Members

Thanks