SA-MP Forums Archive
Car command with message with carname - 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: Car command with message with carname (/showthread.php?tid=560230)



Car command with message with carname - xX4m4zingXx - 27.01.2015

I have made/copied partly a car command and I want to add a message saying, "You spawned a/an [VEHICLENAME]"
How would I do that?
I tried something.
This is my code:
Код:
CMD:car(playerid, params[])
{
	new carName[100];
	new message[128];
	if(sscanf(params, "s[100]", carName)) return SendClientMessage(playerid, COL_RED, "[USAGE]: /car [vehiclename].");
	if (ReturnVehicleID(carName) == INVALID_VEHICLE_ID) return SendClientMessage(playerid, COL_RED, "[SERVER]: Vehicle name/id not found.");
	if (PlayerInfo[playerid][pRights] < 3) return SendClientMessage(playerid, COL_RED, "[SERVER]: You don't have the rights to use this command.");
	new Float:pPos[4], vid;
	GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
	GetPlayerFacingAngle(playerid, pPos[3]);
	vid = CreateVehicle(ReturnVehicleID(carName), pPos[0], pPos[1], pPos[2] + 1, pPos[3], 0, 1, 60);
	PutPlayerInVehicle(playerid, vid, 0);
	format (message, 128, "You have spawned a %s.", GetVehicleNames(carName));
	SendClientMessage(playerid, COL_GREEN, message);
	return 1;
}
But this doesn't work and just says: "You have spawned a [What you typed after /car]"
so if you typed the ID 1 it just says "You have spawned a 1".
I want it to say the vehicle name from that id.
Do any of you know how to do this?


Re: Car command with message with carname - CalvinC - 27.01.2015

Your GetVehicleNames feature probably doesn't work like you want it to.
To get vehicle's names you need something like 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"
};

GetVehicleNames(vehicleid)
{
    new string[128];
    format(string, sizeof(string), "%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return string;
}
Not my list, found it on ******.


Re: Car command with message with carname - xX4m4zingXx - 27.01.2015

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
Your GetVehicleNames feature probably doesn't work like you want it to.
To get vehicle's names you need something like 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"
};

GetVehicleNames(vehicleid)
{
    new string[128];
    format(string, sizeof(string), "%s",VehicleNames[GetVehicleModel(vehicleid) - 400]);
    return string;
}
Not my list, found it on ******.
I got this:
pawn Код:
new VehicleNames[212][] =
{
    {"Landstalker"},{"Bravura"},{"Buffalo"},{"Linerunner"},{"Perrenial"},{"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"},{"Article Trailer"},
    {"Previon"},{"Coach"},{"Cabbie"},{"Stallion"},{"Rumpo"},{"RC Bandit"},{"Romero"},{"Packer"},{"Monster"},
    {"Admiral"},{"Squalo"},{"Seasparrow"},{"Pizzaboy"},{"Tram"},{"Article Trailer 2"},{"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"},{"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 LA"},{"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 Flat"},{"Streak Carriage"},
    {"Kart"},{"Mower"},{"Dunerider"},{"Sweeper"},{"Broadway"},{"Tornado"},{"AT-400"},{"DFT-30"},{"Huntley"},
    {"Stafford"},{"BF-400"},{"Newsvan"},{"Tug"},{"Article Trailer 3"},{"Emperor"},{"Wayfarer"},{"Euros"},{"Mobile Hotdog"},
    {"Club"},{"Freight Carriage"},{"Trailer 3"},{"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"}
};
and this is my getvehiclenames:
pawn Код:
stock GetVehicleNames(vehicleid)
{
    new GVFNstring[56];
    format(GVFNstring, sizeof(GVFNstring), VehicleNames[GetVehicleModel(vehicleid)-400]);
    return GVFNstring;
}



Re: Car command with message with carname - CalvinC - 27.01.2015

Try to replace this
pawn Код:
format(GVFNstring, sizeof(GVFNstring), VehicleNames[GetVehicleModel(vehicleid)-400]);
With this
pawn Код:
format(GVFNstring, sizeof(GVFNstring), "%s", VehicleNames[GetVehicleModel(vehicleid)-400]);



Re: Car command with message with carname - ATGOggy - 27.01.2015

Change this:
PHP код:
format (message128"You have spawned a %s."GetVehicleNames(carName)); 
to:
PHP код:
format (message128"You have spawned a %s."GetVehicleNames(ReturnVehicleID(carName))); 
If you don't mind, can you post that ReturnVehicleID stock for me?


Re: Car command with message with carname - xX4m4zingXx - 27.01.2015

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
Try to replace this
pawn Код:
format(GVFNstring, sizeof(GVFNstring), VehicleNames[GetVehicleModel(vehicleid)-400]);
With this
pawn Код:
format(GVFNstring, sizeof(GVFNstring), "%s", VehicleNames[GetVehicleModel(vehicleid)-400]);
Can you explain what the difference between these two is?
I see that you added "%s",

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Change this:
PHP код:
format (message128"You have spawned a %s."GetVehicleNames(carName)); 
to:
PHP код:
format (message128"You have spawned a %s."GetVehicleNames(ReturnVehicleID(carName))); 
If you don't mind, can you post that ReturnVehicleID stock for me?
Here is the ReturnVehicleID
pawn Код:
ReturnVehicleID(vName[])
{
    for(new x; x != 211; x++) if(strfind(VehicleNames[x], vName, true) != -1) return x + 400;
    return INVALID_VEHICLE_ID;
}
EDIT: I added this, but when I type the command it says SERVER: command not found or something like that and it just spawns the vehicle


Re: Car command with message with carname - xX4m4zingXx - 27.01.2015

Bump


Re: Car command with message with carname - Jefff - 27.01.2015

pawn Код:
CMD:car(playerid, params[])
{
    if(PlayerInfo[playerid][pRights] < 3) SendClientMessage(playerid, COL_RED, "[SERVER]: You don't have the rights to use this command.");
    else if(isnull(params)) SendClientMessage(playerid, COL_RED, "[USAGE]: /car [vehicle name / model].");
    else{
        new Model = ReturnVehicleID(params);
        if(Model == INVALID_VEHICLE_ID)
        {
            if(strlen(params) > 8) params[8] = EOS;
            Model = strval(params);
            if(!(400 <= Model <= 611))
                return SendClientMessage(playerid, COL_RED, "[SERVER]: Vehicle name/id not found.");
        }
        new message[75], Float:pPos[4], vid;
        GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
        GetPlayerFacingAngle(playerid, pPos[3]);
        vid = CreateVehicle(Model, pPos[0], pPos[1], pPos[2] + 1, pPos[3], 0, 1, 60);
        PutPlayerInVehicle(playerid, vid, 0);
        format(message, sizeof(message), "You have spawned a %s.", GetVehicleNames(vid));
        SendClientMessage(playerid, COL_GREEN, message);
    }
    return 1;
}



Re: Car command with message with carname - xX4m4zingXx - 28.01.2015

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Change this:
PHP код:
format (message128"You have spawned a %s."GetVehicleNames(carName)); 
to:
PHP код:
format (message128"You have spawned a %s."GetVehicleNames(ReturnVehicleID(carName))); 
If you don't mind, can you post that ReturnVehicleID stock for me?
Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
CMD:car(playerid, params[])
{
    if(PlayerInfo[playerid][pRights] < 3) SendClientMessage(playerid, COL_RED, "[SERVER]: You don't have the rights to use this command.");
    else if(isnull(params)) SendClientMessage(playerid, COL_RED, "[USAGE]: /car [vehicle name / model].");
    else{
        new Model = ReturnVehicleID(params);
        if(Model == INVALID_VEHICLE_ID)
        {
            if(strlen(params) > 8) params[8] = EOS;
            Model = strval(params);
            if(!(400 <= Model <= 611))
                return SendClientMessage(playerid, COL_RED, "[SERVER]: Vehicle name/id not found.");
        }
        new message[75], Float:pPos[4], vid;
        GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
        GetPlayerFacingAngle(playerid, pPos[3]);
        vid = CreateVehicle(Model, pPos[0], pPos[1], pPos[2] + 1, pPos[3], 0, 1, 60);
        PutPlayerInVehicle(playerid, vid, 0);
        format(message, sizeof(message), "You have spawned a %s.", GetVehicleNames(vid));
        SendClientMessage(playerid, COL_GREEN, message);
    }
    return 1;
}
Thank you, this worked.