22.03.2018, 18:37
Hi all, I have already tried to fix it, but I have no idea what to do anymore so post this
I have a speedometer on my script, that messes everything up. I have an array where I store vehicle names to later use them on a textdraw, and a timer to update speed and damage called every 200 ms aprox.
This is what I get spammed on the log.
And the cars array is at the top,
Any ideas??
I have a speedometer on my script, that messes everything up. I have an array where I store vehicle names to later use them on a textdraw, and a timer to update speed and damage called every 200 ms aprox.
Quote:
[18:01:07] [debug] Run time error 4: "Array index out of bounds" [18:01:07] [debug] Attempted to read/write array element at negative index -400 [18:01:07] [debug] AMX backtrace: [18:01:07] [debug] #0 0003b08c in public Speedometer () from pito.amx |
PHP код:
//ongamemodeinit
SetTimer("Speedometer", 1000, true);
//-------------------------------------------
public Speedometer(playerid)
{
foreach(Player, i)
{
if(pInfo[i][Logged] && IsPlayerInAnyVehicle(i))
{
new string[32], string2[32], string3[10], Float:vhealth;
format(string, sizeof(string), "~g~%s",
VehicleNames[GetVehicleModel(GetPlayerVehicleID(i))-400]); //here is the problem.
TextDrawSetString(VehicleName[i], string);
format(string2, sizeof(string2), "%d", GetPlayerSpeed(i, 0));
TextDrawSetString(VehicleSpeed[i], string2);
GetVehicleHealth(GetPlayerVehicleID(i), vhealth);
format(string3, sizeof(string3), "~%s~%.0f.0", DamageColor(vhealth), vhealth);
TextDrawSetString(VehicleHealth[i], string3);
}
}
return 1;
}
PHP код:
new VehicleNames[212][] =
{
"Landstalker", "Bravura", "Buffalo", "Linerunner", "Perrenial", "Sentinel", "Dumper", "Firetruck",
"BF Injection", "Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
"Rhino", "Barracks", "Hotknife", "Article Trailer", "Previon", "Coach", "Cabbie", "Stallion",
"Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral", "Squallo", "Seasparrow",
etc............ till all cars are done.
};