Jump to content
  • 0

Help With This Piece Of Code Please


b0rto

Question

hello maxcheaters i added a piece of code that i found here:  http://www.maxcheaters.com/topic/171501-helprandom-spawns/ for random respawns after death, all seems work fine but when i tested in my server only get the first random spawn config, if someone can give me a hand I will be grateful, because i have death my mind xD

 

here the code requestrestartpoint.java:


			case 27: // to jail
				if (!activeChar.isInJail()) return;
				loc = new Location(-114356, -249645, -2984);
				break;
				
			default:
				
				if(activeChar.isInsideZone((byte) 23) && Config.CUSTOM_RANDOM_RESPAWN_AFTER_DEATH)
					
				    loc = new Location(getRandomArray()[0], getRandomArray()[1], getRandomArray()[2]);
					else
					loc = MapRegionManager.getInstance().getTeleToLocation(activeChar, MapRegionManager.TeleportWhereType.Town);
				break;
		}
		// Teleport and revive
		activeChar.setInstanceId(instanceId);
		activeChar.setIsIn7sDungeon(false);
		activeChar.setIsPendingRevive(true);
		activeChar.teleToLocation(loc, true);

	}
	private static int[][] RANDOM_LOCATIONS =
	{
		{Config.LOCATIONX,Config.LOCATIONY,Config.LOCATIONZ},
		{Config.LOCATION2X,Config.LOCATION2Y,Config.LOCATION2Z},
		{Config.LOCATION3X,Config.LOCATION3Y,Config.LOCATION3Z},
		{Config.LOCATION4X,Config.LOCATION4Y,Config.LOCATION4Z},
		{Config.LOCATION5X,Config.LOCATION5Y,Config.LOCATION5Z},
		{Config.LOCATION6X,Config.LOCATION6Y,Config.LOCATION6Z}
	};
	
	public static int[] getRandomArray()
	{

		return RANDOM_LOCATIONS[Rnd.get(RANDOM_LOCATIONS.length)];

	}

i try to fix it with this line but my eclipse says unreachable code and no solutions availables:

return RANDOM_LOCATIONS[Rnd.get(1, 6)];

thanks in advance.

Edited by b0rto
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

I believe this line

return RANDOM_LOCATIONS[Rnd.get(1, 6)]

doesn't work because you are generating random from 1 to 6(1,2,3,4,5,6) and while array is counted from zero (0,1,2,3,4,5  --  6Elements).

Link to comment
Share on other sites

  • 0

hello thanks for answer me this line dont work for my eclipse, says unreachable code:

 

return RANDOM_LOCATIONS[Rnd.get(6)];

 

also i try with this line and eclipse accept it but anyway random respawns dont work :/

 

return RANDOM_LOCATIONS[Rnd.get(0, 5)];

 

if someone know where is the problem..because always get the first random respawn filled in configs, thanks in advance.

 

 

Link to comment
Share on other sites

  • 0

Instead of int[][], use Location[]. It will save you time, will shortcut the code and actually will fix an issue you got with your current code (atm you are randomizing THREE TIMES to get one location, one time for X, another for Y and last for Z).

private static Location[] RANDOM_LOCATIONS =
{
	new Location(Config.LOCATIONX,Config.LOCATIONY,Config.LOCATIONZ),
	blablabla
};
	
public static Location getRandomLocation()
{
	return RANDOM_LOCATIONS[Rnd.get(RANDOM_LOCATIONS.length)];
} 

And finally

loc = getRandomLocation(); 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • 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