What wrong here ? :X
#1

Erorrs in server_log.txt -

PHP код:
[16:32:52] [debugRun time error 4"Array index out of bounds"
[16:32:52] [debug]   Accessing element at negative index -400
[16:32:52] [debugBacktrace (most recent call first):
[
16:32:52] [debug#0  public LuX_SpeedoMeterUp()+0x1d5e30 from TalDmMod.amx 
[with the plugin debug]


PHP код:
Public -
forward LuX_SpeedoMeterUp();
public 
LuX_SpeedoMeterUp()
{
    new 
Float:LPosX;
    new 
Float:LPosY;
    new 
Float:LPosZ;
    new 
Float:PlayerSpeedDistance;
    new 
value;
    new 
Float:L_VehHealth;
     for(new 
0<= MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER && PlayerSpeedo[i] == 0)
        {
         
GetPlayerPos(iLPosXLPosYLPosZ);
        
GetPlayerVehicleID(i);
        
GetVehicleHealth(GetPlayerVehicleID(i), L_VehHealth);
        
PlayerSpeedDistance floatsqroot(floatpower(floatabs(floatsub(LPosX,LuX_ReadPlayerPosition[i][ReadX])),2)+floatpower(floatabs(floatsub(LPosY,LuX_ReadPlayerPosition[i][ReadY])),2)+floatpower(floatabs(floatsub(LPosZ,LuX_ReadPlayerPosition[i][ReadZ])),2));
        
value floatround(PlayerSpeedDistance 5000);
        new 
LuxZone[MAX_ZONE_NAME];
        
GetPlayer2DZone(iLuxZoneMAX_ZONE_NAME);
        
LKPH[i] = floatround(value/1000);
        
format(lstring,sizeof(lstring),"~b~Vehicle: ~w~%s~n~~b~Health: ~w~%.2f~n~~b~Gps: ~w~%s~n~%sKM/H: ~w~~n~%sNitro:",LVehiclesName[GetVehicleModel(GetPlayerVehicleID(i))-400],L_VehHealth,LuxZone,MPH_KPH_Color,MPH_KPH_Color);
        
TextDrawSetString(LFunc[i], lstring);
        
TextDrawShowForPlayer(iLFunc[i]);
        
LuX_ReadPlayerPosition[i][ReadX] = LPosXLuX_ReadPlayerPosition[i][ReadY] = LPosYLuX_ReadPlayerPosition[i][ReadZ] = LPosZ;
        }
    }
    return 
1;

Thanks Alot
Reply
#2

Change

pawn Код:
for(new i = 0; i <= MAX_PLAYERS; i++)
to

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Reply
#3

are you sure ? in most of my mode it's <=
Reply
#4

Код:
Run time error 4: "Array index out of bounds"
The problem is at an array [ ]
The mathematical operation on the loops has nothing to do with your problem.
Reply
#5

iam sure this line
pawn Код:
format(lstring,sizeof(lstring),"~b~Vehicle: ~w~%s~n~~b~Health: ~w~%.2f~n~~b~Gps: ~w~%s~n~%sKM/H: ~w~~n~%sNitro:",LVehiclesName[GetVehicleModel(GetPlayerVehicleID(i))-400],L_VehHealth,LuxZone,MPH_KPH_Color,MPH_KPH_Color);
causes it.
or better: this part:
pawn Код:
LVehiclesName[GetVehicleModel(GetPlayerVehicleID(i))-400]
get the players vehicle id, then its model, subtract 400. used as pointer into that array.
try to add a debug print at the IsPlayerInAnyVehicle() to make sure that the vehicle(model) wont return 0 (cell [0-400] as result).
Reply
#6

Quote:
Originally Posted by Babul
Посмотреть сообщение
iam sure this line
pawn Код:
format(lstring,sizeof(lstring),"~b~Vehicle: ~w~%s~n~~b~Health: ~w~%.2f~n~~b~Gps: ~w~%s~n~%sKM/H: ~w~~n~%sNitro:",LVehiclesName[GetVehicleModel(GetPlayerVehicleID(i))-400],L_VehHealth,LuxZone,MPH_KPH_Color,MPH_KPH_Color);
causes it.
or better: this part:
pawn Код:
LVehiclesName[GetVehicleModel(GetPlayerVehicleID(i))-400]
get the players vehicle id, then its model, subtract 400. used as pointer into that array.
try to add a debug print at the IsPlayerInAnyVehicle() to make sure that the vehicle(model) wont return 0 (cell [0-400] as result).
But what is the problam?
Reply
#7

due to any reason, the ModelID of the players vehicle returns 0... 0 minus 400 = -400, thats an invalid array index.
this
pawn Код:
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER && PlayerSpeedo[i] == 0)
{
equals
pawn Код:
if(IsPlayerConnected(i))
    {
        if(IsPlayerInAnyVehicle(i))
        {
            if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                if(PlayerSpeedo[i] == 0)
                {
                }
            }
        }
    }
but in the "long" script you can add some SendClientMessage(), formatted with a string which contains all variables you are using to work with:
pawn Код:
new debug[128];
    if(IsPlayerConnected(i))
    {
        format(debug,sizeof(debug),"Player %d is connected",i);
        SendClientMessageToAll(0xaa3333ff,debugstring);
        if(IsPlayerInAnyVehicle(i))
        {
            format(debug,sizeof(debug),"in vehicleid %d",GetPlayerVehicleID(i));
            SendClientMessageToAll(0xaa3333ff,debugstring);
            if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                format(debug,sizeof(debug),"player is driver");
                SendClientMessageToAll(0xaa3333ff,debugstring);
                if(PlayerSpeedo[i] == 0)
                {
                }
            }
        }
    }
if there is any debug printout with vehicle 0, then the model of "no" vehicle, is also 0. subtracting 400 from 0 must be avoided. thre is something wrong in your checking for IF a player is in a vehicle...
Reply
#8

it's good to do -400, because -

I insert the id of infernus, in the List it's 11, but the model id is 411, so what we need to do is 411-400 = 11, understood ?
Reply
#9

Quote:
Originally Posted by tal_peretz
Посмотреть сообщение
it's good to do -400, because -

I insert the id of infernus, in the List it's 11, but the model id is 411, so what we need to do is 411-400 = 11, understood ?
But what if he is not in any vehicle at all? It would return 0 and 0 - 400 = -400 and that causes the error. So you should check if the player is in any vehicle first.
Reply
#10

Did you see the IsPlayerInAnyVehicle?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)