Jump to content
  • 0

[REQUEST] L2Monster return to spawn point like L2Raid


GsL

Question

Recommended Posts

  • 0

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.

 

Link to comment
Share on other sites

  • 0

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...

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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..

Link to comment
Share on other sites

  • 0

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...

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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? .. :/

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


×
×
  • Create New...