SA-MP Forums Archive
Displaying vehicle model as name. - 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: Displaying vehicle model as name. (/showthread.php?tid=503467)



Displaying vehicle model as name. - Zeppo - 29.03.2014

When a player types /myvehicles, I want it to get his PlayerInfo[playerid][VehicleModel] and display it, but as the name of the vehicle.

I have this:
pawn Код:
new VehicleNames[][] =
{
    "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", "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", "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", "Boxville", "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", "Hustler", "Intruder", "Primo",
    "Cargobob", "Tampa", "Sunrise", "Merit", "Utility", "Nevada", "Yosemite",
    "Windsor", "Monster", "Monster", "Uranus", "Jester", "Sultan", "Stratium",
    "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", "Emperor", "Wayfarer", "Euros", "Hotdog", "Club",
    "Freight Box", "Trailer", "Andromada", "Dodo", "RC Cam", "Launch", "Police Car",
    "Police Car", "Police Car", "Police Ranger", "Picador", "S.W.A.T", "Alpha",
    "Phoenix", "Glendale", "Sadler", "Luggage", "Luggage", "Stairs", "Boxville",
    "Tiller", "Utility Trailer"
};
I don't know what to do from here.(I've searched on the forums and can't find it so don't bother saying "search"
EDIT: for example,
pawn Код:
CMD:myvehicles(playerid, params[])
{
    if(PlayerInfo[playerid][pVehicle1] != 0 && PlayerInfo[playerid][pVehicle2] != 0 && PlayerInfo[playerid][pVehicle3] != 0)
    {
        new string[128];
        format(string, sizeof(string), "%s\n%s\n%s");
        ShowPlayerDialog(playerid, DIALOG_MYVEH, DIALOG_STYLE_LIST, "Your current vehicles:", string, "Info", "Cancel");
    }
    return 1;
}
I want it to display vehicle name where the %s is.


Re: Displaying vehicle model as name. - Abagail - 29.03.2014

pawn Код:
CMD:myvehicles(playerid, params[])
{
    if(PlayerInfo[playerid][pVehicle1] != 0 && PlayerInfo[playerid][pVehicle2] != 0 && PlayerInfo[playerid][pVehicle3] != 0)
    {
        new string[128];
        format(string, sizeof(string), "%s\n%s\n%s", VehicleName[iModelID - 400], VehicleName[iModelID - 400], VehicleName[iModelID - 400] );
        ShowPlayerDialog(playerid, DIALOG_MYVEH, DIALOG_STYLE_LIST, "Your current vehicles:", string, "Info", "Cancel");
    }
    return 1;
}



Re: Displaying vehicle model as name. - Zeppo - 29.03.2014

that won't work, how does it know what the vehicle model is?


Re: Displaying vehicle model as name. - Niko_boy - 29.03.2014

Quote:
Originally Posted by Abagail
Посмотреть сообщение
pawn Код:
CMD:myvehicles(playerid, params[])
{
    if(lPlayerInfo[payerid][pVehicle1] != 0 && PlayerInfo[playerid][pVehicle2] != 0 && PlayerInfo[playerid][pVehicle3] != 0)
    {
        new string[128];
        format(string, sizeof(string), "%s\n%s\n%s", VehicleName[iModelID - 400], VehicleName[iModelID - 400], VehicleName[iModelID - 400] );
        ShowPlayerDialog(playerid, DIALOG_MYVEH, DIALOG_STYLE_LIST, "Your current vehicles:", string, "Info", "Cancel");
    }
    return 1;
}
and where the hell iModelID came from ...

Anyways
just :
pawn Код:
format(string, sizeof(string), "%s\n%s\n%s", VehicleNames[ PlayerInfo[playerid][pVehicle1] - 400 ], VehicleNames[ PlayerInfo[playerid][pVehicle2] - 400 ] ,VehicleNames[ PlayerInfo[playerid][pVehicle3] - 400 ] );
it should work but condition is should contain vehicle modelID.
If it is like:
PlayerInfo[playerid][pVehicle2] = CreateVehicle... in past then it wont work. for that you need to make a work around like this:
pawn Код:
new id1  = GetVehicleModel( PlayerInfo[playerid][pVehicle1] ) - 400  ,
    id2  = GetVehicleModel( PlayerInfo[playerid][pVehicle2] )  - 400  ,
    id3 = GetVehicleModel( PlayerInfo[playerid][pVehicle3] )  - 400
;
format(string, sizeof(string), "%s\n%s\n%s", VehicleNames[ id1 ], VehicleNames[ id2] ,VehicleNames[ id3 ] );



Re: Displaying vehicle model as name. - Konstantinos - 29.03.2014

You should always check if the vehicle's model is valid (between 400-611) because it can cause run time error 19.


Re: Displaying vehicle model as name. - Zeppo - 29.03.2014

I now get "undefined command" ingame.
pawn Код:
CMD:myvehicles(playerid, params[])
{
    new id1  = GetVehicleModel( PlayerInfo[playerid][pVehicle1] ) - 400  ,
    id2  = GetVehicleModel( PlayerInfo[playerid][pVehicle2] )  - 400  ,
    id3 = GetVehicleModel( PlayerInfo[playerid][pVehicle3] )  - 400
    ;
    new string[128];
    format(string, sizeof(string), "%s\n%s\n%s", VehicleNames[id1], VehicleNames[id2], VehicleNames[id3]);
    ShowPlayerDialog(playerid, DIALOG_MYVEH, DIALOG_STYLE_LIST, "Your current vehicles:", string, "Info", "Cancel");
    return 1;
}



Re: Displaying vehicle model as name. - Konstantinos - 29.03.2014

Quote:
Originally Posted by Zeppo
Посмотреть сообщение
I now get "undefined command" ingame.
That's why I told you to check if the vehicle's model is valid because run time errors make the commands not to work well and display the unknown command message.

pawn Код:
CMD:myvehicles(playerid, params[])
{
    new
        id1 = GetVehicleModel(PlayerInfo[playerid][pVehicle1]),
        id2 = GetVehicleModel(PlayerInfo[playerid][pVehicle2]),
        id3 = GetVehicleModel(PlayerInfo[playerid][pVehicle3]),
        string[100];
   
    format(string, sizeof (string), "%s\n%s\n%s", (400 <= id1 <= 611) ? (VehicleNames[id1 - 400]) : ("N/A"), (400 <= id2 <= 611) ? (VehicleNames[id2 - 400]) : ("N/A"), (400 <= id3 <= 611) ? (VehicleNames[id3 - 400]) : ("N/A"));
    ShowPlayerDialog(playerid, DIALOG_MYVEH, DIALOG_STYLE_LIST, "Your current vehicles:", string, "Info", "Cancel");
    return 1;
}
If the vehicle's model isn't correct, it will show the name else "N/A".


Re: Displaying vehicle model as name. - Zeppo - 29.03.2014

Don't work properly. Apparently I own a burrito, and the vehicle is a BF-400.


Re: Displaying vehicle model as name. - Konstantinos - 29.03.2014

There difference between those 2 vehicle models is about 100 so debug it:
pawn Код:
CMD:myvehicles(playerid, params[])
{
    new
        id1 = GetVehicleModel(PlayerInfo[playerid][pVehicle1]),
        id2 = GetVehicleModel(PlayerInfo[playerid][pVehicle2]),
        id3 = GetVehicleModel(PlayerInfo[playerid][pVehicle3]),
        string[100];
   
    printf("%s (%i) | %s (%i) | %s (%i)", (400 <= id1 <= 611) ? (VehicleNames[id1 - 400]) : ("N/A"), id1, (400 <= id2 <= 611) ? (VehicleNames[id2 - 400]) : ("N/A"), id2, (400 <= id3 <= 611) ? (VehicleNames[id3 - 400]) : ("N/A"), id3);
   
    format(string, sizeof (string), "%s\n%s\n%s", (400 <= id1 <= 611) ? (VehicleNames[id1 - 400]) : ("N/A"), (400 <= id2 <= 611) ? (VehicleNames[id2 - 400]) : ("N/A"), (400 <= id3 <= 611) ? (VehicleNames[id3 - 400]) : ("N/A"));
    ShowPlayerDialog(playerid, DIALOG_MYVEH, DIALOG_STYLE_LIST, "Your current vehicles:", string, "Info", "Cancel");
    return 1;
}
Go in-game, execute the command once again and post what it printed in the console/server log.


Re: Displaying vehicle model as name. - Zeppo - 29.03.2014

[21:14:47] Burrito (482) | N/A (0) | Burrito (482)
[21:14:56] Burrito (482) | N/A (0) | Burrito (482)