SA-MP Forums Archive
Errors in crashdetect "Array index out of bounds" x2 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Errors in crashdetect "Array index out of bounds" x2 (/showthread.php?tid=630560)



Errors in crashdetect "Array index out of bounds" x2 - tomasfernandez - 15.03.2017

[19:11:29] [debug] Run time error 4: "Array index out of bounds"
[19:11:29] [debug] Attempted to read/write array element at negative index -400
[19:11:29] [debug] AMX backtrace:
[19:11:29] [debug] #0 0016ada0 in public Speed () from Mundito.amx.

PHP код:
public Speed()
{
    for(new 
0GetMaxPlayers(); p++) if(IsPlayerConnected(p) && !IsPlayerNPC(p))
    {
        new 
vehicleid GetPlayerVehicleID(p);
        if(
vehicleid)
        {
            new 
string[128], Float:XFloat:YFloat:ZFloat:PointToPointFloat:vhealth;
             
GetVehicleVelocity(vehicleidXYZ);
             
PointToPoint = (floatsqroot(floatpower(X2) + floatpower(Y2) + floatpower(Z2)))*100;
            
GetVehicleHealth(vehicleid,vhealth);
            
format(string,sizeof string ,"{00D1FF}Vehнculo: {FFFFFF}%s\n{00D1FF}Vida: {FFFFFF}%.2f\n{00D1FF}Velocidad: {FFFFFF}%ikm/h"VehicleName[GetVehicleModel(vehicleid)-400], vhealthfloatround(PointToPointfloatround_floor));
            
DeletePlayer3DTextLabel(pspeedo3Dtext);
            
speedo3Dtext CreatePlayer3DTextLabel(pstringspeedcolor0.0,-1.6,-0.35,20.0INVALID_PLAYER_IDvehicleid);
        } else if(
p) { DeletePlayer3DTextLabel(pspeedo3Dtext); }
    }

help me, tranks


Re: Errors in crashdetect "Array index out of bounds" x2 - SkyLineGT - 16.03.2017

Quote:

VehicleName[GetVehicleModel(vehicleid)-400]

that is where your problem is, could you show us that array?


Respuesta: Errors in crashdetect "Array index out of bounds" x2 - tomasfernandez - 16.03.2017

PHP код:
new VehicleName[212][] = {
"Landstalker""Bravura""Buffalo""Linerunner""Perrenial""Sentinel""Dumper""Firetruck""Trashmaster""Stretch""Manana",
"Infernus""Voodoo""Pony""Mule""Cheetah""Ambulance""Leviathan""Moonbeam""Esperanto""Taxi""Washington""Bobcat",
"Whoopee""BF Injection""Hunter""Premier""Enforcer""Securicar""Banshee""Predator""Bus""Rhino""Barracks""Hotknife",
"Trailer 1""Previon""Coach""Cabbie""Stallion""Rumpo""RC Bandit""Romero""Packer""Monster""Admiral""Squalo",
"Seasparrow""Pizzaboy""Tram""Trailer 2""Turismo""Speeder""Reefer""Tropic""Flatbed""Yankee""Caddy""Solair",
"Berkley's RC Van""Skimmer""PCJ-600""Faggio""Freeway""RC Baron""RC Raider""Glendale""Oceanic""Sanchez""Sparrow",
"Patriot""Quad""Coastguard""Dinghy""Hermes""Sabre""Rustler""ZR-350""Walton""Regina""Comet""BMX""Burrito",
"Camper""Marquis""Baggage""Dozer""Maverick""News Chopper""Rancher""FBI Rancher""Virgo""Greenwood""Jetmax""Hotring",
"Sandking""Blista Compact""Police Maverick""Boxvillde""Benson""Mesa""RC Goblin""Hotring Racer A""Hotring Racer B",
"Bloodring Banger""Rancher""Super GT""Elegant""Journey""Bike""Mountain Bike""Beagle""Cropduster","Stunt",  "Tanker",
"Roadtrain""Nebula""Majestic""Buccaneer""Shamal""Hydra""FCR-900""NRG-500""HPV1000""Cement Truck""Tow Truck""Fortune",
"Cadrona""FBI Truck""Willard""Forklift""Tractor""Combine""Feltzer""Remington""Slamvan""Blade""Freight""Streak",
"Vortex""Vincent""Bullet""Clover""Sadler""Firetruck LA""Hustler""Intruder""Primo""Cargobob""Tampa""Sunrise""Merit",
"Utility""Nevada""Yosemite""Windsor""Monster A""Monster B""Uranus""Jester""Sultan""Stratum""Elegy""Raindance",
"RC Tiger""Flash""Tahoma""Savanna""Bandito""Freight Flat""Streak Carriage""Kart""Mower""Dune""Sweeper""Broadway",
"Tornado""AT-400""DFT-30""Huntley""Stafford""BF-400""News Van""Tug""Trailer 3""Emperor""Wayfarer""Euros""Hotdog",
"Club""Freight Carriage""Trailer 4""Andromada""Dodo""RC Cam""Launch""Police Car (LSPD)""Police Car (SFPD)",
"Police Car (LVPD)""Police Ranger""Picador""S.W.A.T""Alpha""Phoenix""Glendale""Sadler""Luggage Trailer A",
"Luggage Trailer B""Stairs""Boxville""Tiller""Utility Trailer" }; 



Re: Errors in crashdetect "Array index out of bounds" x2 - raydx - 16.03.2017

Try

if(vehicleid) ----> if(vehicleid != INVALID_VEHICLE_ID)


Re: Errors in crashdetect "Array index out of bounds" x2 - Dayrion - 16.03.2017

It's not :
Код:
VehicleName[GetVehicleModel(vehicleid)-400]
it'ts:
Код:
VehicleName[GetVehicleModel(vehicleid)+400]



Re: Errors in crashdetect "Array index out of bounds" x2 - Toroi - 16.03.2017

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
It's not :
Код:
VehicleName[GetVehicleModel(vehicleid)-400]
it'ts:
Код:
VehicleName[GetVehicleModel(vehicleid)+400]
That would not make any sense.

Код:
new VehicleName[212]
OP, I think you should to the calculations outside the array, like this:

PHP код:
new vehname GetVehicleModel(vehicleid) - 400;
format(bla,sizeof bla,"bla bla veh name %s",VehicleName[vehname]); 



Re: Errors in crashdetect "Array index out of bounds" x2 - Dayrion - 16.03.2017

Quote:
Originally Posted by Troydere
Посмотреть сообщение
That would not make any sense.

Код:
new VehicleName[212]
OP, I think you should to the calculations outside the array, like this:

PHP код:
new vehname GetVehicleModel(vehicleid) - 400;
format(bla,sizeof bla,"bla bla veh name %s",VehicleName[vehname]); 
Woa, yes, my bad.
The code is right, there is no problem with this. The problem is GetVehicleModel return 0. It mean, the vehicle doesn't exist.
Add on the top of your script after includes.:
PHP код:
native IsValidVehicle(vehicleid); 
Try this code:
PHP код:
public Speed() 

    for(new 
0GetMaxPlayers(); p++) if(IsPlayerConnected(p) && !IsPlayerNPC(p)) 
    {
        new 
vehicleid GetPlayerVehicleID(p); 
        if(!
IsValidVehicle(vehicleid))
            continue;
        if(
vehicleid
        { 
            new 
string[128], Float:XFloat:YFloat:ZFloat:PointToPointFloat:vhealth
             
GetVehicleVelocity(vehicleidXYZ); 
             
PointToPoint = (floatsqroot(floatpower(X2) + floatpower(Y2) + floatpower(Z2)))*100
            
GetVehicleHealth(vehicleid,vhealth); 
            
format(string,sizeof string ,"{00D1FF}Vehнculo: {FFFFFF}%s\n{00D1FF}Vida: {FFFFFF}%.2f\n{00D1FF}Velocidad: {FFFFFF}%ikm/h"VehicleName[GetVehicleModel(vehicleid)-400], vhealthfloatround(PointToPointfloatround_floor)); 
            
DeletePlayer3DTextLabel(pspeedo3Dtext); 
            
speedo3Dtext CreatePlayer3DTextLabel(pstringspeedcolor0.0,-1.6,-0.35,20.0INVALID_PLAYER_IDvehicleid); 
        } else if(
p) { DeletePlayer3DTextLabel(pspeedo3Dtext); } 
    } 




Respuesta: Errors in crashdetect "Array index out of bounds" x2 - tomasfernandez - 17.03.2017

tranks