0

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.

James Monger
  • 10,181
  • 7
  • 62
  • 98
Clove
  • 29
  • 2
  • 6

4 Answers4

2

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.

IS4
  • 11,945
  • 2
  • 47
  • 86
Mirco Widmer
  • 2,139
  • 1
  • 20
  • 44
1

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

James Monger
  • 10,181
  • 7
  • 62
  • 98
0
SetPlayerPos(playerid, Float:x, Float:y, Float:z);
0

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]);
arserbin3
  • 6,010
  • 8
  • 36
  • 52