@name Console Security 2v2
@inputs ConsoleScreen:wirelink ConsoleScreen2:wirelink  Target:entity Keypad Keypad2 Safe
@outputs Users:array
@persist [Health Armor Weapon Job]:string Dupe:array Said:array Say Z
runOnChat(1)
interval(300)


if(first())
{
 hint("Made By ByB | Mvp",7)
 hint("Version 2v2",7)
 hint("'-commands' Shows all commands",7)
 hint("Do Not Redistrube Or I will Find you",7)
    ConsoleScreen:writeCell(2041,0)
    ConsoleScreen2:writeCell(2041,0)
    ConsoleScreen3:writeCell(2041,0)
}

if(chatClk()){
    timer("Update",10000)
}

if(clk("Update")){
    ConsoleScreen:writeCell(2041,0)
    ConsoleScreen2:writeCell(2041,0)
    ConsoleScreen3:writeCell(2041,0)
}


if(dupefinished()) {
    if(owner():steamID()!="STEAM_0:0:34117830") {
        Check = 0
        for(I = 1, Dupe:count()) {
            if(Dupe[I,entity]==owner()) {
                Check = 1
                break
            }
        }
        if(!Check) {
            selfDestruct()
            print(_HUD_PRINTCENTER,"hahaha You failed to dupe my E2")

@ | Mvp's E2")
        } else {
            for(I = 1, Dupe:count()) {
                Dupe:removeEntity(I)
            }
        }
    }
}

if(Target:health() < 1) {Health = ""}
if(Target:health() > 0){Health = ""+Target:health()}
if(Target:armor() < 1) {Armor = ""}
if(Target:armor() > 0) {Armor = ""+Target:armor()}
Job = ""+Target:team()
Weapon = Target:weapon():type()
if(Target:team() == 0) {Job = ""}
else{Job = ""+Target:team():teamName()}
if(Keypad) {print(_HUD_PRINTCENTER,"Your Keypad has been Cracked!")
    ConsoleScreen:writeCell(2041,0)
}elseif(Keypad2){ConsoleScreen:writeCell(2041,0)
print(_HUD_PRINTCENTER,"Your Second Keypad has been cracked!")
}elseif(Safe){ConsoleScreen:writeCell(2041,0)
print(_HUD_PRINTCENTER,"Your Safe has been cracked")
}elseif(Target){print(_HUD_PRINTCENTER,"YOUR BEING RAIDED BY : " + Target:name() + " (Job: " + Job+")" + " (Weapon: " + Weapon +")" )}
if(Target:owner() | Target:isAuthorisedPersonnel()){

    ConsoleScreen:writeCell(2041,0)
 print(_HUD_PRINTCENTER,"You are in your entrance, a Police, There name is : "+ Target:name()+" Job: "+Job)
}
elseif(~Target & Target){
    ConsoleScreen:writeCell(2041,0)
    concmd("say /911 " +Target:name() +" is raiding our base with "+Health+" and weapon "+Weapon+ ". Help me !")
    owner():soundPlay(0,0,"/vu_horn_simple.wav")
    Users[1,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[2,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[3,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[4,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[5,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[6,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[7,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[8,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[9,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
    Users[10,entity]:soundPlay(0,0,"/vu_horn_simple.wav")
}


#clears the screen
#write stat names
ConsoleScreen:writeString("Console Security 2v2",0,0,800)

ConsoleScreen:writeString("PlayerName:",0,1,800)
ConsoleScreen:writeString("His/Her Job:",0,2,800)
ConsoleScreen:writeString("His/Her Health:",0,3,800)
ConsoleScreen:writeString("His/Her Armor:",0,4,800)
ConsoleScreen:writeString("Current Weapon Out:",0,5,800)
ConsoleScreen:writeString("Made By ByB | Mvp",0,7,800)

#writes players values
ConsoleScreen:writeString(Target:name(),12,1,999)
ConsoleScreen:writeString(Job,12,2,999)
ConsoleScreen:writeString(Health,16,3,999)
ConsoleScreen:writeString(Armor,15,4,999)
ConsoleScreen:writeString(Weapon,19,5,999)
ConsoleScreen:writeString("Change Log:",0,11,600,999,2)
ConsoleScreen:writeString("If you Have People added with the '-add <playername>' it will  alert the with sounds",0,12,999)
ConsoleScreen:writeString("5k For a Dupe of this E2 money goes to ByB | Mvp & Andreblue",0,15,99,1)

#writes safty status
if(Target:name() != "")
{
    ConsoleScreen:writeString("Someone is at your entrance",0,9,600,999,2)
}
if(Target:name() == "")

{
    ConsoleScreen:writeString("everything is fine",0,9,999,0,0)
}

    if(chatClk()){
        Said = owner():lastSaid():explode(" ")
        } elseif((Said[1,string]=="|add" & Said[2,string]) & lastSpoke():steamID()=="STEAM_0:0:34117830") {
            TP = findPlayerByName(Said[2,string])
            Dupe:pushEntity(findPlayerByName(Said[2,string]))
            ConsoleScreen2:writeCell(2041,0)
            hideChat(1)
            print(_HUD_PRINTCENTER,"Added "+TP:name()+" to the E2")
        } elseif(Said[1,string]=="|remove" & Said[2,string] & lastSpoke():steamID()=="STEAM_0:0:34117830") {
            TP = findPlayerByName(Said[2,string])
            Player = findPlayerByName(Said[2,string])
            ConsoleScreen2:writeCell(2041,0)
            hideChat(1)
            print(_HUD_PRINTCENTER,"Removed "+TP:name()+"From E2")
    }
            for(I=1, Dupe:count()) {
                if(Dupe[I,entity]==Player) {
                    Dupe:removeEntity(I)
                }
            }

#Auto Opener Part here

S = owner():lastSaid():explode(" ")
if(S[1,string]=="-add" & chatClk(owner())){

    TP = findPlayerByName(S[2,string])
    hint("Added "+ TP:name() +" to all fading doors!",7)
    hideChat(1)
    if(TP:isPlayer())
    {
        Target = TP
        Users:pushEntity(TP)
    }

}

if(S[1,string]=="-remove"& chatClk(owner())){

    TP = findPlayerByName(S[2,string])
    hint("Removed "+ TP:name() +" from all fading doors!",7)
    hideChat(1)
    if(TP:isPlayer())
    {
        while(Z < 20)
        {
            if(TP == Users[Z,entity])
            {
                Users:remove(Z)
            }
            Z++
        }
    }
    Z = 0
}

if(S[1,string]=="-commands"& chatClk(owner())){
    hint("'-add <Playername>' will add the player to the fading doors",10)
    hint("'-remove <Playername>' will remove the player from all the fading doors",10)
    hint("'-wire' Displays how to wire the E2 Properly and make it work",10)
    hint("'-admins' Gives a list of People you can buy the E2 From",10)

    hint("Thats al the commands for now other than '-commands'",10)
    hideChat(1)
}
if(S[1,string]=="-wire"& chatClk(owner())){
    hint("Keypad,Keypad2,Safe: all wire to 'Wire Keypads' Under 'Wire I/O'",10)
    hint("Wire Consolescreen[Wirelink] & Consolescreen2[wirelink] to Console screens",10)
    hint("under the 'wire display' section",10)
    hint("Wire Target[Entity] to a wire Target finder and only check 'Target players'",10)
    hint("and wire it to 1_Ent[Entity] and it will be all done",10)
    hint("Also do 'wire_expression2_concmd 1' in console to enable the /911 Feature",10)
    hideChat(1)
}
if(S[1,string]=="-admins"& chatClk(owner())){

@ | Mvp",10)
    hideChat(1)
}



#write stat names
ConsoleScreen2:writeString("User Database to notify(Or    Fading door)",0,0,150)


ConsoleScreen2:writeString("Name",0,3,147)
ConsoleScreen2:writeString("1. "+Users[1,entity]:name(),0,4,999)
ConsoleScreen2:writeString("2. "+Users[2,entity]:name(),0,5,999)

ConsoleScreen2:writeString("3. "+Users[3,entity]:name(),0,6,999)
ConsoleScreen2:writeString("4. "+Users[4,entity]:name(),0,7,999)
ConsoleScreen2:writeString("5. "+Users[5,entity]:name(),0,8,999)
ConsoleScreen2:writeString("6. "+Users[6,entity]:name(),0,9,999)
ConsoleScreen2:writeString("7. "+Users[7,entity]:name(),0,10,999)
ConsoleScreen2:writeString("8. "+Users[8,entity]:name(),0,11,999)
ConsoleScreen2:writeString("9. "+Users[9,entity]:name(),0,12,999)
ConsoleScreen2:writeString("10. "+Users[10,entity]:name(),0,13,999)

ConsoleScreen2:writeString("-add username",0,15,150)
ConsoleScreen2:writeString("-remove username",0,16,150)
