Jump to content
  • 0

Help about Random Spawn


lamle1112

Question

So as title of Topic. I want to make random spawn mobs when the character exit peacezone

 

I have added

 

+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
...
protected void onExit(L2Character character)
{
character.setInsideZone(L2Character.ZONE_PEACE, false);
+	int loc_X = character.getX();
+	int loc_Y = character.getY();
+	int loc_Z = character.getZ();
addSpawn(29001,loc_X,loc_Y ,loc_Z ,306,False,0,False,0);
}

 

But That's problem . I don't know how to spawn mob near that character >"<

Help me!

Thanks.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Took it from handlers/admincommandhandlers/adminspawn

		L2NpcTemplate template1;
	if (monsterId.matches("[0-9]*"))
	{
		//First parameter was an ID number
		int monsterTemplate = Integer.parseInt(monsterId);
		template1 = NpcTable.getInstance().getTemplate(monsterTemplate);
	}
	else
	{
		//First parameter wasn't just numbers so go by name not ID
		monsterId = monsterId.replace('_', ' ');
		template1 = NpcTable.getInstance().getTemplateByName(monsterId);
	}

	try
	{
		L2Spawn spawn = new L2Spawn(template1);
		if (Config.SAVE_GMSPAWN_ON_CUSTOM)
			spawn.setCustom(true);
		spawn.setLocx(target.getX());
		spawn.setLocy(target.getY());
		spawn.setLocz(target.getZ());
		spawn.setAmount(mobCount);
		spawn.setHeading(activeChar.getHeading());
		spawn.setRespawnDelay(respawnTime);
		if (activeChar.getInstanceId() > 0)
		{
			spawn.setInstanceId(activeChar.getInstanceId());
			permanent = false;
		}
		else
			spawn.setInstanceId(0);
		// TODO add checks for GrandBossSpawnManager
		if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcid()))
			activeChar.sendMessage("You cannot spawn another instance of " + template1.name + ".");
		else
		{
			if (RaidBossSpawnManager.getInstance().getValidTemplate(spawn.getNpcid()) != null)
			{
				spawn.setRespawnMinDelay(43200);
				spawn.setRespawnMaxDelay(129600);
				RaidBossSpawnManager.getInstance().addNewSpawn(spawn, 0, template1.baseHpMax, template1.baseMpMax, permanent);
			}
			else
			{
				SpawnTable.getInstance().addNewSpawn(spawn, permanent);
				spawn.init();
			}
			if (!permanent)
				spawn.stopRespawn();
			activeChar.sendMessage("Created " + template1.name + " on " + target.getObjectId());
		}
	}
	catch (Exception e)
	{
		activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TARGET_CANT_FOUND));
	}

 

Hope it seems helpful, I won't make it to your needs, just to learn and explore yourself in java.

 

Also if you want modify the values 50 100 when you choose randomOffset "true" (means close to x,y,z points you entered)

 

	public L2Npc addSpawn(int npcId, int x, int y, int z, int heading, boolean randomOffset, long despawnDelay, boolean isSummonSpawn, int instanceId)
{
	L2Npc result = null;
	try
	{
		L2NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
		if (template != null)
		{
			// Sometimes, even if the quest script specifies some xyz (for example npc.getX() etc) by the time the code
			// reaches here, xyz have become 0!  Also, a questdev might have purposely set xy to 0,0...however,
			// the spawn code is coded such that if x=y=0, it looks into location for the spawn loc!  This will NOT work
			// with quest spawns!  For both of the above cases, we need a fail-safe spawn.  For this, we use the
			// default spawn location, which is at the player's loc.
			if ((x == 0) && (y == 0))
			{
				_log.log(Level.SEVERE, "Failed to adjust bad locks for quest spawn!  Spawn aborted!");
				return null;
			}
			if (randomOffset)
			{
				int offset;

				offset = Rnd.get(2); // Get the direction of the offset
				if (offset == 0)
				{
					offset = -1;
				} // make offset negative
				offset *= Rnd.get(50, 100);
				x += offset;

				offset = Rnd.get(2); // Get the direction of the offset
				if (offset == 0)
				{
					offset = -1;
				} // make offset negative
				offset *= Rnd.get(50, 100);
				y += offset;
			}
			L2Spawn spawn = new L2Spawn(template);
			spawn.setInstanceId(instanceId);
			spawn.setHeading(heading);
			spawn.setLocx(x);
			spawn.setLocy(y);
			spawn.setLocz(z + 20);
			spawn.stopRespawn();
			result = spawn.spawnOne(isSummonSpawn);

			if (despawnDelay > 0)
				result.scheduleDespawn(despawnDelay);

			return result;
		}
	}
	catch (Exception e1)
	{
		_log.warning("Could not spawn Npc " + npcId);
	}

	return null;
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...