How to return the name of the choosen car?
#1

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
        if(dialogid == 1)// dialogid
        {
                if(strlen(inputtext))
                {
                        new vehicle = GetVehicleModelIDFromName(inputtext);
                        if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, -1, "That vehicle name was not found");
                        else
                        {
                                if(GetPlayerMoney(playerid) >= 50000)
                                {
                                        GivePlayerMoney(playerid, -50000);
                                        CreateVehicle(vehicle, 2126.34, -1143.67, 24.88, 90, -1, -1, -1);
                                        SendClientMessage(playerid, -1, " ~carname~ has been spawned behind you!");
                                }
                                else return SendClientMessage(playerid, -1, "INSUFFICIENT MONEY! YOU NEED 50000 TO BUY A CAR!");
                        }
                }
        }
        return 1;
}

I have coloured in red what i would like to do, any help? If You need more code lemme know :D
Reply
#2

Top of the code:
Код:
new VehicleModel[MAX_VEHICLES];

new VehicleNames[][] =
{
	"Landstalker","Bravura","Buffalo","Linerunner","Perennial","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 (SJPD)","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"
};
Then use this variable to help you get the vehicle name this way:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)// dialogid
    {
        if(strlen(inputtext))
        {
            new vehicle = GetVehicleModelIDFromName(inputtext), string[50];
            if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, -1, "That vehicle name was not found");
            else
            {
                if(GetPlayerMoney(playerid) >= 50000)
                {
                    GivePlayerMoney(playerid, -50000);
                    CreateVehicle(vehicle, 2126.34, -1143.67, 24.88, 90, -1, -1, -1);
                    format(string,sizeof(string), "%s has spawned behind you!", VehicleNames[VehicleModel[vehicle]-400]);
                    SendClientMessage(playerid, -1, string);
                }
                else return SendClientMessage(playerid, -1, "INSUFFICIENT MONEY! YOU NEED 50000 TO BUY A CAR!");
            }
        }
    }
    return 1;
}
Try the codes tell me if something is wrong.
Reply
#3

Just like this:

PHP код:
stock GetVehicleModelIDFromName(const name[])
{
    static 
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"
    
};
    for(new 
ii<sizeof VehicleNamesi++) if(!strcmp(VehicleNames[i],name,true)) return i+400;
    return -
1;

if it returns -1 the modelname was invalid

Greekz
Reply
#4

EDIT: Already answered was too slow ^^
Reply
#5

FULL CODE

This is my full code, i just want to notice user that him selected vehicle will spawn behind him


ignore the

Код:
 if(GetPlayerMoney(playerid) >= 50000)
                                {
                                        GivePlayerMoney(playerid, -50000);
                                        CreateVehicle(vehicle, 2126.34, -1143.67, 24.88, 90, -1, -1, -1);
                                        SendClientMessage(playerid, -1, "INSUFFICIENT MONEY! YOU NEED 50000 TO BUY A CAR!");
                                }
Reply
#6

You can make it spawn infront of him or spawn it and put him inside it automatically.
Reply
#7

Quote:
Originally Posted by Terrorizt
Посмотреть сообщение
You can make it spawn infront of him or spawn it and put him inside it automatically.
Nice Idea! How i can do that instead of just spawning behind Him? I need to spawn behind him as he got a door in front of him.
Reply
#8

Edit: can it be used everywhere or only in a specified place?
Reply
#9

Quote:
Originally Posted by Terrorizt
Посмотреть сообщение
1 question, is this dialog called through a command or wut?
Код:
CMD:buycar(playerid)
{
        if(IsPlayerInRangeOfPoint(playerid, 7.0, 2131.96, -1150.64, 24.14))
        {
                ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Buy Car","Insert the model name:","Find","Cancel");
        }
    else return SendClientMessage(playerid,0xFFFFFFFF,"You must be near the dealership entrance!");
        return 1;
}
Reply
#10

Quote:
Originally Posted by VanillaRain
Посмотреть сообщение
FULL CODE

This is my full code, i just want to notice user that him selected vehicle will spawn behind him
Click
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)