@persist Target:entity Mode Speed Interval
if(first())
{
    runOnChat(1)
    Mode = 0 #Idle
    Speed = 25
    Interval = 50
}

if(chatClk(owner()))
{
    S = lastSaid():explode(" ")
    Command = S:string(1)
    if(Command == "!target")
    {
        hideChat(1)
        local Temp = findPlayerByName(S:string(2))
        if(Temp)
        {
            Target = Temp
            Mode = 1 #Fly towards target
            holoCreate(1,entity():pos())
            holoScale(1,vec(0.5))
        
            timer("refresh",Interval)
        }   
    }
}
if(clk("refresh") & Mode)
{
    local Direction = (Target:shootPos() - holoEntity(1):pos()):normalized()
    local Distance = Target:shootPos():distance(holoEntity(1):pos())
    holoPos(1,holoEntity(1):pos() + Direction * clamp(Distance,0,Speed))
    if(Distance < 25)
    {
        print("Target reached")
        Mode = 0
        holoDelete(1)
        stoptimer("refresh")
        
    }
    else
    {
        timer("refresh",Interval)
    }
}
