Vehicle name
#1

Hi all,
I've another problem with vehicles name.

I've this array:
Код:
static const VehicleName[212][64] = {
		"Landstalker","Bravura","Buffalo","Linerunner","Pereniel","Sentinel","Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus",
		"Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam","Esperanto","Taxi","Washington","Bobcat","Mr Whoopee","BF Injection",
		"Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie",
		"Stallion","Rumpo","RC Bandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer","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","ZR3 50","Walton","Regina",
		"Comet","BMX","Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper","Rancher","FBI Rancher","Virgo","Greenwood",
		"Jetmax","Hotring","Sandking","Blista Compact","Police Maverick","Boxville","Benson","Mesa","RC Goblin","Hotring Racer A","Hotring Racer B",
		"Bloodring Banger","Rancher","Super GT","Elegant","Journey","Bike","Mountain Bike","Beagle","Cropdust","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","Hustler","Intruder","Primo","Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monstera",
		"Monsterb","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RC Tiger","Flash","Tahoma","Savanna","Bandito","Freight","Trailer",
		"Kart","Mower","Duneride","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford","BF-400","Newsvan","Tug","Trailer A","Emperor",
		"Wayfarer","Euros","Hotdog","Club","Trailer B","Trailer C","Andromada","Dodo","RC Cam","Launch","Police Car (LSPD)","Police Car (SFPD)",
		"Police Car (LVPD)","Police Ranger","Picador","S.W.A.T. Van","Alpha","Phoenix","Glendale","Sadler","Luggage Trailer A","Luggage Trailer B",
		"Stair Trailer","Boxville","Farm Plow","Utility Trailer"};
So, also this function:
Код:
GetVehicleModelName(modelid) 
{
	return VehicleName[modelid - 400];
}
In /vmenu, vehicles name appears:
Код:
new szVehicleLine[128], szVehicleList[400], iVehicle = 0;
	strcat(szVehicleList, "Veicolo\tTarga\n");
	for(new i = 1, j = GetVehiclePoolSize(); i <= j; i++) {
		if(g_VehicleData[i][eOwned] && !strcmp(g_VehicleData[i][eOwner], GetName(playerid))) {
			new plate[20];
			GetVehicleNumberPlate(i, plate, sizeof plate);
			format(szVehicleLine, sizeof szVehicleLine, "%s\t[%s]\n", GetVehicleModelName(g_VehicleData[i][eModel]), plate);
			strcat(szVehicleList, szVehicleLine);
			iVehicle++;
			g_PlayerData[playerid][eVehicleOwned][iVehicle] = i;
		}
	}
	ShowPlayerDialog(playerid, DIALOG_VMENU, DIALOG_STYLE_TABLIST_HEADERS, GREEN_YELLOW"Lista veicoli", szVehicleList, "Seleziona", "Indietro");
But when i click on item, it should show me another dialog with vehicle options instead nothing appears and crashdetects says:
Код:
[18:21:45] [debug] Run time error 4: "Array index out of bounds"
[18:21:45] [debug]  Accessing element at negative index -400
[18:21:45] [debug] AMX backtrace:
[18:21:45] [debug] #0 00023014 in GetVehicleModelName (modelid=0) at C:\Users\Cristian\Desktop\samp\samp037_svr_R1_win32\gamemodes\rp.pwn:1027
[18:21:45] [debug] #1 00018328 in public OnDialogResponse (playerid=0, dialogid=15, response=1, listitem=0, inputtext[]=@0013cac8 "Infernus") at C:\Users\Cristian\Desktop\samp\samp037_svr_R1_win32\gamemodes\rp.pwn:584
Код:
Line 1027: return VehicleName[modelid - 400];
Line 584: 			ShowPlayerDialog(playerid, DIALOG_VMENU_MANAGE, DIALOG_STYLE_TABLIST_HEADERS, sprintf(GREEN_YELLOW"%s [%s]", GetVehicleModelName(g_VehicleData[g_PlayerData[playerid][eSelectedVehicle]][eModel]), plate), sprintf("*\t*\nAllarme\t%s\nSicura\t%s\nCofano\t%s\nBagagliaio\t%s\nTrova\nVendi a giocatore", szAlarm, szDoors, szBonnet, szBoot), "Seleziona", "Indietro");
Reply
#2

Checking if the car is valid prevents it and also change the 2nd dimension of the array to 18 as it's nowhere close to 64.

PHP код:
GetVehicleModelName(modelid)
{
    new 
tmp_vname[sizeof VehicleName[]];
    if (
400 <= modelid <= 611strcat(tmp_vnameVehicleName[modelid 400], sizeof tmp_vname);
    return 
tmp_vname;

EDIT: In the loop, you can skip it directly so it won't call the function for no reason:
pawn Код:
if (!(400 <= g_VehicleData[i][eModel] <= 611)) continue;
Reply
#3

Work, thanks! +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)