@name Brain!
@inputs Leg1:wirelink Leg2:wirelink
@outputs Values:array FPS FPS_Num Ended Repeat
#@persist Animations:table Animate Loop:array Table:table Keyz:array Q5:array Rate:array
#@persist Time FPS Ended Repeat Animation_Name:string Animation_Link:string

@persist Q5:array Table:table Loop:array Keyz:array Rate:array Animations:table House:array
@persist Animation:string Animation_Name:string Animation_Hold:string Animation_Link:string Hold_Name:string Mode:string Animation_Linked:string
@persist FPS Time Timez Animate Repeat Ended Start Trail Modez Sub_Mode Scale Scale_Pitch Scale_Turn Stand_Timer FPS_Num

@persist Values:array

@persist Base:entity
@trigger none
if(first()|duped())
{
    runOnTick(1)
    runOnChat(1)
    Base = entity():isWeldedTo()
    holoCreate(1,Base:pos()+Base:forward()*500)
    Values = array(60,80,100,60,80,100)
    
    Stand="Stand//1/10/"
    Stand+="1*0|60|50|100|100|60|110|60*"
    Stand+="2*0|140|50|80|100|140|110|140*"
    Stand+="3*0|200|50|150|100|200|110|200*"
    
    Stand+="4*0|60|50|100|100|60|110|60*"
    Stand+="5*0|140|50|80|100|140|110|140*"
    Stand+="6*0|200|50|150|100|200|110|200*"
    
    Walk="Walk//1/15/"
    Walk+="1*0|60|30|150|45|80|90|0|120|60*"
    Walk+="2*0|80|30|160|90|50|120|80*"
    Walk+="3*0|100|30|250|90|0|120|100*"
    
    Walk+="4*0|60|30|0|90|150|105|80|120|60*"
    Walk+="5*0|80|30|50|90|160|120|80*"
    Walk+="6*0|100|30|0|90|250|120|100*"
    
    Walk1="Walk1//1/40/"
    Walk1+="4*0|60|15|120|30|80|90|20|120|60*"
    Walk1+="5*0|80|15|160|90|30|120|80*"
    Walk1+="6*0|100|15|250|90|0|120|100*"
    
    Walk1+="1*0|60|30|20|60|120|75|80|120|60*"
    Walk1+="2*0|80|30|30|60|160|120|80*"
    Walk1+="3*0|100|30|0|60|250|120|100*"
    
    Temp=array(Stand,Walk,Walk1)
    
    for(I=1,Temp:count())
    {
        Animation=Temp:string(I)
        Animation_Name=Animation:explode("/"):string(1)
        Animations[Animation_Name,string]=Animation
    }
    Animation=""
    #===#
    Time=curtime()*10000
    Start=Time
    Ended=0
    #Mode_Ready=1
}
Now=curtime()*10000
if(Now-Time>10000&!Animate)
{
    Time=curtime()*10000
    Start=Time
    Animate=1
}
if(!Animation:find("*")&Animation != "")
{
    Animation=Animations[Animation,string]
    if(Animation == "")
    {
        print("Error Animation Does Not Exist")
    }
}
if(changed(Animation)&Animation!="")
{
    TempArray=Animation:explode("/")
    Animation_Name=TempArray:string(1)
    Animation_Link=TempArray:string(2)
    Repeat=TempArray:string(3):toNumber()
    FPS=TempArray:string(4):toNumber()
    FPS_Num=FPS
    Array=TempArray:string(5):explode("*")
    FPS=10000/FPS
    Temp=array()
    Table=table()
    Loop=array()
    Q5=array()
    Keyz=array()
    Rate=array()
    TempNum=0
    for(I=2,Array:count(),2)
    {
        TempNum+=Temp:count()
        Table["P"+Array:string(I-1),number]=TempNum+1
        Loop:pushNumber(Array:string(I-1):toNumber())
        Temp=Array:string(I):explode("|")
        for(Q=2,Temp:count(),2)
        {
            Q5:pushNumber(Temp:string(Q-1):toNumber())
            Q5:pushNumber(Temp:string(Q):toNumber())
        }
    }
    Loop:pushNumber(0)
    Table["P0",number]=Q5:count()
    for(I=1,Loop:count())
    {
        Index=Table[("P"+toString(Loop:number(I))),number]
        Key=vec(Q5:number(Index),Q5:number(Index+2),3)
        Keyz[I,vector]=Key
        Rate[I,number]=(Q5:number(Index+Key:z())-Q5:number(Index+Key:z()-2))/(Key:y()-Key:x())
    }
    Time=curtime()*10000
    Start=Time
    Ended=0
}
if(Animate)
{
    if(Now-Time>FPS&!Ended)
    {
        Time=Now
        for(I=1,Loop:count())
        {
            Index=Table[("P"+toString(Loop:number(I))),number]
            Key=Keyz:vector(I)+vec(1,0,0)
            #Ang=Q5:angle(Index+Key:z()-2)+(Rate:angle(I)*(Key:x()-Q5:number(Index+Key:z()-3)))
            Values[Loop:number(I),number] = Q5:number(Index+Key:z()-2)+(Rate:number(I)*(Key:x()-Q5:number(Index+Key:z()-3)))
            #holoAng(Loop:number(I),Doggy_Angle+Ang)
            if(Animation_Link!="")
            {
                Animation_Linked=Animation_Name
            }
            if(Key:x()>=Key:y())
            {
                Key+=vec(0,0,2)
                Key=Key:setY(Q5:number(Index+Key:z()-1))
                #Rate[I,angle]=(Q5:angle(Index+Key:z())-Q5:angle(Index+Key:z()-2))/(Key:y()-Key:x())
                Rate[I,number]=(Q5:number(Index+Key:z())-Q5:number(Index+Key:z()-2))/(Key:y()-Key:x())
                if(Key:z()+Index>Table[("P"+toString(Loop:number(I+1))),number])#===Note May Cause Timeing Error===#
                {
                    if(Repeat)
                    {
                        Key=vec(Q5:number(Index),Q5:number(Index+2),3)
                        #Rate[I,angle]=(Q5:angle(Index+Key:z())-Q5:angle(Index+Key:z()-2))/(Key:y()-Key:x())
                        Rate[I,number]=(Q5:number(Index+Key:z())-Q5:number(Index+Key:z()-2))/(Key:y()-Key:x())
                    }
                    elseif(Now-Start>5000)
                    {
                        if(Animation_Link!="")
                        {
                            Animation=Animations[Animation_Link,string]
                        }
                        else
                        {
                            Animation_Linked=""
                            Ended=1
                        }
                    }
                }
            }
            Keyz[I,vector]=Key
        }
    }
}
if(chatClk(owner()))
{
    Said = lastSaid():explode(" ")
    Said1 = Said:string(1):lower()
    if(Said1 == "stop")
    {
        Values = array(60,80,100,60,80,100)
        Animation = ""
    }
    if(Said1 == "animation")
    {
        Animation = Said:string(2)
    }
}
Base:applyAngForce((-Base:angles()*50-Base:angVel()*3)*Base:mass()*ang(2,0,60))
Leg1["Hy_In",number] = Values:number(1)
Leg1["Hy1_In",number] = Values:number(2)
Leg1["Hy2_In",number] = Values:number(3)

Leg2["Hy_In",number] = Values:number(4)
Leg2["Hy1_In",number] = Values:number(5)
Leg2["Hy2_In",number] = Values:number(6)