Jump to content
  • 0

Help With This Piece Of Code Please


Question

Posted (edited)

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

4 answers to this question

Recommended Posts

  • 0
Posted

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

  • 0
Posted

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.

 

 

  • 0
Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • 亲爱的合作伙伴! 目前我们非常需要以下项目: ➡ WhatsApp 老账户 ➡ Twitter 带粉丝和帖子账户(老账户) 请通过以下联系方式与我们联系。我们很高兴与您合作! 我们项目的有效链接: 数字商品商店(网站): 前往 商店 Telegram 机器人: 前往 – 通过 Telegram 信使方便访问商店。 虚拟号码服务: 前往 用于购买 Telegram Stars 的 Telegram 机器人: 前往 – 在 Telegram 中快速且优惠地购买 Stars。 SMM 面板: 前往 – 推广您的社交媒体账户。 联系方式和支持: ➡ 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: ➡ WhatsApp OLD Accounts ➡ Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! 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: ➡ WhatsApp OLD Accounts ➡ Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! 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: ➡ WhatsApp OLD Accounts ➡ Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! 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: ➡ WhatsApp OLD Accounts ➡ Twitter accounts with followers and posts (old accounts) Contact us via the details below. We will be glad to cooperate! 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
  • 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