Any Way To Make Make An Entity Class-Restricted?

I am developing a DarkRP server, and I was hoping that I could make a VIP class that can spawn a combine mech http://steamcommunity.com/sharedfiles/filedetails/?id=142230583

So I made the class and they can spawn it from the entities tab, however, I am worried that since it is a CP class, if they get out of the mech someone can get in it.
Any help or ideas of how to prevent that from happening?

My first thought would be the CanPlayerEnterVehicle hook.

Something along the lines of this should work
[lua]
hook.Add( “CanPlayerEnterVehicle”, “CombineMech CombineOnly”, function(ply, mech)
if not (IsValid(ply) and IsValid(mech)) then return end

if mech:GetClass()==“WhateverMechClassIs” then
if ply:Team()~=TEAM_WHATEVER then return false end
end
end)[/lua]

You’re awesome. Where would I put this? In the entity’s shared.lua?

Also I’m obviously new to lua and such, but would this script still work if the mech is an entity rather than a vehicle?

[lua]
hook.Add( “CanPlayerEnterVehicle”, “CombineMech CombineOnly”, function(ply, mech)
return (IsValid(ply) and IsValid(mech) and (mech:GetClass() == “WhateverMechClassIs”) and (ply:Team() == TEAM_WHATEVER))
end)
[/lua]

This goes into a shared file.
“lua/autorun/filename.lua”

Then you’re always returning true or false, that’ll interfere with other hooks.

So I put it in the shared.lua and now when i try to get in as that class it is as if it lets me in but then forces me out in a fraction of a second. I hit E on the mech, it raises me up to the mech but then I fall.

with hat’s code, it just doesn’t work and I can get in regardless of my class.

[editline]22nd October 2013[/editline]

If you guys want to connect to the server to test things yourself, the ip is 192.168.0.106:27015 and the password is mech.

192.168.. is a local IP, no-one can connect to it except for you.

Wow Can’t believe I just made a mistake like that sorry: 24.217.143.132:27015 (25565?)

Been fooling around with brandon’s script trying to make it work. IDK Why it doesn’t…

EDIT!!: Alright so I got it working by making the script:

hook.Add( “CanPlayerEnterVehicle”, “CombineMech CombineOnly”, function(ply, mech)
return (IsValid(ply) and IsValid(mech) and (ply:Team() == TEAM_MECH))
end)

and taking out the:
(mech:GetClass() == “Civil Patrol Mech Pilot”) and

Part. Thanks all who contributed, wouldn’t have been able to do it without you.