SPEEDO - Run time error 4: "Array index out of bounds"
#1

Please Help me with this


[23:59:27] [debug] Run time error 4: "Array index out of bounds"
[23:59:27] [debug] Accessing element at negative index -400
[23:59:27] [debug] AMX backtrace:
[23:59:27] [debug] #0 000932a8 in public Kilometraj () from (SE).amx
[23:59:43] [death] nGen.SoNNy died 255

pawn Код:
fc Kilometraj()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerInAnyVehicle(i) && IsPlayerConnected(i) && KilometrajStats[i] == 1)
        {
            new vehicleid = GetPlayerVehicleID(i), strg1[256], strg2[256];
            new speedysor=GetPlayerSpeed(i,true);
            format(strg1, sizeof(strg1), "~b~~h~KM/h: ~w~%d", speedysor);
            format(strg2, sizeof(strg2), " ` ~r~~h~Vehicle: ~w~%s", VehicleName1[GetVehicleModel(vehicleid)-400]);
            TextDrawSetString(SFSSpeedo1[i], strg1);
            TextDrawSetString(SFSSpeedo2[i], strg2);
        }
    }
    return ( 1 );
}
pawn Код:
new VehicleName1[][] = { // (Colors)
"~g~~h~L~w~andstalker",  "~g~~h~B~w~ravura",  "Buffalo", "Linerunner", "Perennial", "Sentinel",
"~g~~h~D~w~umper",  "~g~~h~F~w~iretruck" ,  "Trashmaster" ,  "Stretch",  "Manana",  "~g~~h~I~w~nfernus",
"~g~~h~V~w~oodoo", "~g~~h~P~w~ony",  "Mule", "Cheetah", "Ambulance",  "Leviathan",  "Moonbeam",
"~g~~h~E~w~speranto", "~g~~h~T~w~axi",  "Washington",  "Bobcat",  "Mr Whoopee", "BF Injection",
"~g~~h~H~w~unter", "~g~~h~P~w~remier",  "Enforcer",  "Securicar", "Banshee", "Predator", "Bus",
"~g~~h~R~w~hino",  "~g~~h~B~w~arracks",  "Hotknife",  "Trailer",  "Previon", "Coach", "Cabbie",
"~g~~h~S~w~tallion", "~g~~h~R~w~umpo", "RC Bandit",  "Romero", "Packer", "Monster",  "Admiral",
"~g~~h~S~w~qualo", "~g~~h~S~w~easparrow", "Pizzaboy", "Tram", "Trailer",  "Turismo", "Speeder",
"~g~~h~R~w~eefer", "~g~~h~T~w~ropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
"~g~~h~S~w~kimmer", "~g~~h~P~w~CJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
"~g~~h~O~w~ceanic", "~g~~h~S~w~anchez", "Sparrow",  "Patriot", "Quad",  "Coastguard", "Dinghy",
"~g~~h~H~w~ermes", "~g~~h~S~w~abre", "Rustler", "ZR-350", "Walton",  "Regina",  "Comet", "BMX",
"~g~~h~B~w~urrito", "~g~~h~C~w~amper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
"~g~~h~R~w~ancher", "FBI ~g~~h~R~w~ancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
"~g~~h~B~w~lista Compact", "~g~~h~P~w~olice ~g~M~w~averick", "Boxville", "Benson", "Mesa", "RC Goblin",
"~g~~h~H~w~otring Racer", "~g~~h~H~w~otring ~g~~h~R~w~acer", "Bloodring Banger", "Rancher",  "Super GT",
"~g~~h~E~w~legant", "~g~~h~Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
"~g~~h~T~w~anker", "~g~~h~RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal",  "Hydra",
"~g~~h~F~w~CR-900", "~g~~h~N~w~RG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona",
"~g~~h~F~w~BI Truck", "~g~~h~Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington",
"~g~~h~S~w~lamvan", "~g~~h~Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover",
"~g~~h~S~w~adler",  "~g~~h~Firetruck", "Hustler", "Intruder", "Primo", "Cargobob",  "Tampa",
"~g~~h~S~w~unrise", "~g~~h~Merit",  "Utility Truck", "Nevada", "Yosemite", "Windsor", "Monster",
"~g~~h~M~w~onster", "~g~~h~Uranus", "Jester", "Sultan", "Stratum", "~g~~h~E~w~legy", "Raindance", "RCTiger",
"~g~~h~F~w~lash", "~g~~h~Tahoma", "Savanna", "Bandito", "Freight", "Trailer", "Kart", "Mower",
"~g~~h~D~w~une", "~g~~h~Sweeper", "Broadway", "Tornado", "AT-400",  "DFT-30",     "Huntley",
"~g~~h~S~w~tafford", "~g~~h~BF-400", "Newsvan", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros",
"~g~~h~H~w~otdog", "~g~~h~Club", "Trailer", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch",
"~g~~h~P~w~olice Car (LSPD)", "~g~~h~Police Car (SFPD)", "Police Car (LVPD)", "Police Ranger",
"~g~~h~P~w~icador",   "~g~~h~S.W.A.T. Van",  "Alpha",   "Phoenix",   "Glendale",   "Sadler",
"~g~~h~L~w~uggage Trailer", "~g~~h~Luggage Trailer", "Stair Trailer", "Boxville", "Farm Plow",
"~g~~h~U~w~tility Trailer"
};
Reply
#2

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

Without that "{" ?
Reply
#4

Quote:
Originally Posted by Dubya
Посмотреть сообщение
Change
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
To
pawn Код:
new i;
for(i=0;i<MAX_PLAYERS;i++){
it doesnt makes any sense that this would fix the error.

Declaring i before loop or in the loop wont make any difference.

EDIT :

Your code is perfect..
TESTED with this GM
pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <uf>
new Text:SFSSpeedo1[MAX_PLAYERS];
new Text:SFSSpeedo2[MAX_PLAYERS];

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
new VehicleName1[][] = { // (Colors)
"~g~~h~L~w~andstalker",  "~g~~h~B~w~ravura",  "Buffalo", "Linerunner", "Perennial", "Sentinel",
"~g~~h~D~w~umper",  "~g~~h~F~w~iretruck" ,  "Trashmaster" ,  "Stretch",  "Manana",  "~g~~h~I~w~nfernus",
"~g~~h~V~w~oodoo", "~g~~h~P~w~ony",  "Mule", "Cheetah", "Ambulance",  "Leviathan",  "Moonbeam",
"~g~~h~E~w~speranto", "~g~~h~T~w~axi",  "Washington",  "Bobcat",  "Mr Whoopee", "BF Injection",
"~g~~h~H~w~unter", "~g~~h~P~w~remier",  "Enforcer",  "Securicar", "Banshee", "Predator", "Bus",
"~g~~h~R~w~hino",  "~g~~h~B~w~arracks",  "Hotknife",  "Trailer",  "Previon", "Coach", "Cabbie",
"~g~~h~S~w~tallion", "~g~~h~R~w~umpo", "RC Bandit",  "Romero", "Packer", "Monster",  "Admiral",
"~g~~h~S~w~qualo", "~g~~h~S~w~easparrow", "Pizzaboy", "Tram", "Trailer",  "Turismo", "Speeder",
"~g~~h~R~w~eefer", "~g~~h~T~w~ropic", "Flatbed", "Yankee", "Caddy", "Solair", "Berkley's RC Van",
"~g~~h~S~w~kimmer", "~g~~h~P~w~CJ-600", "Faggio", "Freeway", "RC Baron", "RC Raider", "Glendale",
"~g~~h~O~w~ceanic", "~g~~h~S~w~anchez", "Sparrow",  "Patriot", "Quad",  "Coastguard", "Dinghy",
"~g~~h~H~w~ermes", "~g~~h~S~w~abre", "Rustler", "ZR-350", "Walton",  "Regina",  "Comet", "BMX",
"~g~~h~B~w~urrito", "~g~~h~C~w~amper", "Marquis", "Baggage", "Dozer", "Maverick", "News Chopper",
"~g~~h~R~w~ancher", "FBI ~g~~h~R~w~ancher", "Virgo", "Greenwood", "Jetmax", "Hotring", "Sandking",
"~g~~h~B~w~lista Compact", "~g~~h~P~w~olice ~g~M~w~averick", "Boxville", "Benson", "Mesa", "RC Goblin",
"~g~~h~H~w~otring Racer", "~g~~h~H~w~otring ~g~~h~R~w~acer", "Bloodring Banger", "Rancher",  "Super GT",
"~g~~h~E~w~legant", "~g~~h~Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
"~g~~h~T~w~anker", "~g~~h~RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal",  "Hydra",
"~g~~h~F~w~CR-900", "~g~~h~N~w~RG-500", "HPV1000", "Cement Truck", "Tow Truck", "Fortune", "Cadrona",
"~g~~h~F~w~BI Truck", "~g~~h~Willard", "Forklift", "Tractor", "Combine", "Feltzer", "Remington",
"~g~~h~S~w~lamvan", "~g~~h~Blade", "Freight", "Streak", "Vortex", "Vincent", "Bullet", "Clover",
"~g~~h~S~w~adler",  "~g~~h~Firetruck", "Hustler", "Intruder", "Primo", "Cargobob",  "Tampa",
"~g~~h~S~w~unrise", "~g~~h~Merit",  "Utility Truck", "Nevada", "Yosemite", "Windsor", "Monster",
"~g~~h~M~w~onster", "~g~~h~Uranus", "Jester", "Sultan", "Stratum", "~g~~h~E~w~legy", "Raindance", "RCTiger",
"~g~~h~F~w~lash", "~g~~h~Tahoma", "Savanna", "Bandito", "Freight", "Trailer", "Kart", "Mower",
"~g~~h~D~w~une", "~g~~h~Sweeper", "Broadway", "Tornado", "AT-400",  "DFT-30",     "Huntley",
"~g~~h~S~w~tafford", "~g~~h~BF-400", "Newsvan", "Tug", "Trailer", "Emperor", "Wayfarer", "Euros",
"~g~~h~H~w~otdog", "~g~~h~Club", "Trailer", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch",
"~g~~h~P~w~olice Car (LSPD)", "~g~~h~Police Car (SFPD)", "Police Car (LVPD)", "Police Ranger",
"~g~~h~P~w~icador",   "~g~~h~S.W.A.T. Van",  "Alpha",   "Phoenix",   "Glendale",   "Sadler",
"~g~~h~L~w~uggage Trailer", "~g~~h~Luggage Trailer", "Stair Trailer", "Boxville", "Farm Plow",
"~g~~h~U~w~tility Trailer"
};
public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    CreateVehicle(400,1978,1343,15,0,-1,-1,1000);
    return 1;
}

forward Kilometraj();
public Kilometraj()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerInAnyVehicle(i) && IsPlayerConnected(i) )
        {
            new vehicleid = GetPlayerVehicleID(i), strg1[256], strg2[256];
            new Float:speedysor=GetPlayerSpeed(i,true);
            format(strg1, sizeof(strg1), "~b~~h~KM/h: ~w~%d", speedysor);
            format(strg2, sizeof(strg2), " ` ~r~~h~Vehicle: ~w~%s", VehicleName1[GetVehicleModel(vehicleid)-400]);
            TextDrawSetString(SFSSpeedo1[i], strg1);
            TextDrawSetString(SFSSpeedo2[i], strg2);
        }
    }
    return ( 1 );
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{

    SFSSpeedo1[playerid] = TextDrawCreate(470.000000, 321.000000, "Speed01");
    TextDrawBackgroundColor(SFSSpeedo1[playerid], 255);
    TextDrawFont(SFSSpeedo1[playerid], 1);
    TextDrawLetterSize(SFSSpeedo1[playerid], 0.639998, 2.099999);
    TextDrawColor(SFSSpeedo1[playerid], -1);
    TextDrawSetOutline(SFSSpeedo1[playerid], 0);
    TextDrawSetProportional(SFSSpeedo1[playerid], 1);
    TextDrawSetShadow(SFSSpeedo1[playerid], 1);

    SFSSpeedo2[playerid] = TextDrawCreate(334.000000, 421.000000, "Speedo2");
    TextDrawBackgroundColor(SFSSpeedo2[playerid], 255);
    TextDrawFont(SFSSpeedo2[playerid], 1);
    TextDrawLetterSize(SFSSpeedo2[playerid], 0.639998, 2.099999);
    TextDrawColor(SFSSpeedo2[playerid], -1);
    TextDrawSetOutline(SFSSpeedo2[playerid], 0);
    TextDrawSetProportional(SFSSpeedo2[playerid], 1);
    TextDrawSetShadow(SFSSpeedo2[playerid], 1);

    TextDrawShowForPlayer(playerid,SFSSpeedo1[playerid]);
    TextDrawShowForPlayer(playerid,SFSSpeedo2[playerid]);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}


public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    Kilometraj();
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#5

Quote:
Originally Posted by Anonym2009
Посмотреть сообщение
Without that "{" ?
Yes. Without it.
Reply
#6

with
pawn Код:
new i;
for(i=0;i<MAX_PLAYERS;i++)
i don't get errors server_log is clean now!
Reply
#7

It's this line that's causing the error i think.

pawn Код:
format(strg2, sizeof(strg2), " ` ~r~~h~Vehicle: ~w~%s", VehicleName1[GetVehicleModel(vehicleid)-400]);
It looks like GetVehicleModel(vehicleid) is returning zero, in which case you are doing this.

pawn Код:
format(strg2, sizeof(strg2), " ` ~r~~h~Vehicle: ~w~%s", VehicleName1[-400]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)