Jump to content
  • 0

Question

Posted

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.

3 answers to this question

Recommended Posts

  • 0
Posted

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;
}

Guest
This topic is now closed to further replies.


  • Posts

    • WTB GRACIA FINAL INTERFACE
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear partners! At the moment we are in great need of the following positions: — Snapchat old and new accounts | With snapscores | Geo: Europe/USA | Full access via email/phone number — Reddit old (brute or hacked origin, self-registered) accounts with post and comment karma from 100 to 100,000+ | Full email access included — LinkedIn old accounts with real connections | Geo: Europe/USA | Full email access + active 2FA password — Instagram old accounts (2010–2023) | Full email access (possibly with active 2FA password) — Facebook old accounts (2010–2023) | Full email access (possibly with active 2FA password) | With friends or without friends | Geo: Europe/USA/Asia — Threads accounts | Full email access (possibly with active 2FA password) — TikTok/Facebook/Google ADS Agency advertising accounts — Email accounts: mail.ru, yahoo.com, gazeta.pl, gmx.ch / gmx.de / gmx.net (BUT NOT gmx.com) — Google ADS Manual Farm accounts (verified via email and phone number) | GEO: USA/Europe, mostly USA. — WhatsApp OLD Accounts — Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! We are also ready to consider other partnership and collaboration options. Active links to our projects: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • 冬天是享受优惠、省钱的好时机。 首次下单时使用促销码 SOCNET 即可获得 15% 折扣 ,适用于全场商品! 前往商店(网站) 前往商店(Telegram 机器人)
    • Winter is the time to save with benefits. Activate the promo code SOCNET on your first order and get a 15% discount on the entire assortment! Go to the store (website) Go to the store (Telegram bot)
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock