class 2 default_use_db_maker : default_maker
{
parameter:
	string	maker_name = "";

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

	EventHandler ON_DB_NPC_INFO(loaded_def,record0,i0)
	{
		if( record0.is_alive )
		{
			if( myself::IncreaseTotal(1) )
			{
				loaded_def::IncCount(1);
				loaded_def::SetDBLoaded(1);
				loaded_def::SpawnEx(1,0,record0.x,record0.y,record0.z,0,record0.time,record0.party_id,record0.db_value);
			}
		}
		else if( myself::IncreaseTotal(1) )
		{
			loaded_def::IncCount(1);
			if( record0.death_time == 0 )
			{
				loaded_def::Spawn(loaded_def.def_count,0);
			}
			else
			{
				i0 = ( record0.death_time + loaded_def.respawn_time );
				loaded_def::RegToRespawnTimer(i0);
			}
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,i0,i1,maker0)
	{
		i0 = myself::DecreaseTotal(1);
		deleted_def::DecCount(1);
		deleted_def::SetDBLoaded(0);
		if( i0 == 0 )
		{
			maker0 = gg::GetNpcMaker(maker_name);
			if( gg::IsNull(maker0) == 0 )
			{
				gg::SendMakerScriptEvent(maker0,1001,0,0);
			}
		}
		if( myself::IncreaseTotal(1) )
		{
			deleted_def::IncCount(1);
			deleted_def::Spawn(1,deleted_def.respawn_time);
		}
	}

}
