Jump to content
  • 0

[REQUEST] L2Monster return to spawn point like L2Raid


Question

Posted

 

 

As title say i need same code for L2Monsters to return at spawn point like L2Raids when i attacj to 1 monster after X distance return to spawn point with current HP

what i have to fix?

Recommended Posts

  • 0
Posted

i add this code but same problem

 

/**
 * Return home.
 */
public void returnHome()
 {
  ThreadPoolManager.getInstance().scheduleAi(new Runnable() {
   @Override
   public void run()
   {
    L2Spawn mobSpawn = getSpawn();
    if(!isInCombat() && !isAlikeDead() && !isDead() && mobSpawn != null && !isInsideRadius(mobSpawn.getLocx(), mobSpawn.getLocy(), Config.MAX_DRIFT_RANGE, false))
    {
     teleToLocation(mobSpawn.getLocx(), mobSpawn.getLocy(), mobSpawn.getLocz(), false);
    }
    mobSpawn = null;
   }
   
  }, 1000);
 }
protected void startMaintenanceTask()
{
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable() {
		@Override
		public void run()
		{
			checkAndReturnToSpawn();
		}
	}, 3000, getMaintenanceInterval()+Rnd.get(5000));
}
protected void checkAndReturnToSpawn()
{
	if (isDead() || isMovementDisabled())
		return;

	final L2Spawn spawn = getSpawn();
	if (spawn == null)
		return;

	final int spawnX = spawn.getLocx();
	final int spawnY = spawn.getLocy();
	final int spawnZ = spawn.getLocz();

	if (!isInCombat() && !isMovementDisabled())
	{
		if (!isInsideRadius(spawnX, spawnY, spawnZ, Math.max(1000, 200), true, false))
			teleToLocation(spawnX, spawnY, spawnZ);
	}
}

 

 

i use L2jfrozen last revision

 

forzen have one config for that but dont work.

 

  • 0
Posted

Copy/paste, find what code makes Raid Bosses return and just simple change it for mobs.. L2RaidBossInstance with L2MonsterInstance.

Or smth like that if you get mt mind...

  • 0
Posted

I can't describe how retarded this code is...First of all you told that what you wanted is when the player runs and the monsters get out of the x,y radius should be teleported back, well with that check !isInCombat() if the monster is following the player and hitting him he won't be teleported back cause he is in combat...

  • 0
Posted

I can't describe how retarded this code is...First of all you told that what you wanted is when the player runs and the monsters get out of the x,y radius should be teleported back, well with that check !isInCombat() if the monster is following the player and hitting him he won't be teleported back cause he is in combat...

 

Thats the code from L2RaidbossInstance idk what u have in your pack but it works as it should...

 

the !isInCombat(); on this code, makes the NPC teleport when u run but u dont attack it, if you want the Npc to teleport back even if its under attack just remove the method

  • 0
Posted

That behavior is located in L2AttackableAI, and it is part of thinkAttack method. If you want "retail" system where mob runs back to his location.

 

 

// Order to the L2MonsterInstance to random walk (1/100)
	else if(!(npc instanceof L2ChestInstance) && npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0)
	{
		int x1, y1, z1;

		// If NPC with random coord in territory
		if(npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
		{
			// If NPC with random fixed coord, don't move
			if(TerritoryTable.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0)
				return;

			// Calculate a destination point in the spawn area
			int p[] = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocation());
			x1 = p[0];
			y1 = p[1];
			z1 = p[2];

			// Calculate the distance between the current position of the L2Character and the target (x,y)
			double distance2 = _actor.getPlanDistanceSq(x1, y1);

			if(distance2 > Config.MAX_DRIFT_RANGE * Config.MAX_DRIFT_RANGE)
			{
				npc.setisReturningToSpawnPoint(true);
				float delay = (float) Math.sqrt(distance2) / Config.MAX_DRIFT_RANGE;
				x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
				y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
			}
			else
			{
				npc.setisReturningToSpawnPoint(false);
			}

		}
		else
		{
			if(Config.MONSTER_RETURN_DELAY > 0 && npc instanceof L2MonsterInstance && !npc.isAlikeDead() && !npc.isDead() && npc.getSpawn() != null && !npc.isInsideRadius(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), Config.MAX_DRIFT_RANGE, false))
			{
				((L2MonsterInstance) _actor).returnHome();
			}

			// If NPC with fixed coord
			x1 = npc.getSpawn().getLocx() + Rnd.nextInt(Config.MAX_DRIFT_RANGE * 2) - Config.MAX_DRIFT_RANGE;
			y1 = npc.getSpawn().getLocy() + Rnd.nextInt(Config.MAX_DRIFT_RANGE * 2) - Config.MAX_DRIFT_RANGE;
			z1 = npc.getZ();
		}

		//_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
		// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
		moveTo(x1, y1, z1);
	}

	npc = null;

	return;

}

 

i find this, i wanna monster when run a X distance teleport back to spawn point..

  • 0
Posted

Thats the code from L2RaidbossInstance idk what u have in your pack but it works as it should...

 

the !isInCombat(); on this code, makes the NPC teleport when u run but u dont attack it, if you want the Npc to teleport back even if its under attack just remove the method

i know it dude i said it is retarded for what he is asking...

  • 0
Posted

Frozen Config have this

 

# The maximum deviation from the point of Spawn mobs
MaxDriftRange = 200

 

 

here is 2 codes for that but no1 works

 

this is in L2attack

 

// Order to the L2MonsterInstance to random walk (1/100)
	else if(!(npc instanceof L2ChestInstance) && npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0)
	{
		int x1, y1, z1;

		// If NPC with random coord in territory
		if(npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
		{
			// If NPC with random fixed coord, don't move
			if(TerritoryTable.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0)
				return;

			// Calculate a destination point in the spawn area
			int p[] = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocation());
			x1 = p[0];
			y1 = p[1];
			z1 = p[2];

			// Calculate the distance between the current position of the L2Character and the target (x,y)
			double distance2 = _actor.getPlanDistanceSq(x1, y1);

			if(distance2 > Config.MAX_DRIFT_RANGE * Config.MAX_DRIFT_RANGE)
			{
				npc.setisReturningToSpawnPoint(true);
				float delay = (float) Math.sqrt(distance2) / Config.MAX_DRIFT_RANGE;
				x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
				y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
			}
			else
			{
				npc.setisReturningToSpawnPoint(false);
			}

		}
		else
		{
			if(Config.MONSTER_RETURN_DELAY > 0 && npc instanceof L2MonsterInstance && !npc.isAlikeDead() && !npc.isDead() && npc.getSpawn() != null && !npc.isInsideRadius(npc.getSpawn().getLocx(), npc.getSpawn().getLocy(), Config.MAX_DRIFT_RANGE, false))
			{
				((L2MonsterInstance) _actor).returnHome();
			}

			// If NPC with fixed coord
			x1 = npc.getSpawn().getLocx() + Rnd.nextInt(Config.MAX_DRIFT_RANGE * 2) - Config.MAX_DRIFT_RANGE;
			y1 = npc.getSpawn().getLocy() + Rnd.nextInt(Config.MAX_DRIFT_RANGE * 2) - Config.MAX_DRIFT_RANGE;
			z1 = npc.getZ();
		}

		//_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
		// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
		moveTo(x1, y1, z1);
	}

	npc = null;

	return;

}

 

this in l2monsterinstance

 

	/**
 * Return home.
 */
public void returnHome()
{
	ThreadPoolManager.getInstance().scheduleAi(new Runnable() {
		@Override
		public void run()
		{
			L2Spawn mobSpawn = getSpawn();
			if(!isInCombat() && !isAlikeDead() && !isDead() && mobSpawn != null && !isInsideRadius(mobSpawn.getLocx(), mobSpawn.getLocy(), Config.MAX_DRIFT_RANGE, false))
			{
				teleToLocation(mobSpawn.getLocx(), mobSpawn.getLocy(), mobSpawn.getLocz(), false);
			}
			mobSpawn = null;
		}
	}, Config.MONSTER_RETURN_DELAY * 1000);
}

  • 0
Posted

Already answered you dude remove this !isInCombat() and try again although it could be better handled in l2attackable as tk said

  • 0
Posted

As I said, it's part of thinkAttack() method. At top beginning you got a possibility the AI is setted on active statut, notably if the Ai hasn't anymore target, or timer runs out without being able to attack.

 

Then, on thinkActive(), you got the code to send back monsters to his location. On aCis, he runs from one point to another. Just use latest L2J sources to get overall code, and edit following your wishes (instead of moveTo(), use teleToLocation()).

 

You got notably isReturningToSpawnPoint() / setIsReturningToSpawnPoint() methods.

  • Thanks 1
  • 0
Posted

Guys i spend to many hours for this shit :/ my experience is low on l2j and until do compile and test compiel and test it will take a year to fix this code ..:/

 

 

i remove that borinio same exist as tryskel say i have to check on attack files but i dont know... i m searching on l2j to find solution for this fail.

 

if some1 have any idea help me to finish this shit

  • 0
Posted

As I said, it's part of thinkAttack() method. At top beginning you got a possibility the AI is setted on active statut, notably if the Ai hasn't anymore target, or timer runs out without being able to attack.

 

Then, on thinkActive(), you got the code to send back monsters to his location. On aCis, he runs from one point to another. Just use latest L2J sources to get overall code, and edit following your wishes (instead of moveTo(), use teleToLocation()).

 

You got notably isReturningToSpawnPoint() / setIsReturningToSpawnPoint() methods.

 

i find this

 

 

// Order to the L2MonsterInstance to random walk (1/100)
	else if (npc.getSpawn() != null && Rnd.nextInt(RANDOM_WALK_RATE) == 0 
			&& !_actor.isRndWalk())
	{
		int x1, y1, z1;
		final int range = Config.MAX_DRIFT_RANGE;



		// If NPC with random coord in territory
		if (npc.getSpawn().getLocx() == 0 && npc.getSpawn().getLocy() == 0)
		{
			// Calculate a destination point in the spawn area
			int p[] = TerritoryTable.getInstance().getRandomPoint(npc.getSpawn().getLocation());
			x1 = p[0];
			y1 = p[1];
			z1 = p[2];

			// Calculate the distance between the current position of the L2Character and the target (x,y)
			double distance2 = _actor.getPlanDistanceSq(x1, y1);

			if (distance2 > (range + range) * (range + range))
			{
				npc.setisReturningToSpawnPoint(true);
				float delay = (float) Math.sqrt(distance2) / range;
				x1 = _actor.getX() + (int) ((x1 - _actor.getX()) / delay);
				y1 = _actor.getY() + (int) ((y1 - _actor.getY()) / delay);
			}

			// If NPC with random fixed coord, don't move (unless needs to return to spawnpoint)
			if (TerritoryTable.getInstance().getProcMax(npc.getSpawn().getLocation()) > 0 && !npc.isReturningToSpawnPoint())
				return;
		}
		else
		{
			// If NPC with fixed coord
			x1 = npc.getSpawn().getLocx();
			y1 = npc.getSpawn().getLocy();
			z1 = npc.getSpawn().getLocz();

			if (!_actor.isInsideRadius(x1, y1, z1, range + range, true, false))
				npc.setisReturningToSpawnPoint(true);
			else
			{
				x1 += Rnd.nextInt(range * 2) - range;
				y1 += Rnd.nextInt(range * 2) - range;
				z1 = npc.getZ();
			}
		}

		//_log.config("Curent pos ("+getX()+", "+getY()+"), moving to ("+x1+", "+y1+").");
		// Move the actor to Location (x,y,z) server side AND client side by sending Server->Client packet CharMoveToLocation (broadcast)
		moveTo(x1, y1, z1);
	}
}

 

i have only with red line this

 

isRndWalk

 

i remove code all code for walk and monsters walk like crazy xd

but i test the code for return and nothing happend again follow ..

 

can some1 edit this code for frozen? .. :/

  • 0
Posted

Bump no solution : /

 

 

Guys if u know this code help me here i cant to more test already 30 compiles , i dont know i try everything .. :/

 

Guest
This topic is now closed to further replies.


  • Posts

    • ⚔️ The Grand Opening Has Arrived! ⚔️ In just a few hours the gate to the eternal battlefield will be open and the war between Order and Chaos will be set once again ! Its time to claim your destiny 🔥 👉 Register now and join the fight today! 🌐 https://l2ovc.com
    • Don’t miss the new Telegram gifts with our Telegram Stars purchasing bot! A great opportunity to invest in a stable digital asset at an early stage while the market is still forming. Buy other existing gifts in the official store using Telegram Stars, pay for subscriptions, donate to games and projects, pay for Premium subscriptions, and react to messages in channels! Low prices, multiple payment options, and other cool unique features! ⚡ Try it today — SOCNET STARS BOT ⚡ Active links to SOCNET stores: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store via Telegram messenger. ⭐ Telegram Stars Purchase Bot: Go – fast and profitable way to buy stars in Telegram. SMM Panel: Go – promote your social media accounts. We present to you the current list of promotions and special offers for purchasing our products and services: 1️⃣ Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, bot) in October! You can also use the promo code SOCNET (15% discount) for your first purchase. 2️⃣ Get $1 on your store balance or a 10–20% discount — just write your username after registration on our website using the template: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3️⃣ Get $1 for your first SMM Panel trial — simply open a ticket titled “Get Trial Bonus” on our website (Support). 4️⃣ Weekly ⭐ Telegram Stars giveaways in our Telegram channel and in our Telegram Stars bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Don’t miss the new Telegram gifts with our Telegram Stars purchasing bot! A great opportunity to invest in a stable digital asset at an early stage while the market is still forming. Buy other existing gifts in the official store using Telegram Stars, pay for subscriptions, donate to games and projects, pay for Premium subscriptions, and react to messages in channels! Low prices, multiple payment options, and other cool unique features! ⚡ Try it today — SOCNET STARS BOT ⚡ Active links to SOCNET stores: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store via Telegram messenger. ⭐ Telegram Stars Purchase Bot: Go – fast and profitable way to buy stars in Telegram. SMM Panel: Go – promote your social media accounts. We present to you the current list of promotions and special offers for purchasing our products and services: 1️⃣ Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, bot) in October! You can also use the promo code SOCNET (15% discount) for your first purchase. 2️⃣ Get $1 on your store balance or a 10–20% discount — just write your username after registration on our website using the template: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3️⃣ Get $1 for your first SMM Panel trial — simply open a ticket titled “Get Trial Bonus” on our website (Support). 4️⃣ Weekly ⭐ Telegram Stars giveaways in our Telegram channel and in our Telegram Stars bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Don’t miss the new Telegram gifts with our Telegram Stars purchasing bot! A great opportunity to invest in a stable digital asset at an early stage while the market is still forming. Buy other existing gifts in the official store using Telegram Stars, pay for subscriptions, donate to games and projects, pay for Premium subscriptions, and react to messages in channels! Low prices, multiple payment options, and other cool unique features! ⚡ Try it today — SOCNET STARS BOT ⚡ Active links to SOCNET stores: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store via Telegram messenger. ⭐ Telegram Stars Purchase Bot: Go – fast and profitable way to buy stars in Telegram. SMM Panel: Go – promote your social media accounts. We present to you the current list of promotions and special offers for purchasing our products and services: 1️⃣ Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, bot) in October! You can also use the promo code SOCNET (15% discount) for your first purchase. 2️⃣ Get $1 on your store balance or a 10–20% discount — just write your username after registration on our website using the template: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3️⃣ Get $1 for your first SMM Panel trial — simply open a ticket titled “Get Trial Bonus” on our website (Support). 4️⃣ Weekly ⭐ Telegram Stars giveaways in our Telegram channel and in our Telegram Stars bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • 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