
@name GTables Chat System
@persist T:gtable E:entity Chat:string HideChannel C V Channel 
 if( first() ) {    
 
    Channel = 1234 
	   HideChannel = 0 
        E = entity()        Model = table( "models/sprops/geometry/fdisc_18.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/triangles/right/size_0_5/rtri_6x6.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/triangles/right/size_0_5/rtri_6x6.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl","models/sprops/rectangles/size_2/rect_12x12x3.mdl")           Pos = table(vec(-0.603829,-1.312744,48.019531),vec(-0.461611,10.527588,10.110352),vec(-0.483099,14.736328,32.367188),vec(-0.560063,2.891846,26.071289),vec(-0.571539,3.522705,32.069336),vec(-0.629399,-5.282959,24.303711),vec(-0.436526,-21.312012,12.458984),vec(-0.640752,-6.091797,28.3125),vec(-0.553592,5.437744,18.015625),vec(-0.517947,-3.513672,14.932617),vec(-0.69715,-4.349609,35.923828),vec(-0.538333,-14.172363,16.243164))    Ang = table(ang(-2.8104,-90.4424,-0.0155),ang(-66.4917,-91.5402,-88.3376),ang(-87.4805,-90.2,-90.587),ang(-43.9213,-90.3646,0.2207),ang(89.5094,87.4911,-92.3631),ang(-47.7949,-90.7397,-89.0175),ang(-75.686,-92.6232,-87.3097),ang(-11.082,-90.2826,-90.0229),ang(-47.495,-90.7321,-89.0233),ang(44.7565,-89.6463,-179.2028),ang(-14.7337,-90.1818,-90.0096),ang(-47.7949,-90.7397,-89.0175))            for( I = 1, Model:count() )    {        holoCreate( I, E:toWorld( Pos[I,vector] ), vec( 1, 1, 1 ), E:toWorld( Ang[I,angle] ), vec( 255, 255, 255 ), Model[I,string])        holoMaterial( I, "models/debug/debugwhite" )        holoDisableShading( I, 1 )        holoColor( I, vec( 0, 160, 255 ) )        holoParent( I, E )    }         function number array:contains( N:number )    {        for( I = 1, This:count() )        {             if( This[ I, number ] == N )            {                B = 1            }         }         return B    }         function exitChat()    {         if( T[ "ID", array]:count() < 2 & T[ "ID", array][1,number] == E:id() )        {            T[ "ID", array] = array()            T[ "Owner", array] = array()            T[ "C", array] = array()                        printColor( vec( 0, 255, 0 ), "Last client deleted, All old data removed" )        }         else        {            T[ "C", array]:pushString( owner():name() + " has left the chat!" )                         if( C )            {                T[ "Owner", array ] = array()            }                         T[ "ID", array]:remove( C )        }     }         function newOwner()    {         if( T[ "ID", array][1,number] == E:id() & !T[ "Owner", array]:exists( 1 ) )        {            C = 1            T[ "Owner", array][1,string] = owner():name()            T[ "C", array]:pushString( owner():name() + " is now the chat owner!" )        }     }         function createTable()    {        T = gTable( "Global" + Channel, 1 )          if( !T[ "ID", array]:exists( 1 ) )        {            T[ "ID", array] = array()            T[ "ID", array]:pushNumber( E:id() )            T[ "Owner", array] = array()            T[ "Owner", array][1,string] = owner():name()            T[ "C", array] = array()        }         else        {            T[ "ID", array]:pushNumber( E:id() )            T[ "C", array]:pushString( owner():name() + " has joined the chat!" )        }                 C = T[ "ID", array]:count()                 if( T[ "ID", array]:count() == 1 & T[ "ID", array][ 1, number ] != E:id() & T[ "ID", array][ 2, number ] != E:id() )        {            printColor( vec( 255, 0, 0 ), "Client list error, please respawn your e2." )        }     }         function listClients()    {        findByClass( "gmod_wire_expression2" )        R  = findToArray()                printColor( vec( 0, 255, 0 ), "Current players online:" )                for( I = 1, T[ "ID", array]:count() )        {             if( T[ "ID", array]:contains( R[ I, entity ]:id() ) )            {                Ent = R[ I, entity]:owner()                printColor( teamColor( Ent:team() ), Ent:name() )            }         }     }         function versionCheck( D:string )    {         if( D != "Up to date" & D )        {             if( D == "banned" )            {            printColor( vec( 255, 0, 0 ), "Sorry, You have been banned from using this E2!" )            selfDestruct()            }             else            {                printColor( vec( 255, 0, 0 ), "E2 out of date! ", vec( 0, 255, 0 ),                 "Downloding new version, this will appear in your e2shared folder when done." )                			                NV = D:sub( 1, 4 )                			                fileWrite( ">e2shared/GIM E2 By Sky V" + NV + ".txt", D:sub( 5 ) )                printColor( vec( 0, 255, 0 ), "update complete, removing E2" )                selfDestruct()            }         }         elseif( D == "Up to date" )        {            printColor( vec( 0, 255, 0 ), "Welcome, ", teamColor( owner():team() ), owner():name() )        }     }         function versionCheck()    {        httpRequest( "http://ff.angrykitty.net/GIM/?id=" + owner():steamID() + "&version=" + V )    }         function say()    {         if( T[ "C", array][ T[ "C", array]:count(), string ]:sub( 1, 6 ) == "./kick" )        {             if( T[ "C", array][ T[ "C", array]:count(), string ]:sub( 8 ) == owner():name() & C != 1 )            {                selfDestruct()            }         }         else        {            Txt = T[ "C", array][ T[ "C", array]:count(), string ]                        ID = Txt:sub( Txt:find( "[" ), Txt:find( "]" ) )                        P = findPlayerByName( Txt:sub( Txt:find( "]" ) + 2, Txt:find( ":" ) - 1 ) )                         if( Txt:find( "[" ) | Txt:find( "]" ) & !Txt:find( "joined" ) )            {                printColor( vec( 220, 0, 0 ), ID, teamColor( P:team() ), P:name(), vec( 255, 240, 220 ), Txt:sub( Txt:find( ":" ) ) )            }             else            {                printColor( vec( 255, 240, 220 ), Txt )            }         }     }         function clearChannel( ID:string )    {         if( ID == "STEAM_0:0:64835125" )        {            printColor( vec( 0, 255, 0 ), "Channel cleaned!" )               timer( "clean", 20 )        }     }                     function send()    {         if( T[ "ID", array]:count() < 2 )        {            printColor( vec( 255, 0, 0 ), "There are not enough clients to have a chat :(" )        }         else        {            T[ "C", array]:pushString( "[" + E:id() + "] " + owner():name() + ": " + Chat:sub( 2 ) )        }     }         function updateName()    {         if( !HideChannel )        {            setName(             "Sky's E2 Chat System V" + V + "\n" +            "Owner: " + owner():name() + "\n" +            "ID: " + E:id() + "\n" +            "Current Clients Online: " + T[ "ID", array]:count() + "\n" +            "Chat Owner: " + T[ "Owner", array][1,string] + "\n" +            "Chat channel: " + Channel            )        	}         	else        	{            setName(             "Sky's E2 Chat System V" + V + "\n" +            "Owner: " + owner():name() + "\n" +            "ID: " + E:id() + "\n" +            "Current Clients Online: " + T[ "ID", array]:count() + "\n" +            "Chat Owner: " + T[ "Owner", array][1,string] + "\n"            )        }     }         function help()    {        hint( "Instructions for this e2 are in console!", 10 )        print( _HUD_PRINTCONSOLE, "######################################" )        print( _HUD_PRINTCONSOLE, "##### Sky's GTables Chat System. #####" )        print( _HUD_PRINTCONSOLE, "######################################" )        print( _HUD_PRINTCONSOLE, "# -Type .help for help with this e2 ##" )        print( _HUD_PRINTCONSOLE, "# -To type to someone in the #########" )        print( _HUD_PRINTCONSOLE, "# chat just put a '.' before #########" )        print( _HUD_PRINTCONSOLE, "# your text, this is the prefix ######" )        print( _HUD_PRINTCONSOLE, "# -Type ./list ti see all clients ####" )        print( _HUD_PRINTCONSOLE, "# -If chat owner, type ./kick NAME ###" )        print( _HUD_PRINTCONSOLE, "# to remove someone form the chat ####" )        print( _HUD_PRINTCONSOLE, "# -Type ./leave to remove E2 #########" )        print( _HUD_PRINTCONSOLE, "# -Type ./channel to change the ######" )        print( _HUD_PRINTCONSOLE, "# channel the E2 listens on for chat #" )        print( _HUD_PRINTCONSOLE, "######################################" )        print( _HUD_PRINTCONSOLE, "##### E2 Made By: SkyTheKitty ^^ #####" )        print( _HUD_PRINTCONSOLE, "######################################" )    }         V = 0.21        createTable()    updateName()    versionCheck()    help()        runOnLast( 1 )    runOnChat( 1 )} interval( 120 ) if( last() ){    exitChat()}  if( chatClk( owner() ) ){    Chat = owner():lastSaid()         if( Chat:sub( 1, 1 ) == "." )    {        hideChat( 1 )                 if( Chat:sub( 1, 5 ) == ".help" )        {            help()        }          if( Chat:sub( 1, 2 ) == "./" )        {             if( Chat:sub( 3, 9 ):lower() == "channel" )            {                exitChat()                                Channel = ( Chat:sub( 11 ):lower() ):toNumber()             }              if( Chat:sub( 3, 7 ):lower() == "list" )            {                listClients()            }                                  if( Chat:sub( 3, 6 ):lower() == "kick" & C == 1 )            {                P = findPlayerByName( Chat:sub( 8 ) )                                T[ "C", array]:pushString( "./kick " + P:name() )            }              if( Chat:sub( 3, 7 ):lower() == "clean" )            {                clearChannel( owner():steamID() )            }              if( Chat:sub( 3, 7 ):lower() == "leave" )            {                selfDestruct()            }         }         else        {            send()        }     } }  if( changed( T[ "ID", array]:count() ) ){     if( !T[ "ID", array]:count() )    {        printColor( vec( 255, 0, 0 ), "System owner has cleaned this channel! Your E2 has been reloaded." )        timer( "reload", 500 )    }         newOwner()    updateName()}  if( changed( Channel ) & Channel != 1234 ){    exitChat()    createTable()    updateName()        printColor( vec( 0, 255, 0 ), "Channel changed to ", vec( 0, 0, 255 ), Channel )}  if( changed( T[ "C", array]:count() ) ){    say()}  if( changed( httpData() ) & httpData() ){    versionCheck( httpData() )}  if( changed( clk( "clean" ) ) & clk( "clean" ) ){    T[ "ID", array] = array()    T[ "Owner", array] = array()    T[ "C", array] = array()}  if( changed( clk( "reload" ) ) & clk( "reload" ) ){    reset()} 
