Intercepting Use command on all entities?

Not as clear a title as I want it to be, but basically this is what I want to do.

I have a map full of doors all using func_door, right? Then I have two teams, one of humans, one of CPs. What I want to do is check every time a player hits ‘E’ (or whatever key they have for use), and see if there’s a door in front of them. Once they hit E in front of a door, I want it to check for a certain string that door entity has, and if it has the right one for each team, it opens. If it doesn’t, then it doesn’t open.

What I want the function to do:

Find door in certain range in front of player > check flag > check team > if team and flag match, open door, if not, do nothing.

I know there’s an ENT:Use() method, as well as seeing if the IN_USE is down using KeyDown, but I’m not entirely sure where to put the code so the player will always have access to it, or if there’s even a hook I can intercept.

Start by checking the all knowing wiki.

for this i would use this gamemode hook and put it in your gamemodes init.lua

function GM:PlayerUse( ply, ent) 
     if ent:GetClass() == "prop_door" or ent:GetClass() == "func_door" then//check to see if the used ent is a door
          if ent:GetKeyValues().bluedoorflag == true then //check the key value flag assigned in hammer change bluedoorflag to keyvalue from hammer
               if team.GetName(ply:Team()) == "Team Awesome" then//change team awesome to the name of your team
                    return true// allow them to use ent from above
               return false//dont allow them to use object
          return false// door has wrong flag dont allow

untested code buts its the general idea of how you could do it.

Had no idea there was a PlayerUse function for GMod, thanks, this’ll help push my work forward a little. I did actually check the Wiki, but I guess I didn’t check the gamemode hooks.

Ah well, at least you took the time to help me out :), thanks again mate, I’ll be sure to look into this. As for the actual flag, I don’t plan on using the hammer flags, as I can assign my own, given the door is actually an entity.