Find index of an array
#1

I have this array storing different spawn points, i want to make a random spawn system.

Code:
new Spawns [MAX_SPAWN_AREAS][][4] =
{
	{	{2050.3469, -1704.7300, 13.5547,1.0169},
		{2441.4512, -1895.1366, 13.5534,1.4484},
		{2202.9856, -2019.7108, 13.5469,20.2159},
		{2427.6135, -1415.6868, 24.0612,90.2920},
		{2248.9397, -1937.4247, 13.5469,90.8681},
		{2660.6953, -1593.8492, 13.3384,97.1763},
		{2631.9658, -2202.0972, 13.5469,90.1551},
		{2327.2188, -1913.4989, 13.6065,91.7376},
		{2296.1692, -1719.6720, 13.5545,174.8575},
		{2038.5065, -1778.1056, 13.5533,270.2934},
		{1859.0859, -1852.2188, 13.5805,181.1541},
		{1803.2119, -1711.0032, 13.5388,179.4361},
		{2046.3868, -1104.6135, 24.4763,269.8674},
		{2338.7900, -1046.6512, 52.5372,184.4534},
		{2477.6860, -1323.7358, 27.8503,180.1541},
		{2300.7202, -2117.7615, 13.5983,229.1671},
		{2125.8301, -1814.3864, 13.5545,268.8662},
		{2448.1016, -1979.3562, 13.5539,269.7284}    },
		
	{   {2487.7795, 80.9487,  26.9918,  0.9819},
		{2322.6675, 31.1972,  26.4766,  91.5550},
		{2599.9316, 50.0952,  26.4177,  90.8396},
		{2252.4841, 67.7023,  26.4844,  271.1258},
		{2386.5100, 132.7873, 26.4769,  276.7143},
		{2319.3423, -59.5278, 26.4844,  178.1172}    },
		
	{   {1315.0155, 189.9191, 19.9922, 80.3777},
		{1275.2113, 301.8757, 19.5547, 66.0465},
		{1423.5811, 276.5982, 19.5547, 67.0497},
		{1238.7804, 214.1248, 19.5547, 76.6525},
		{1301.9076, 353.8661, 19.5617, 247.3368},
		{1322.8766, 207.9405, 19.5547, 155.6168}    },
		
	{   {203.2630, 6.0490,    2.5781, 179.9836},
		{155.9573, -6.5729,   1.5781, 268.5487},
		{251.3828, -39.9476,  1.5781, 87.1157},
		{317.1255, -38.0950,  1.5781, 271.7027},
		{240.0708, -307.2509, 1.5781, 89.6976},
		{153.3353, -301.2694, 1.5781, 270.4137}     },
		
	{   {873.3766, -606.1093, 18.4219, 2.2795},
		{658.1357, -646.4300, 16.3359, 1.5642},
		{666.8577, -546.1932, 16.3359, 91.4204},
		{680.7677, -441.6770, 16.3359, 92.7093},
		{608.8641, -589.0514, 17.2266, 270.2758}    }

		
};
I want to find the number of items/spawns in it's second dimension.

Code:
Spawns [0][??][0]
So i can do something like this:

Code:
new rand = random (total_items);
SetPlayerFacingAngle (playerid, Spawns[0][rand][3]);
Any idea how can i do it?
Reply
#2

for first, one of the array indexs (second) is extra and doesn't makes any sense, make it like this
new Float:Spawns [MAX_SPAWN_AREAS][4]

so you can create a spawn like this:
PHP Code:
new rand random(MAX_SPAWN_AREAS);
SetPlayerPos(playerid,Spawns[rand][0],Spawns[rand][1],Spawns[rand][2]);
SetPlayerFacingAngle(playerid,Spawns[rand][3]); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)