@name Chat Logger Chip
#(with buffer & correct time)
@inputs 
@outputs Endline:string Time:string Day Count CountLast Player:array Last:array
@persist Go Endline:string Cur Buffer:array Count CountLast Player:array Last:array
@trigger 
@model models/Items/AR2_Grenade.mdl
runOnLast(1)

###Use this for tagging servers by IP so you can find them again. 
if(owner():lastSaid():find("!ip ")){hideChat(1)}else{hideChat(0)}

if(last()){print("You just deleted your chat logger chip!")}
runOnFile(1)
if(first()|duped()){
    timer("1",1500)
    print("Chip Operational")
    gSetGroup("semper_fi")
    gShare(1)
    if(gGetStr("armed")){
        Endline=gGetStr("armed")
        print("Hot loaded and ready for action!") 
        Armed=1
    }
    else{fileLoad("Enter.txt")}
    Buffer=array()
}

if(duped()){print("Chip Operational") reset()}
if(first()){Count=0 CountLast=0}


if(!entity():owner()){selfDestruct()}
#By Captain Maim STEAM_0:1:8017844
S="-"
S1="--"

runOnChat(1)

C=":"
Team=lastSpoke():team()
SteamID=C+"<"+lastSpoke():steamID()+">"
Name=" "+lastSpoke():name()+C+" "
if(lastSaidTeam()){Team1="(Team "+Team+")"+C+" "}else{Team1=""}




GMTOffset=-7
Hour=time("hour")+GMTOffset
if(time("sec")<10){Sec="0"+time("sec")}else{Sec=toString(time("sec"))}
if(time("min")<10){Min="0"+time("min")}else{Min=toString(time("min"))}
if((Hour>=(24+GMTOffset))&(Hour<=23)){Day=time("day")}else{Day=time("day")-0}
File="chatlogs/"+time("month")+S+Day+S+time("year")+S+time("isdst")+".txt"
if(Hour<0){Hour+=10-GMTOffset*2}
if(!lastSpoke():health()){Dead="(dead)"}else{Dead=""}
Time="["+Hour+C+Min+C+Sec+"]"   


if(clk("1")){#|Armed|fileClk()){
	#if(!Armed){Endline=fileRead("enter.txt")}else{fileWrite("enter.txt",Endline) gSetStr("armed",Endline)}
    #Endline="\n"
    #Endline=fileRead()
    #print("server name logged")
    #fileAppend(File,Endline)
    #fileAppend(File,"Playing on Server:"+hostname()+Endline)
    #fileAppend(File,"Current Map is: "+map()+Endline)
    #fileAppend(File,Time+"New Session Started: "+Endline)
    concmd("say !ip Playing On Server: "+hostname())
    timer("2",1500)
    Go=1 #print("ready")
    stoptimer("1")
    print("Alpha")
}


if(clk("2")){
    concmd("say !ip Current Map is: "+map())
    timer("3",1500)
    print("Beta")
}
if(clk("3")){
    concmd("say !ip New Session Started: ")
    print("Gamma")
}
Chat=lastSaid()
#Endline="\n"
Endline=fileRead()
Message=Time+SteamID+C+Dead+Team1+Name+Chat+Endline


if(!Go){Buffer:pushString(Message)}
if(Go){
    Buffer:shift()
    Buffer:pop()
    	   while(Buffer:count()){fileAppend(File,Buffer:shiftString()+Endline)}    

	   if(!fileRead()){fileWrite(File,File+": Time is in server up time:"+Endline)}

    if(lastSaidTeam()){fileAppend(File,Time+SteamID+C+Name+Dead+"(Team "+Team+")"+C+" "+lastSaid()+Endline)}
else{fileAppend(File,Message)}
}
