@name Key Protector
@inputs Keypad:entity Screen:wirelink 
@outputs Light
@persist Keypad:entity TarPly:entity Resp:number Return 
@autoupdate
runOnChat(1)
Return = 0
if(first()){
    for(I=0, findInSphere(entity():pos(), 20)){
        if(findResult(I):model() == "models/props_lab/keypad.mdl"){
            
            owner():soundPlay(1,1,"buttons/button17.wav")
            Keypad = findResult(I)
            Return =1
        }
        
    }
    if(Return!=1){hint("No Keypads found type /ref to find new keypads", 15)}else{hint("Found Keypad!", 4)}
   
    
}


Chat = owner():lastSaid():explode(" ")
if(chatClk(owner())){
    if(Chat:string(1)=="/i"){
        entity():setAlpha(0)
        hideChat(1)
        hint("Chip Is Invisible", 4)
        hideChat(1)
    }
    if(Chat:string(1)=="/v"){
        entity():setAlpha(255)
        hint("Chip Is Visible", 4)
        hideChat(1)
    }
    if(Chat:string(1)=="/ref"){
        for(I=0, findInSphere(entity():pos(), 10)){
            if(findResult(I):model() == "models/props_lab/keypad.mdl"){
            hint("Found Keypad!", 4)
            Keypad = findResult(I)
            hideChat(1)
            
            }
        }
}
}

timer("Checkerino", 1000)
for(I = 0, findInSphere(Keypad:pos(), 50)){
    if(findResult(I):isPlayer() & findResult(I):isAlive() & findResult(I):aimEntity()==Keypad){
        
        TarPly = findResult(I)
        
        print(_HUD_PRINTCENTER,TarPly:name() + " is aiming at your keypad")
       
        
    }
    }
if(TarPly!=noentity() & TarPly:isPlayer() & TarPly:isAlive() & TarPly:aimEntity()==Keypad){
    owner():soundPlay(0,0,"buttons/button17.wav")
     Light = 1
}else{soundStop(0,0)  Light = 0}


    Screen:egpText(1,TarPly:name() + " is looking at your keypad!",vec2(10,30))
    Screen:egpText(2,TarPly:name() + " is a " +TarPly:team():teamName(),vec2(10,60))
    Screen:egpText(3,"Last Said: " + TarPly:lastSaid(),vec2(10,90))
    
    
