@name Robotboy655's Expression 2: Precise Turret
@inputs 
@outputs Fire X Y Z On
@persist Offests:table Hax:vector
@trigger 
#@model models/hunter/plates/plate1x1.mdl

interval(10)

#TODO: Chat Control
#TODO: Player Targetting :D
#TODO: BETTER AIMING SYSTEM

if(first())
{
    #Purpose of creation :D
    findIncludeClass("fishing_mod_seagull")
    
    #Birds
    findIncludeClass("npc_seagull")
    findIncludeClass("npc_crow")
    findIncludeClass("npc_pigeon")
    
    #Metallic And Flying
    findIncludeClass("npc_manhack")
    findIncludeClass("npc_cscanner")
    findIncludeClass("npc_clawscanner")
    
    #Zombie related
    findIncludeClass("npc_headcrab")
    findIncludeClass("npc_zombie")
    findIncludeClass("npc_fastzombie")
    findIncludeClass("npc_poisonzombie")
    findIncludeClass("npc_zombine")
    
    #Combine related
    findIncludeClass("npc_metropolice")
    findIncludeClass("npc_combine_s")
    findIncludeClass("npc_stalker")
    
    #Antlion related
    findIncludeClass("npc_antlion")
    
    #Other
    findIncludeClass("npc_hunter")
    findIncludeClass("player")
    #findIncludePlayer(findPlayerByName("sly"))
    
    #Additional offests
    Offests["npc_metropolice",number] = 32
    Offests["npc_combine_s",number] = 32
    Offests["npc_stalker",number] = 32
    
    Offests["npc_headcrab",number] = 3
    Offests["npc_headcrab_fast",number] = 3
    Offests["npc_headcrab_black",number] = 3
    Offests["npc_headcrab_poison",number] = 3
    Offests["npc_zombie",number] = 32
    Offests["npc_fastzombie",number] = 32
    Offests["npc_poisonzombie",number] = 32
    Offests["npc_zombine",number] = 32
    
    Offests["npc_antlion",number] = 16
    Offests["npc_antlionguard",number] = 32
    Offests["npc_antlion_worker",number] = 18
    
    Offests["npc_hunter",number] = 64
    Offests["player",number] = 36

    #holoCreate(1)
    #holoModel(1,"hqsphere2")
    #holoColor(1,vec(255,0,0),128)
    #holoScale(1,vec(5,5,5))
}

Ent = entity()
findInSphere(Ent:pos(),999999999) #Ugly hack
findSortByDistance(Ent:pos())
Target = findResult(1)

if(Target) # & Target:isAlive())
{
    #Ent:setAng(((Target:pos() + vec(0,0,Offests[Target:type(),number]) + Target:vel()/(Ent:pos():distance(Target:pos()))) - Ent:pos()):normalized():toAngle())

    #holoScale(1,vec(5,5,5))
    #holoParent(1,Target)

    Fire = 1
    
    Hax = Target:pos() + vec(0,0,Offests[Target:type(),number]) + (Target:vel() / Target:boxMax())#/(Ent:pos():distance(Target:pos()))
    #holoPos(1, Hax)
    
    #Facer support
    X = Hax:x()
    Y = Hax:y()
    Z = Hax:z()
}
elseif(Target)
{
    Fire = 0
}
else
{
    Fire = 0

    #holoScale(1,vec(0.5,0.5,0.5))
    #holoPos(1,Ent:pos() + Ent:forward()*25)
}

#Facer support
On = Fire
