@name Turret
@inputs 
@outputs Fire W:entity
@persist [T O]:entity M1 Ammo Spam Reload 
@trigger 

interval(1)
if(duped()) {reset()}
if(first()) {
    findIncludePlayerProps(owner())
    findByClass("gmod_wire_turret")
    T = find()
    T:setColor(vec(0,255,0))
    O = owner()
    Ammo = 45
}
M1 = owner():keyAttack2()
if(T) {
    if(O:weapon():getAlpha() != 0 & O:isAlive()) {
        O:weapon():setAlpha(0)
        hint("HIDE",10)
    }
    T:applyForce((O:shootPos()+O:right()*7-O:up()*2+O:eye()*30-T:pos()-T:vel()/15)*T:mass()*10)
    Ang = O:eyeAngles()-T:angles()
    Ang = ang(Ang:pitch()/5,Ang:yaw(),Ang:roll()/10)
    T:applyAngForce(angnorm(Ang-T:angVel()/25)*T:mass()*5)
    if(M1 & !Spam & Ammo > 0) {
        Ammo--
        Fire = 1
        Spam = 2
    } else {
        if(Fire == 1) {
            Fire = 0
        }
        if(!Ammo & !Reload) {
            timer("reload",2500)
            Reload = 1
        }
    }
    if(Spam) {Spam--}
}

if(clk("reload")) {
    Ammo = 45
    Reload = 0
    stoptimer("reload")
}
