Get vehicle ID from name? -
randomkid88 - 03.06.2010
I am making a system where a player can "call" a car and it will spawn next to them. Now instead of doing, for example, /callname, /callname2, etc, I am trying to use dcmd and sscanf to return the vehicle ID from the car name, loaded as the sscanf params. I have each vehicle created in an enumeration with the name as one of the values. Is it possible to return the car id from this value?
Let me post some of the code so you can see:
Код:
enum CarInfo
{
Name[24],
Locked,
Kill,
Model,
Color1,
Color2
}
new cInfo[MAX_CARS][CarInfo];
public OnFilterScriptInit()
{
carname= AddStaticVehicle(model, x, y, z, color, color2);
return 1;
}
Код:
dcmd_callcar(playerid, params[])
{
new Float:px, Float:py, Float:pz, carname;
if(sscanf(params, "s", carname)) SendClientMessage(playerid, COLOR_RED, "[Usage:] /callcar [car name]");
else
{
GetPlayerPos(playerid, px, py, pz);
SetVehiclePos(*VEHICLE ID AS VAR?*, px-5, py, pz);
Re: Get vehicle ID from name? -
cessil - 03.06.2010
well every model would have the same name, if you could only call your car then you could set a PVar to their vehicle ID and then call that
Re: Get vehicle ID from name? -
Backwardsman97 - 03.06.2010
I think he wants to do custom names for each vehicle. Anyway, there's some things about this that don't seem right. Did you define MAX_CARS? A_samp.inc has the definition as MAX_VEHICLES. Either way the maximum vehicles is 2000. That's a big ass array especially with an enumeration like that. Besides that, I don't think that you could store the vehicle's name in an enum.
pawn Код:
format(cInfo[9][Name],24,"Bob");
I'm not sure if that's considered a 3d array which PAWN doesn't support. Maybe it would work. Maybe not..
Re: Get vehicle ID from name? -
randomkid88 - 03.06.2010
Yes, I did define MAX_CARS and right now set it to 6. And I am trying to have a name for each car. So for example, if they do /callcar Bob, I need to somehow return Bob's vehicle ID and plug that into SetVehiclePos.
Re: Get vehicle ID from name? -
Backwardsman97 - 03.06.2010
Try this.
pawn Код:
dcmd_callcar(playerid, params[])
{
new carname;
if(sscanf(params, "s", carname))
{
SendClientMessage(playerid, COLOR_RED, "[Usage:] /callcar [car name]");
return 1;
}
for(new i; i<MAX_CARS; i++)
{
if(!strcmp(params,cInfo[i][Name],true))
{
new Float:px, Float:py, Float:pz,
GetPlayerPos(playerid, px, py, pz);
SetVehiclePos(i, px-5, py, pz); //i here will only work if the array is organized via vehicle ids
return 1;
}
}
return 1;
}
I just used i for the vehicle's id. I'm not sure how you organized it. It will work if you did it like cInfo[vehicleid][Name].
Re: Get vehicle ID from name? -
randomkid88 - 03.06.2010
What do you mean the array has to be organized via vehicle ids?
Re: Get vehicle ID from name? -
RyDeR` - 03.06.2010
At the top of your script:
pawn Код:
new
vNames[212][] =
{
"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", "Monster A",
"Monster B", "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"
}
;
Anywhere in your script:
pawn Код:
ReturnVehicleID(vName[])
{
for(new x; x != 211; x++) if(strfind(vNames[x], vName, true) != -1) return x + 400;
return INVALID_VEHICLE_ID;
}
Re: Get vehicle ID from name? -
randomkid88 - 03.06.2010
Thanks for that, but I still don't have anything. In that case, it would have to be "/callcar bullet" or something like that, not "/callcar Bob" right?
Re: Get vehicle ID from name? -
Joe_ - 03.06.2010
Take a look at my Hire System [FS], It has a way to assign IDs to vehicles etc, That's also enumerated, maybe you can go on from there.
pawn Код:
enum whatever
{
name[20]
};
new vdata[MAX_CARS][whatever];
Then you can loop through all vehicle ID's, and check if their one of the custom IDs.
If they are, compare params with the VehicleID's name and wallah!
But yeah, if you're really stuck, take a peep into my hire system, It has a methord of assigning a VehicleID etc, etc..
Re: Get vehicle ID from name? -
RyDeR` - 03.06.2010
lolwut?
Just use it like this
pawn Код:
CreateVehicle(ReturnVehicleID(params), Float: x, Float: y, Float: z, Float: a, color1, color2, respawn time);