@name Android Zbychu
@inputs
@outputs Shoot
@persist State Spawning Angle Speed RandomWalk HeadAngle E:entity Holding ThrowAngle Pos:vector AnimVel CanHold Target:entity AttackTarget:entity LastPos:vector Fallspeed
@persist HandAngle1:angle HandAngle2:angle
@trigger
interval(20)
runOnChat(1)
if(first()) {
    #Movement
    holoCreate(0)
    holoAng(0, ang(0,-90,0))
    holoPos(0,entity():pos())
    holoAlpha(0,0)
    #Cialo
    holoCreate(1)
    holoModel(1,”hq_cylinder”)
    holoPos(1, holoEntity(0):pos()+vec(0,0,40))
    holoColor(1, vec(0,150,0))
    holoScale(1,vec(3,3,3))
    holoParent(1, 0   )
    #Glowa
    holoCreate(2)
    holoModel(2,”hq_dome”)
    holoPos(2,holoEntity(1):pos()+vec(0,0,19))
    holoColor(2, vec(0,150,0))
    holoScale(2,vec(3,3,3))
    holoParent(2, 1)
    #Oczy
    holoCreate(3)
    holoModel(3,”hqsphere”)
    holoPos(3,holoEntity(2):pos()+vec(8,-12,10))
    holoScale(3,vec(0.3,0.3,0.3))
    holoParent(3, 2)
    holoCreate(4)
    holoModel(4,”hqsphere”)
    holoPos(4,holoEntity(2):pos()+vec(-8,-12,10))
    holoScale(4,vec(0.3,0.3,0.3))
    holoParent(4, 2)
    #Kutasy na glowie
    holoCreate(5)
    holoModel(5,”models/holograms/hq_rcylinder.mdl”)
    holoPos(5,holoEntity(2):pos()+vec(10,0,18))
    holoAng(5, ang(30,0,0))
    holoScale(5,vec(0.15,0.15,0.8))
    holoColor(5, vec(0,150,0))
    holoParent(5, 2)
    holoCreate(6)
    holoModel(6,”models/holograms/hq_rcylinder.mdl”)
    holoPos(6,holoEntity(2):pos()+vec(-10,0,18))
    holoAng(6, ang(-30,0,0))
    holoScale(6,vec(0.15,0.15,0.8))
    holoColor(6, vec(0,150,0))
    holoParent(6, 2)
    #Raczki – Zawiasy
    holoCreate(7)
    holoPos(7,holoEntity(1):pos()+vec(24,0,12))
    holoParent(7, 1)
    holoAlpha(7, 0)
    holoCreate(8)
    holoPos(8,holoEntity(1):pos()+vec(-24,0,12))
    holoParent(8, 1)
    holoAlpha(8, 0)
    #Raczki
    holoCreate(9)
    holoModel(9,”hqcylinder”)
    holoPos(9,holoEntity(1):pos()+vec(24,0,2))
    holoScale(9,vec(0.8,0.8,2.5))
    holoColor(9, vec(0,150,0))
    holoParent(9, 7)
    holoCreate(10)
    holoModel(10,”hqcylinder”)
    holoPos(10,holoEntity(1):pos()+vec(-24,0,2))
    holoScale(10,vec(0.8,0.8,2.5))
    holoColor(10, vec(0,150,0))
    holoParent(10, 8)
    #Do Czymania Rzeczy
    holoCreate(15)
    holoPos(15,holoEntity(1):pos()+vec(-24,0,-12))
    holoParent(15, 10)
    holoAlpha(15, 0)
    #Nozki – Zawiasy
    holoCreate(11)
    holoPos(11,holoEntity(1):pos()+vec(10,0,-15))
    holoParent(11, 1)
    holoAlpha(11, 0)
    holoCreate(12)
    holoPos(12,holoEntity(1):pos()+vec(-10,0,-15))
    holoParent(12, 1)
    holoAlpha(12, 0)
    #Nozki
    holoCreate(13)
    holoModel(13,”hqcylinder”)
    holoPos(13,holoEntity(1):pos()+vec(10,0,-25))
    holoScale(13,vec(0.8,0.8,2.5))
    holoColor(13, vec(0,150,0))
    holoParent(13, 11)
    holoCreate(14)
    holoModel(14,”hqcylinder”)
    holoPos(14,holoEntity(1):pos()+vec(-10,0,-25))
    holoScale(14,vec(0.8,0.8,2.5))
    holoColor(14, vec(0,150,0))
    holoParent(14, 12)
    #Random Movement Target
    holoCreate(20)
    holoPos(20,entity():pos())
    holoAlpha(20,0)
    Pos = entity():pos()
    Target = owner()
    AttackTarget = owner()
    CanHold = 1
    Holding = 0
    Speed = 3
    holoEntity(0):soundPlay(1,5,”vo/npc/male01/hi0?+randint(1,2)+”.wav”)
    soundPitch(1,150)
}
function number isGrounded() {
    R = rangerOffset(2,Pos+vec(0,0,0.5),vec(0,0,-1))
    if(R:distance()<=1) {return 1}
    else {return 0}
}
Angle+=15
if(Angle>360) {Angle-=360}
if(chatClk(owner())) {
    Said = owner():lastSaid():explode(” “)
    switch(Said[1, string]) {
        case “target”,
            for(I=0,players():count())
            {
                if(Said[2, string]:lower()==players()[I,entity]:name():lower():sub(0,Said[2,string]:length()))
                {
                    if(State==0) {
                        Target=players()[I,entity]
                    }
                    elseif(State==1) {
                        AttackTarget=players()[I,entity]
                    }
                    break
                }
            }
            hideChat(1)
        break
        case “combat”,
            State=1
            holoEntity(0):soundPlay(1,5,”vo/npc/male01/okimready0?+randint(1,3)+”.wav”)
            soundPitch(1,150)
            hideChat(1)
        break
        case “normal”,
            State=0
            holoEntity(0):soundPlay(1,5,”vo/npc/male01/ok01.wav”)
            soundPitch(1,150)
            hideChat(1)
        break
        case “spawning”,
            Spawning=!Spawning
            print(“Spawning rockets “+Spawning)
            hideChat(1)
        break
        case “speed”,
            Speed=Said[2, string]:toNumber()
            hideChat(1)
        break
        case “comeon”,
            RandomWalk = 0
            Target = owner()
            hideChat(1)
        break
        case “tp”,
            Pos=owner():pos()
            hideChat(1)
        break
        case “random”,
            RandomWalk = 1
            hideChat(1)
        break
        case “speed”,
            Speed=Said[2, string]:toNumber()
            hideChat(1)
        break
        default,
            hideChat(0)
        break
    }
}
if(State==0) {
    holoColor(3, vec(255,255,255))
    holoColor(4, vec(255,255,255))
}
elseif(State==1) {
    holoColor(3, vec(255,0,0))
    holoColor(4, vec(255,0,0))
}
holoAng(2,holoEntity(0):toWorld(ang(0,-holoEntity(0):bearing(Target:pos())+90,0)))
#Animacja raczek
HandAngle1 = ang(sin(Angle)*30*AnimVel,0,0)
if(!Holding) {
    HandAngle2 = ang(-sin(Angle)*30*AnimVel,0,0)
} else {
    HandAngle2 = ang(-sin(Angle)*5*AnimVel-50,0,0)
}
TempA = Fallspeed*20-80
if(Fallspeed<4) {TempA=0}
if(TempA>140) {TempA=140}
HandAngle1+=ang(0,0,TempA)
HandAngle2+=ang(0,0,-TempA)
if(ThrowAngle>1) {
    HandAngle2+=ang(-ThrowAngle*10+20,0,0)
}
holoAng(7,holoEntity(0):toWorld(HandAngle1))
holoAng(8,holoEntity(0):toWorld(HandAngle2))
#Animacja nozek
holoAng(11,holoEntity(0):toWorld(ang(-sin(Angle)*30*AnimVel,0,0)))
holoAng(12,holoEntity(0):toWorld(ang(sin(Angle)*30*AnimVel,0,0)))
if(clk(“HoldWait”)) {
    CanHold=1
}
if(clk(“Throw”)) {
    Holding=0
    ThrowAngle=0
    E:applyForce(holoEntity(10):forward()*E:mass()*randint(10,300))
    timer(“HoldWait”,1000)
}
if(State==1) {
    if(Holding==0) {
        findInSphere(holoEntity(0):pos(), 1500)
        findIncludeModel(“models/props_phx/mk-82.mdl”)
        Temp=find()
        if(Temp:type()==”prop_physics” && Temp:owner()==owner()) {
            Target=Temp
        }
    }
    if(Spawning) {
        Target=AttackTarget
    }
}
if(Holding) {
    if(E:type()==”gmod_wire_turret”) {
        E:setPos(holoEntity(15):pos()+holoEntity(15):forward()*5-holoEntity(15):up()*2)
        E:setAng(E:toWorld(-ang(E:elevation(Target:boxCenterW()),E:bearing(Target:boxCenterW()),E:angles():roll())))
        RS=rangerOffset(holoEntity(15):pos()+holoEntity(15):up()*10,Target:boxCenterW())
        if(RS:hit() && RS:entity()==Target) {
            Shoot=1
        }
        else {
            Shoot=0
        }
    }
    else {
        E:applyForce((holoEntity(15):pos()-E:pos()-E:vel()/8)*E:mass()*5)
    }
    if(E:pos():distance(holoEntity(0):pos())>100 || !E) {
        if(E:type()==”gmod_wire_turret”) {
            E:deleteWire(“Fire”)
        }
        Holding = 0
    }
    if(State==0 && E:type()!=”gmod_wire_turret”) {
        if(randint(100)==1) {
            timer(“Throw”, randint(0,400))
            CanHold=0
            ThrowAngle=1
        }
    }
    if(E:model()==”models/props_phx/mk-82.mdl”) {
        if(randint(100)==1 && CanHold) {
            Holding=0
            CanHold=0
            timer(“HoldWait”, 1000)
            E:applyForce((Target:pos()+vec(0,0,20)-E:pos())*60000)
            holoEntity(0):soundPlay(1,5,”vo/npc/male01/watchout.wav”) #vo/npc/male01/gotone01.wav
            soundPitch(1,150)
        }
    }
    if(changed(Holding) && Holding) {
        holoEntity(0):soundPlay(1,5,”vo/npc/male01/nice.wav”)
        soundPitch(1,150)
    }
    if(ThrowAngle>0) {ThrowAngle++}
}
elseif(CanHold) {
    if(Spawning==0) {
        findInSphere(holoEntity(0):pos(), 100)
        findIncludeClass(“prop_physics”)
        findIncludeClass(“gmod_wire_turret”)
        E=find()
        if(E:owner()==owner() && holoEntity(0):pos():distance(E:pos())<100 && !E:isFrozen()) {
            if(E:type()=="gmod_wire_turret") {
                E:createWire(entity(),"Fire","Shoot")
            }
            Holding = 1
            if(State==1) {
                Target=AttackTarget
            }
        }
    }
    else {
        if(randint(0,100)==1) {
            E=propSpawn("models/props_phx/mk-82.mdl",holoEntity(15):pos(),0)
            CanHold=0
            timer("HoldWait",1000)
            Holding = 1
            Target=AttackTarget
        }
    }
}
if(randint(0,1000)==1) {
    holoEntity(0):soundPlay(1,25,"vo/npc/male01/question0"+randint(1,8)+".wav")
    soundPitch(1,150)
}
holoPos(0, Pos)
holoAng(0,holoEntity(0):toWorld(ang(0,-holoEntity(0):bearing(Target:pos()),0)))
if(vec(Pos:x(),Pos:y(),0):distance(vec(Target:pos():x(),Target:pos():y(),0))>100) {
    R=rangerOffset(30,holoEntity(1):pos(), holoEntity(0):forward())
    if(R:distance()>28) {
        Pos+=holoEntity(0):forward()*Speed
    }
}
if(State==0) {
    if(RandomWalk) {
        if(randint(0,150)==1 | vec(Target:pos():x(),Target:pos():y(),0):distance(vec(owner():pos():x(),owner():pos():y(),0))<100) {
            holoPos(20, owner():pos()-vec(400,400,400)+randvec(0,800))
            Target = holoEntity(20)
        }
    }
}
R = rangerOffset(10,Pos+vec(0,0,10),vec(0,0,-1))
Pos = R:position()
if(abs((Pos-LastPos):length())>0.0001) {
    if(AnimVel<1) {
        AnimVel+=0.1
    }
}
else {
    if(AnimVel>0) {
        AnimVel-=0.1
    }
}
LastPos = Pos
if(isGrounded()) {
   Fallspeed=0
}
else {
    Pos-=vec(0,0,1)*Fallspeed
    Fallspeed+=0.5
}