@name NPC Spawner
@inputs 
@outputs P1ID NPC:string Count Total:array Stop
@persist P1:entity NPCS:array NPC:string Stop Z

#findInSphere(entity():pos(),50000)
#findIncludeClass(NPC)
#findExcludeClass("player")
#findExcludeClass("prop")
#
#Total=findToArray()
for(C=1,Total:count()){
    if(!Total[C,entity]:isAlive()){Total:remove(C)}
}
Count=Total:count()


Respawn=10*1000
Max=15

Wave=Respawn/1000
O=owner()
runOnChat(1)
K=chatClk()
Chat=O:lastSaid()

Com="NPC"
Die="kill"
Break=" "

COM=Chat:find(Com)
DIE=Chat:find(Die)
BRK=Chat:find(Break)

if(COM&K){
    if(BRK){
        N=Chat:explode(Break)[2,string]:toNumber()
        NPC=NPCS[N,string]
        print("Spawning "+Max+" "+NPC+" every "+Wave+" Seconds!")
        #stoptimer("wave")
        timer("wave",100)
    }
    if(DIE){
        print("Self Destructing "+NPCS[N,string]+" Spawner chip")
        selfDestruct()
    }
}

if(first()){
#animals
    NPCS:pushString("npc_pigeon")
    NPCS:pushString("npc_seagull")
    NPCS:pushString("npc_seagull")
    NPCS:pushString("npc_crow")
    NPCS:pushString("npc_ichthyosaur")
#humans
    NPCS:pushString("npc_fisherman")
    NPCS:pushString("npc_monk")
    NPCS:pushString("npc_kleiner")
    NPCS:pushString("npc_magnusson")
    NPCS:pushString("npc_eli")
    NPCS:pushString("npc_gman")
    NPCS:pushString("npc_citizen")
    NPCS:pushString("npc_breen")
    NPCS:pushString("npc_alyx")
    NPCS:pushString("npc_dog")
    NPCS:pushString("npc_vortigaunt")
    NPCS:pushString("npc_mossman")
    NPCS:pushString("npc_cranedriver")
#Combine
    NPCS:pushString("npc_manhack")
    NPCS:pushString("npc_strider")
    NPCS:pushString("npc_combine_s")
    NPCS:pushString("npc_rollermine")
    NPCS:pushString("npc_hunter")
    NPCS:pushString("npc_metropolice")
    NPCS:pushString("npc_stalker")
    NPCS:pushString("npc_turret_floor")
    NPCS:pushString("combine_mine")
    NPCS:pushString("npc_cscanner")
    NPCS:pushString("npc_crabsynth")
    NPCS:pushString("npc_mortarsynth")
    NPCS:pushString("npc_sniper")
    NPCS:pushString("npc_helicopter")
    NPCS:pushString("npc_turret_ground")
    NPCS:pushString("npc_turret_ceiling")
    NPCS:pushString("npc_combinegunship")



#Antlions
    NPCS:pushString("npc_antlionguard")
    NPCS:pushString("npc_antlion_worker")
    NPCS:pushString("npc_antlion")
    NPCS:pushString("npc_antlion_grub")
#Zombies
    NPCS:pushString("npc_poisonzombie")
    NPCS:pushString("npc_fastzombie")
    NPCS:pushString("npc_zombine")
    NPCS:pushString("npc_zombie")
    NPCS:pushString("npc_headcrab_black")
    NPCS:pushString("npc_headcrab")
    NPCS:pushString("npc_headcrab_fast")
    NPCS:pushString("npc_zombie_torso")
#print list
    printTable(NPCS)

}


#if(!K){


    if(clk("wave")&NPC){Stop=0}
    #if(Max>=Count){Stop=1}
    if(!Stop){
        Z = entity():pos():z()*2+5
        for(C=1,Max){
            D = random(0,360)
            R = random(20,500)
            
            Spawn = entity():pos()-vec(R*cos(D),R*sin(D),Z)
            
         
            if (Count<=Max & !Stop & Spawn:isInWorld()) { 
            P1 = npcSpawn(NPC,Spawn)
            timer("wave",Respawn)
            Total:pushEntity(P1)
            #P1ID=P1:id()
            #entity(P1ID):npcRelationship("player","fear",99)
            #Feelings = entity(P1ID):npcDisp(entity():owner())
            }
        }
    Stop=1
    }
    

#}

