@LabelIndex 420146
@StringIndex 0
class 1 default_use_db_maker : default_maker {
parameter:
	int	on_start_spawn = 1;
	int	on_start_spawn_child = 0;
	string	maker_name = "default_use_db_maker_default";

handler:
	EventHandler ON_START(i0,def0) {
		if( on_start_spawn == 0 ) {
			return;
		}
		for(i0 = 0; i0 < myself.def_count; i0++) {
			def0 = myself::GetSpawnDefine(i0);
			if( gg::IsNull(def0) == 0 && def0.has_dbname ) {
				def0::LoadDBNpcInfo(1010);
			}
		}
	}

	EventHandler ON_DB_NPC_INFO(loaded_def,record0,i0,maker0) {
		if( record0.is_alive ) {
			if( loaded_def.respawn_time != 0 && myself::AtomicIncreaseTotal(loaded_def,1,1) ) {
				loaded_def::SetDBLoaded(1);
				loaded_def::SpawnEx(1,0,record0.x,record0.y,record0.z,0,record0.hp,record0.mp,record0.db_value);
			}
		} else if( loaded_def.respawn_time != 0 && myself::AtomicIncreaseTotal(loaded_def,1,1) ) {
			if( record0.death_time == 0 ) {
				loaded_def::Spawn2(loaded_def.total,0,0);
			} else {
				i0 = ( record0.death_time + loaded_def.respawn_time );
				loaded_def::RegToRespawnTimer(i0);
				if( on_start_spawn_child == 1 ) {
					maker0 = gg::GetNpcMaker(maker_name);
					if( gg::IsNull(maker0) == 0 ) {
						gg::SendMakerScriptEvent(maker0,1001,0,0);
					}
				}
			}
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,i0,i1,maker0,reply) {
		deleted_def::SetDBLoaded(0);
		if( deleted_def.respawn_time != 0 && myself::AtomicIncreaseTotal(deleted_def,1,1) ) {
			deleted_def::Spawn2(1,deleted_def.respawn_time,deleted_def.respawn_rand);
		}
	}

	EventHandler ON_ALL_NPC_DELETED(maker0) {
		maker0 = gg::GetNpcMaker(maker_name);
		if( gg::IsNull(maker0) == 0 ) {
			gg::SendMakerScriptEvent(maker0,1001,0,0);
		}
	}

}
