This works for me. (array copied from a forum post)
Console APP just for speed of testing.
pawn Code:
#include <string>
#include <iostream>
char aVehicleNames[212][32] =
{
{"Landstalker"},
{"Bravura"},
{"Buffalo"},
{"Linerunner"},
{"Perrenial"},
{"Sentinel"},
{"Dumper"},
{"Firetruck"},
{"Trashmaster"},
{"Stretch"},
{"Manana"},
{"Infernus"},
{"Voodoo"},
{"Pony"},
{"Mule"},
{"Cheetah"},
{"Ambulance"},
{"Leviathan"},
{"Moonbeam"},
{"Esperanto"},
{"Taxi"},
{"Washington"},
{"Bobcat"},
{"MrWhoopee"},
{"BFInjection"},
{"Hunter"},
{"Premier"},
{"Enforcer"},
{"Securicar"},
{"Banshee"},
{"Predator"},
{"Bus"},
{"Rhino"},
{"Barracks"},
{"Hotknife"},
{"Trailer1"},
{"Previon"},
{"Coach"},
{"Cabbie"},
{"Stallion"},
{"Rumpo"},
{"RCBandit"},
{"Romero"},
{"Packer"},
{"Monster"},
{"Admiral"},
{"Squalo"},
{"Seasparrow"},
{"Pizzaboy"},
{"Tram"},
{"Trailer2"},
{"Turismo"},
{"Speeder"},
{"Reefer"},
{"Tropic"},
{"Flatbed"},
{"Yankee"},
{"Caddy"},
{"Solair"},
{"BerkleyRCVan"},
{"Skimmer"},
{"PCJ-600"},
{"Faggio"},
{"Freeway"},
{"RCBaron"},
{"RCRaider"},
{"Glendale"},
{"Oceanic"},
{"Sanchez"},
{"Sparrow"},
{"Patriot"},
{"Quad"},
{"Coastguard"},
{"Dinghy"},
{"Hermes"},
{"Sabre"},
{"Rustler"},
{"ZR-350"},
{"Walton"},
{"Regina"},
{"Comet"},
{"BMX"},
{"Burrito"},
{"Camper"},
{"Marquis"},
{"Baggage"},
{"Dozer"},
{"Maverick"},
{"NewsChopper"},
{"Rancher"},
{"FBIRancher"},
{"Virgo"},
{"Greenwood"},
{"Jetmax"},
{"Hotring"},
{"Sandking"},
{"Blista Compact"},
{"Police Maverick"},
{"Boxville"},
{"Benson"},
{"Mesa"},
{"RCGoblin"},
{"HotringRacer A"},
{"HotringRacer B"},
{"BloodringBanger"},
{"Rancher"},
{"SuperGT"},
{"Elegant"},
{"Journey"},
{"Bike"},
{"MountainBike"},
{"Beagle"},
{"Cropdust"},
{"Stunt"},
{"Tanker"},
{"Roadtrain"},
{"Nebula"},
{"Majestic"},
{"Buccaneer"},
{"Shamal"},
{"Hydra"},
{"FCR-900"},
{"NRG-500"},
{"HPV1000"},
{"CementTruck"},
{"TowTruck"},
{"Fortune"},
{"Cadrona"},
{"FBITruck"},
{"Willard"},
{"Forklift"},
{"Tractor"},
{"Combine"},
{"Feltzer"},
{"Remington"},
{"Slamvan"},
{"Blade"},
{"Freight"},
{"Streak"},
{"Vortex"},
{"Vincent"},
{"Bullet"},
{"Clover"},
{"Sadler"},
{"FiretruckLA"},
{"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"},
{"FreightFlat"},
{"StreakCarriage"},
{"Kart"},
{"Mower"},
{"Duneride"},
{"Sweeper"},
{"Broadway"},
{"Tornado"},
{"AT-400"},
{"DFT-30"},
{"Huntley"},
{"Stafford"},
{"BF-400"},
{"Newsvan"},
{"Tug"},
{"Trailer 3"},
{"Emperor"},
{"Wayfarer"},
{"Euros"},
{"Hotdog"},
{"Club"},
{"FreightCarriage"},
{"Trailer3"},
{"Andromada"},
{"Dodo"},
{"RCCam"},
{"Launch"},
{"PoliceCar(LSPD)"},
{"PoliceCar(SFPD)"},
{"PoliceCar(LVPD)"},
{"PoliceRanger"},
{"Picador"},
{"S.W.A.T.Van"},
{"Alpha"},
{"Phoenix"},
{"Glendale"},
{"Sadler"},
{"LuggageTrailerA"},
{"LuggageTrailerB"},
{"StairTrailer"},
{"Boxville"},
{"FarmPlow"},
{"UtilityTrailer"}
};
int GetVehicleModelIDFromName(std::string vname)
{
for(int i = 0; i < 211; i++)
{
if( vname.find( aVehicleNames[i] ) != std::string::npos )
{
return i + 400;
}
}
return -1;
}
int main()
{
std::cout << "Infernus ID == " <<
GetVehicleModelIDFromName("Infernus") << std::endl;
return 0;
}
Obviously using a map is better, but just thought I'd show you the code DOES work.
tring::npos if not found.
Was thinking it would be a pain in the ass inserting all those values into a map so i wrote this small loop that creates a file called "VehicleMap.txt". It defines an unordered_map that holds vehicle names and ids.
This needs to be used with the above code. It's not optimized because it only needs to be run once.
Tested and it generates valid code.