Question

I am using spawn points but when it compiles I'm getting this error:

Array index out of bounds

On this line is the error

for(new i =0 ; i < 5 ;i++) {
    SetPlayerPos(playerid, spawnpoints[i][0], spawnpoints[i][1], spawnpoints[i][2]);
} 

Hoping somebody knows the solution to the error.

Was it helpful?

Solution

Your array spawnpoints has either less than 5 entries or one of the arrays (spawnpoints[0], spawnpoints[1], spawnpoints[2], spawnpoints[3], spawnpoints[4]) has less than 3 entries. Try debugging your code.

OTHER TIPS

Replace 5 with sizeof(spawnpoints). If you still get the error after this, then your spawnpoints array doesn't contain an x, y and z coordinate (and so is incorrectly structured.)

SetPlayerPos(playerid, Float:x, Float:y, Float:z);

Are spawnpoints defined with Float?

new Float:OldPos[MAX_PLAYERS][3];

Try with this example:

new Float:OldPos[MAX_PLAYERS][3];
GetPlayerPos(i, OldPos[i][0], OldPos[i][1], OldPos[i][2]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top