@name Holo Chess
@persist [Board Moves]:table VMoves:array [P1 P2]:entity [Select MVec]:vector2 Stage H Turn DPW DPB
if(first())
{
    Moves["pawn",table]=table(table(vec2(0,1),array(),1),table(vec2(0,2),  array(vec2(0,1)),2),table(vec2(-1,1),array(),3),table(vec2(1,1),array(),3))
    Moves["rook",table]=table()
    for(I=1,7)
    {
        T1=array()
        T2=array()
        T3=array()
        T4=array()
        for(J=1,I-1)
        {
            T1:pushVector2(vec2(0,J))
            T2:pushVector2(vec2(J,0))
            T3:pushVector2(vec2(0,-J))
            T4:pushVector2(vec2(-J,0))
        }
        Moves["rook",table]:pushTable(table(vec2(0,I),T1,0))
        Moves["rook",table]:pushTable(table(vec2(I,0),T2,0))
        Moves["rook",table]:pushTable(table(vec2(0,-I),T3,0))
        Moves["rook",table]:pushTable(table(vec2(-I,0),T4,0))
    }
    Moves["knight",table]=table(table(vec2(1,2),array(),0),table(vec2(1,-2),array(),0),table(vec2(-1,2),array(),0),table(vec2(-1,-2),array(),0),table(vec2(2,1),array(),0),table(vec  2(2,-1),array(),0),table(vec2(-2,1),array(),0),table(vec2(-2,-1),array(),0))
    Moves["bishop",table]=table()
    for(I=1,7)
    {
        T1=array()
        T2=array()
        T3=array()
        T4=array()
        for(J=1,I-1)
        {
            T1:pushVector2(vec2(J,J))
            T2:pushVector2(vec2(J,-J))
            T3:pushVector2(vec2(-J,J))
            T4:pushVector2(vec2(-J,-J))
        }
        Moves["bishop",table]:pushTable(table(vec2(I,I),T1,0))
        Moves["bishop",table]:pushTable(table(vec2(I,-I),T2,0))
        Moves["bishop",table]:pushTable(table(vec2(-I,I),T3,0))
        Moves["bishop",table]:pushTable(table(vec2(-I,-I),T4,0))
    }
    Moves["queen",table]=table()
    for(I=1,7)
    {
        T1=array()
        T2=array()
        T3=array()
        T4=array()
        T5=array()
        T6=array()
        T7=array()
        T8=array()
        for(J=1,I-1)
        {
            T1:pushVector2(vec2(0,J))
            T2:pushVector2(vec2(J,0))
            T3:pushVector2(vec2(0,-J))
            T4:pushVector2(vec2(-J,0))
            T5:pushVector2(vec2(J,J))
            T6:pushVector2(vec2(J,-J))
            T7:pushVector2(vec2(-J,J))
            T8:pushVector2(vec2(-J,-J))
        }
        Moves["queen",table]:pushTable(table(vec2(0,I),T1,0))
        Moves["queen",table]:pushTable(table(vec2(I,0),T2,0))
        Moves["queen",table]:pushTable(table(vec2(0,-I),T3,0))
        Moves["queen",table]:pushTable(table(vec2(-I,0),T4,0))
        Moves["queen",table]:pushTable(table(vec2(I,I),T5,0))
        Moves["queen",table]:pushTable(table(vec2(I,-I),T6,0))
        Moves["queen",table]:pushTable(table(vec2(-I,I),T7,0))
        Moves["queen",table]:pushTable(table(vec2(-I,-I),T8,0))
    }
    Moves["king",table]=table(table(vec2(0,1),array(),0),table(vec2(1,1),  array(),0),table(vec2(1,0),array(),0),table(vec2(1  ,-1),array(),0),table(vec2(0,-1),array(),0),table(vec2(-1,-1),array(),0),table(vec2(-1,0),array(),0),table(vec2(-1,1),array(),0))
    Colors=array()
    Colors[105,vector]=vec(255,93,0)
    Colors[106,vector]=vec(0,0,255)
    Colors[107,vector]=vec(255,0,0)
    Colors[108,vector]=vec(255,0,0)
    for(I=105,108)
    {
        holoCreate(I,vec(),vec(),entity():angles(),Colors[I,vector],"hq_cylinder")
        holoScaleUnits(I,vec(20,20,50))
        holoAlpha(I,0)
        holoDisableShading(I,1)
        holoParent(I,entity())
    }
    Stage=1
    runOnTick(1)
    runOnChat(1)
}
if(tickClk())
{
    if(Stage==1)
    {
        while(H<64&holoCanCreate())
        {
            holoCreate(H+1,entity():toWorld(vec((floor(H/8)-3.5)*20,(mod(H,8)-3.5)*20,10)),vec(),entity():angles(),mod(abs(floor  (H/8)+mod(H,8)),2)*vec(128,64,-127)+vec(127))
            holoScaleUnits(H+1,vec(20,20,5))
            holoParent(H+1,entity())
            H++
        }
        if(H==64)
        {
            Stage=2
        }
    }
    if(Stage==3)
    {
        if(H<=64)
        {
            for(I=1,8)
            {
                Board[I,table]=table()
            }
            Board[1,table][1,array]=array(1,"rook")
            Board[2,table][1,array]=array(1,"knight")
            Board[3,table][1,array]=array(1,"bishop")
            Board[4,table][1,array]=array(1,"queen")
            Board[5,table][1,array]=array(1,"king")
            Board[6,table][1,array]=array(1,"bishop")
            Board[7,table][1,array]=array(1,"knight")
            Board[8,table][1,array]=array(1,"rook")
            Board[1,table][8,array]=array(2,"rook")
            Board[2,table][8,array]=array(2,"knight")
            Board[3,table][8,array]=array(2,"bishop")
            Board[4,table][8,array]=array(2,"queen")
            Board[5,table][8,array]=array(2,"king")
            Board[6,table][8,array]=array(2,"bishop")
            Board[7,table][8,array]=array(2,"knight")
            Board[8,table][8,array]=array(2,"rook")
            for(I=1,8)
            {
                Board[I,table][2,array]=array(1,"pawn")
                Board[I,table][7,array]=array(2,"pawn")
                for(J=3,6)
                {
                    Board[I,table][J,array]=array(0,"",0)
                }
            }
        }
        while(H<96&holoCanCreate())
        {
            S="white"
            if(H>=80)
            {
                S="black"
            }
            holoCreate(H+1,entity():toWorld(vec((mod(H,8)-3.5)*20,((floor((H-64)/8)+floor((H-64)/16)*4)-3.5)*20,12.5)),vec(1),entity():angles():rotateArou  ndAxis(entity():up(),90-floor((H-64)/16)*180),vec(255),"models/props_phx/games/chess/"+S+"_"+Board[mod(H,8)+1,table][floor((H-56)/8)+floor((H-64)/16)*4,array][2,string]+".mdl")
            holoParent(H+1,entity())
            Board[mod(H,8)+1,table][floor((H-56)/8)+floor((H-64)/16)*4,array][3,number]=H+1
            H++
        }
        if(H==96)
        {
            Stage=4
        }
    }
    if(Stage==4)
    {
        if(Turn)
        {
            P=P2
        }
        else
        {
            P=P1
        }
        C1=0
        C2=0
        if(changed(P:keyAttack2())&P:keyAttack2()&P:weapon():type()=="weapon_crowbar")
        {
            C1=1
        }
        if(changed(P:keyReload())&P:keyReload()&P:weapon():type()=="weapon_crowbar")
        {
            C2=1
        }
        V1=entity():toLocal(P:shootPos())
        V2=entity():toLocalAxis(P:eye())
        N1=(V1:z()-12.5)/V2:z()
        V3=vec2(V1-V2*N1)
        V4=vec2(floor(V3:x()/20)+5,floor(V3:y()/20)+5)
        if(C2)
        {
            VMoves=array()
            Select=vec2()
        }
        if(N1<0&V2:z()<0&inrange(V4,vec2(1),vec2(8)))
        {
            holoPos(105,entity():toWorld(vec((V4:x()-4.5)*20,(V4:y()-4.5)*20,37.5)))
            holoAlpha(105,127)
            if(Select:x())
            {
                Valid=0
                for(I=1,VMoves:count())
                {
                    if(V4==VMoves[I,vector2])
                    {
                        Valid=1
                    }
                }
                if(Valid)
                {
                    holoColor(105,vec(0,255,0))
                    if(C1)
                    {
                        if(Board[V4:x(),table][V4:y(),array][1,number])
                        {
                           if(Turn)
                            {
                                holoPos(Board[V4:x(),table][V4:y(),array][3,number],entity():toWorld(vec((-mod(DPB,8)+3.5)*20,(5.5+floor(DPB/8))*20,7.5)))
                                DPB++
                            }
                            else
                            {
                                holoPos(Board[V4:x(),table][V4:y(),array][3,number],entity():toWorld(vec((mod(DPW,8)-3.5)*20,(-5.5-floor(DPW/8))*20,7.5)))
                                DPW++
                            }
                            if(Board[V4:x(),table][V4:y(),array][2,string]=="king")
                            {
                                concmd("say [Chess] Winner: "+P:name())
                                print("Winner: "+P:name())
    
