#SEQUENCE "spawn";
# var func = nop;
  func = if(or(geq(this_get_attribute("spawned"), this_get_attribute("spawn_init")), eq(avar("spawn_off"), 1), geq(this_get_attribute("spawn_total"), this_get_attribute("spawn_max"))), seq_jump, nop);
  func("cycle");
// Fade into the spawning anim.
# animate( "prep_spawn", 1, 1, 0.2 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.5 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.3 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 2.4 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 3.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 4.0 );
  wait( 0.05, 1 );
# sound_play("monsters/raise.wav", this_x(), this_y(), this_z() );
  animate( "prep_spawn", 1, 1, 5.5 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 8.0 );
  wait( 0.05, 1 );

// Do the spawning anim.
# wait( 0.92, 1 );
  animate( "spawn", 1, 1, 100.0 );
# char_clone(avar(add("monster_type", num_to_str(this_get_attribute("spawn_id")))), add(this_x(), rand(-4,4)), add(this_y(), rand(4,8)));
# char_clone(avar(add("monster_typeb", num_to_str(this_get_attribute("spawn_id")))), add(this_x(), rand(-4,4)), add(this_y(), rand(4,8)));
# wait( 0.97 );

// Fade out the spawning anim.
# animate( "prep_spawn", 1, 1, 5.5 );
  animate( "spawn", 1, 1, 0.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 4.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 3.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 2.4 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.3 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.5 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.2 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.0 );
  wait( 0.05, 1 );

// Wait for good measure.
//# wait( 4 );
# this_set_attribute("spawned", add(this_get_attribute("spawned"), 1));
  this_set_attribute("spawn_total", add(this_get_attribute("spawn_total"), 1));
  avar("total_spawn", add(avar("total_spawn"), 1));  
# wait( 0.01 );

#SEQUENCE "cycle";
# wait( this_get_attribute("spawn_r_wait") );
# this_set_attribute("spawned", 0);
# seq_jump("spawn");
