@name 
@inputs 
@outputs 
@persist E:entity CMD:string Help:table
@persist ARGS:array STATE MODE:string Force:vector
@persist Perefix:string CMDs:table Options:table Default:table Ow:entity Target:entity
@persist Delim:string Pos:vector
@trigger all
runOnTick(1)
runOnChat(1)
if(first() | duped())
{
    MODE = "follow"
    STATE = 1
    Ow = owner()
    E = entity()
    Target = Ow
    if(E:isWeldedTo())
    {
        E = E:isWeldedTo()
    }
    Options:setString("h","50")        #height
    Options:setString("offx","30")     #offset y
    Options:setString("offy","15")     #offset x
    Options:setString("weight","50000")
    Options:setString("hitbind","1")
    Options:setString("spin","0")      #spin speed
    Options:setString("hitst","400")   #hit length
    Options:setString("weph","200")    #weapon mode length
    
    Default = Options:clone()
    
    #you can replace perefix and delimiter with your own!
    Perefix = "#"
    Delim = ","
    #you can replace command names!
    CMDs:setString("back","b")
    CMDs:setString("kill","kill")
    CMDs:setString("aimkill","aimkill")
    CMDs:setString("orbit","orbit")
    CMDs:setString("hit","hit")
    CMDs:setString("spin","spin")
    CMDs:setString("set","set")
    CMDs:setString("get","get")
    CMDs:setString("wep","wp")
    CMDs:setString("cross","cross")
    CMDs:setString("follow","goto")
    CMDs:setString("on","on")
    CMDs:setString("hold","hold")
    CMDs:setString("off","off")
    CMDs:setString("invis","invis")
    CMDs:setString("vis","vis")
    CMDs:setString("givecontrol","gc")
    CMDs:setString("getcontrol","tc")
    hint("hax bot by koster",7)
    
    print("############HAXBOT#############")
    print(Perefix+CMDs:string("kill")+" nick // bot will try to kill player")
    print(Perefix+CMDs:string("orbit")+" radius"+Delim+"height"+Delim+"speed // bot will fly around target")
    print(Perefix+CMDs:string("back")+" // bot will return to you")
    print(Perefix+CMDs:string("on")+" // tun bot on")
    print(Perefix+CMDs:string("wep")+" // tun weapon on")
    print(Perefix+CMDs:string("cross")+" // tun cross mode on")
    print(Perefix+CMDs:string("aimkill")+" // attacks thing that you are aiming at")
    print(Perefix+CMDs:string("off")+" // tun bot off")
    print(Perefix+CMDs:string("hold")+" // bot will freeze on place")
    print(Perefix+CMDs:string("spin")+" speed // bot will start spining")
    print(Perefix+CMDs:string("invis")+" // makes you and your bot invisible")
    print(Perefix+CMDs:string("vis")+" // makes you and your bot visible")
    print(Perefix+CMDs:string("givecontrol")+" nick // allow other player use your bot")
    print(Perefix+CMDs:string("getcontrol")+" // take control back")
    print(Perefix+CMDs:string("set")+" var number // example "+Perefix+CMDs:string("set")+" h 55")
    print(Perefix+CMDs:string("get")+" var // return var value")
    print(Perefix+CMDs:string("hit")+" // bot will hiy stuff that you are aiming at")
    print("############HAXBOT#############")
    
    hint("all commands printed to console",7)
}

#last said parsing
if(chatClk(Ow) | chatClk(owner()))
{
    if(lastSpoke() == owner() | lastSpoke() == Ow)
    {
        LS = Ow:lastSaid()
        if(owner():lastSaid():explode(" "):string(1) == CMDs:string("givecontrol"))
        {
            if(findPlayerByName(owner():lastSaid():explode(" "):string(2)):pos() != vec(0,0,0))
            {
                Ow = findPlayerByName(owner():lastSaid():explode(" "):string(2))
                Target = Ow
                MODE = "follow"
                hint("give control",7)
            }
        }
        if(owner():lastSaid() == CMDs:string("getcontrol"))
        {
            Ow = owner()
            Target = Ow
            MODE = "follow"
            hint("take control",7)
        }
        elseif(LS:left(Perefix:length()) == Perefix)
        {
            LS = LS:right(LS:length()-1)
            Exp = LS:explode(" ")
            CMD = Exp:string(1)
            ARGS = Exp:string(2):explode(Delim)
            
            if(CMD == CMDs:string("back"))
            {
                MODE = "follow"
                Target = Ow
            }
            elseif(CMD == CMDs:string("cross"))
            {
                MODE = "cross"
            }
            elseif(CMD == CMDs:string("get"))
            {
                if(ARGS:count() == 1)
                {
                    Var = ARGS:string(1)
                    print(Options:string(ARGS:string(1)))
                    hint(Options:string(ARGS:string(1)),7)
                }
                else
                {
                    hint("fucked up arguments",7)
                }
            }
            elseif(CMD == CMDs:string("orbit"))
            {
                if(ARGS:count() == 3)
                {
                    R = ARGS:string(1):replace("d",Default:string("or"))
                    S = ARGS:string(2):replace("d",Default:string("os"))
                    H = ARGS:string(3):replace("d",Default:string("h"))
                    Options:setString("or",R)
                    Options:setString("h",H)
                    Options:setString("os",S)
                    Options:setString("orb","1")
                }
                else
                {
                    hint("fucked up arguments",7)
                }
            }
            elseif(CMD == CMDs:string("hold"))
            {
                MODE = "hold"
                Pos = E:pos()
            }
            elseif(CMD == CMDs:string("hit"))
            {
                Options:setString("lastMode",MODE)
                MODE = "hit"
            }
            elseif(CMD == CMDs:string("wep"))
            {
                MODE = "wep"
            }
            elseif(CMD == CMDs:string("invis"))
            {
                if(Ow:getMaterial() != "models/effects/vol_light001")
                {
                    entity():setMaterial("models/effects/vol_light001")
                    Ow:setMaterial("models/effects/vol_light001")
                    E:setMaterial("models/effects/vol_light001")
                    Ow:weapon():setMaterial("models/effects/vol_light001")
                }
            }
            elseif(CMD == CMDs:string("vis"))
            {
                entity():setMaterial("")
                Ow:setMaterial("")
                E:setMaterial("")
                Ow:weapon():setMaterial("")
            }
            elseif(CMD == CMDs:string("spin"))
            {
                if(ARGS:string(1))
                {
                    Options:setString("spin",ARGS:string(1))
                }
            }
            elseif(CMD == CMDs:string("set"))
            {
                if(ARGS:count() == 2)
                {
                    Var = ARGS:string(1)
                    Val = ARGS:string(2)
                    if(Val == "d")
                    {
                        Options:setString(Var,Default:string(Var))
                    }
                    else
                    {
                        Options:setString(Var,Val)
                    }
                }
                else
                {
                    hint("fucked up arguments",7)
                }
            }
            elseif(CMD == CMDs:string("kill"))
            {
                Nick = ARGS:string(1):trim()
                Target = findPlayerByName(Nick)
                if(Target:name() != "")
                {
                    MODE = "kill"
                }
                elseif(Ow:aimEntity())
                {
                    Target = Ow:aimEntity()
                    if(Target:type() != "")
                    {
                        MODE = "kill"
                    }
                }
                else
                {
                    hint("no such player",7)
                }
            }
            elseif(CMD == CMDs:string("aimkill"))
            {
                if(Ow:aimEntity())
                {
                    Target = Ow:aimEntity()
                    if(Target:type() != "")
                    {
                        MODE = "kill"
                    }
                }
                else
                {
                    hint("no such player",7)
                }
            }
            elseif(CMD == CMDs:string("follow"))
            {
                if(ARGS:string(1) != "")
                {
                    if(findPlayerByName(ARGS:string(1)))
                    {
                        Target = findPlayerByName(ARGS:string(1))
                        MODE = "follow"
                    }
                    else
                    {
                        hint("no such player",7)
                    }
                }
                elseif(Ow:aimEntity())
                {
                        Target = Ow:aimEntity()
                        MODE = "follow"
                }
                else
                {
                    hint("no such player",7)
                }
            }
            else
            {
                hint("no such command!",7)
            }
        }
    }
}
else
{
    E:setMass(Options:string("weight"):toNumber())
    
    Offx = Options:string("offx"):toNumber()
    Offy = Options:string("offy"):toNumber()
    Height = Options:string("h"):toNumber()
    Hitbind = clamp(0,floor(Options:string("hitbind"):toNumber()),3)
    #modes
    
    if(Hitbind & MODE != "hit")
    {
        if(Hitbind == 1)
        {
            if(Ow:keyUse())
            {
                Options:setString("lastMode",MODE)
                MODE = "hit"
            }
        }
        elseif(Hitbind == 2)
        {
            if(Ow:keyAttack1())
            {
                Options:setString("lastMode",MODE)
                MODE = "hit"
            }
        }
        elseif(Hitbind == 3)
        {
            if(Ow:keyAttack2())
            {
                Options:setString("lastMode",MODE)
                MODE = "hit"
            }
        }
    }
    
    if(MODE == "follow")
    {
        if(Options:string("orb"):toNumber())
        {
            Ospeed = Options:string("os"):toNumber()
            ORadius = Options:string("or"):toNumber()
            Off = vec(Offx + cos(curtime()*Ospeed)*ORadius,Offy + sin(curtime()*Ospeed)*ORadius,Target:height()+Height)
        }
        else
        {            
            Ospeed = Options:string("os"):toNumber()
            ORadius = Options:string("or"):toNumber()
            Off = vec(Offx,Offy,Target:height()+Height)
        }
        Force = (Target:pos() - E:pos())+Off
    }
    elseif(MODE == "wep")
    {
        Wh = Options:string("weph"):toNumber()
        Force = (Ow:shootPos() + Ow:eye()*Wh - E:massCenterL()) - E:pos()
        Force *= 10
    }
    elseif(MODE == "cross")
    {
        Force = Ow:aimPos() - E:pos()
        Force *= 10
    }
    elseif(MODE == "hit")
    {
        Hitst = Options:string("hitst"):toNumber()
        Force = (Ow:shootPos() + Ow:eye()*Hitst - E:massCenterL()) - E:pos()
        Force *= 10
        timer("lastmode",Hitst/2)
    }
    elseif(MODE == "hold")
    {
        if(Options:string("orb"))
        {
            Ospeed = Options:string("os"):toNumber()
            ORadius = Options:string("or"):toNumber()
            Off = vec(Offx + cos(curtime()*Ospeed)*ORadius,Offy + sin(curtime()*Ospeed)*ORadius,Target:height()+Height)
        }
        else
        {            
            Ospeed = Options:string("os"):toNumber()
            ORadius = Options:string("or"):toNumber()
            Off = vec(Offx,Offy,Target:height()+Height)
        }
        Force = (Pos - E:pos())+Off
    }
    elseif(MODE == "kill")
    {
        if(Target != owner())
        {
            if(Target:isAlive() | Target:type() != "player")
            {
                Force = (Target:pos() - E:pos())*E:mass()
            }
            else
            {
                if(Options:string("orb"))
                {
                    Ospeed = Options:string("os"):toNumber()
                    ORadius = Options:string("or"):toNumber()
                    Off = vec(Offx + cos(curtime()*Ospeed)*ORadius,Offy + sin(curtime()*Ospeed)*ORadius,Target:height()+Height)
                }
                else
                {            
                    Ospeed = Options:string("os"):toNumber()
                    ORadius = Options:string("or"):toNumber()
                    Off = vec(Offx,Offy,Target:height()+Height)
                }
                Force = (Ow:pos() - E:pos())+Off
            }
        }
        else
        {
            Force = (Ow:pos() - E:pos())*E:mass()
        }
    }
    if(STATE)
    {
        Lev=sqrt((E:inertia():length()^2)/3)
        EA=(E:angles()*20+E:angVel())
        
        Spin = Options:string("spin"):toNumber()
        if(Spin)
        {
            E:applyAngForce(((-EA*Lev)*5):setYaw(Spin*E:mass()))
        }
        else
        {
            E:applyAngForce((-EA*Lev)*5)
        }
        
        E:applyForce((Force - E:vel()/5)*E:mass()*3)
    }
}
if(clk("lastmode"))
{
    MODE = Options:string("lastMode")
}
