Jump to content
  • 0

pomoc Run time error 4: "Array index out of bounds"


vladasavel

Dotaz

Caute mám takovej problem..crahdetect mi neustále do logu zapisuje chybu.

Viz zde:

 

[debug] Run time error 4: "Array index out of bounds"
[13:48:44] [debug] Accessing element at negative index -400
[13:48:44] [debug] AMX backtrace:
[13:48:44] [debug] #0 00003fc4 in ?? (806) from vehsys.amx
[13:48:44] [debug] #1 00007b8c in public OnPlayerUpdate (11) from vehsys.amx

Zde je public

public OnPlayerUpdate(playerid)
{
new vehicleid,veh_string[20],speed_string[10],gps_string[16];
  vehicleid = GetPlayerVehicleID(playerid);
if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
{
new rychlost = GetVehicleSpeed(playerid);
format(speed_string,sizeof(speed_string)," %i km/h",rychlost);
PlayerTextDrawSetString(playerid,RYCHLOST[playerid], speed_string);
 
format(veh_string,sizeof(veh_string),"   %s",GetVehicleName(vehicleid));
PlayerTextDrawSetString(playerid,VOZIDLO[playerid], veh_string);
 
new Float:vehicle_health,final_vehicle_health,health_string[10];
GetVehicleHealth(vehicleid,vehicle_health);
final_vehicle_health = floatround(floatround(vehicle_health - 250)/ 7.5);
format(health_string,10,"%i %", final_vehicle_health);
PlayerTextDrawSetString(playerid,STAV[playerid], health_string);
 
new pozice[16];
        GetPlayer2DZone(playerid, pozice, sizeof(pozice));
format(gps_string,sizeof(gps_string)," %s",pozice);
PlayerTextDrawSetString(playerid,GPS[playerid], gps_string);
 
}
 
return 1;
}

 a tady je funkce GetVehicleSpeed

 

 

stock GetVehicleSpeed(playerid)
{
new Float:p[3];
new Float:final_speed,final_speed_int;
GetVehicleVelocity(GetPlayerVehicleID(playerid),p[0],p[1],p[2]);
final_speed = floatsqroot(((p[0]*p[0])+(p[1]*p[1]))+(p[2]*p[2]))*181.1166672; // 250.666667 = kmph  // 199,4166672= mph
final_speed_int = floatround(final_speed,floatround_round);
if(IsVehicleDrivingBackwards(playerid))
{
final_speed_int=0;
}
return final_speed_int;
}
stock IsVehicleDrivingBackwards(vehicleid)
{
new Float:Float[3];
if(GetVehicleVelocity(vehicleid, Float[1], Float[2], Float[0]))
{
GetVehicleZAngle(vehicleid, Float[0]);
if(Float[0] < 90)
{
if(Float[1] > 0 && Float[2] < 0) return true;
}
else if(Float[0] < 180)
{
if(Float[1] > 0 && Float[2] > 0) return true;
}
else if(Float[0] < 270)
{
if(Float[1] < 0 && Float[2] > 0) return true;
}
else if(Float[1] < 0 && Float[2] < 0) return true;
}
return false;
}

 

 

Vubec netuším co to zpusobuje proto se obracím na Vás.Předem díky moc

Link to comment
Share on other sites

4 odpovědí na tuto otázku

Recommended Posts

  • 0

crashdetect ti přímo říká co máš opravit

[13:48:44] [debug] Accessing element at negative index -400

​zde:

format(veh_string,sizeof(veh_string),"   %s",GetVehicleName(vehicleid));

ve funkci GetVehicleName je pravděpodobně funkce, která zjišťuje model odeslaného vehicleid a tahá jméno z array. Bohužel do tohoto pole posíláš číslo -400.

Solved.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...