SA-MP Forums Archive
[Ajuda] "Ler array com valor negativo". Alguйm? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] "Ler array com valor negativo". Alguйm? (/showthread.php?tid=665711)



"Ler array com valor negativo". Alguйm? - Psicotico - 13.04.2019

Por favor, alguйm me ajuda?

pawn Code:
[16:05:57] [debug] AMX backtrace:
[16:05:57] [debug] #0 0008e60c in public UpdateCar@INFO (0) from GM.amx
[16:05:57] [debug] Run time error 4: "Array index out of bounds"
[16:05:57] [debug]  Attempted to read/write array element at negative index -400
Nгo sou expert, mas creio eu que a linha do erro й esta:

pawn Code:
format(String, sizeof(String), "%s", carName[GetVehicleModel(GetPlayerVehicleID(playerid))-400]);
Se necessitar da public completa, sу avisar que posto...


Re: "Ler array com valor negativo". Alguйm? - MultiKill - 13.04.2019

O problema acontece pois o jogador nгo estб em um veнculo vбlido, e a funзгo GetVehicleModel retorna a 0.

Vocк deve verificar antes se o jogador estб em um veнculo e se o id retornado pela funзгo GetPlayerVehicleID й vбlido.

Basta usar a funзгo IsValidVehicle, caso nгo esteja definida no seu script:
PHP Code:
native IsValidVehicle(vehicleid); 
Exemplo:

PHP Code:
new vid GetPlayerVehicleID(playerid);
if(!
IsValidVehicle(vid)){
    
printf("O veнculo id %d nгo й vбlido"vid);
}
else{
    
printf("O veнculo id %d й vбlido."vid);




Re: "Ler array com valor negativo". Alguйm? - Psicotico - 14.04.2019

Obrigado, MultiKill.


+rep