SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/05/2019, 11:01 AM   #1
YouShootIDodge
Big Clucker
 
Join Date: May 2019
Posts: 84
Reputation: 15
Default Find index of an array

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?
YouShootIDodge is offline   Reply With Quote
Old 09/05/2019, 11:28 AM   #2
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,176
Reputation: 73
Default Re: Find index of an array

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]); 
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attempted to read/write array element at index 2000 in array of size 2000 IndependentGaming Scripting Help 4 21/02/2019 10:58 AM
Array does not work properly " array index out of bounds " XpoZzA Scripting Help 1 11/02/2019 10:23 PM
How can I index (search) trought mysql database and to find best values of every column? Zeus666 Scripting Help 0 15/03/2018 11:37 PM
[debug] Attempted to read/write array element at index 90 in array of size 90 HELP ME D: tomasfernandez Scripting Help 3 16/03/2017 05:26 AM
Array must be index, expected token ';' but found this '}' And must be assigned to array again. Deal-or-die Scripting Help 2 14/08/2012 07:33 PM


All times are GMT. The time now is 07:34 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.