Vehicle spawn with name
#1

Ok so I got a vehicle spawn command that saves in a file but I want it to spawn by doing vehicle name like: /veh Hunter (colorid) (colorid)
At the moment it's made for carid only.

Heres the code
Код:
	if(strcmp(cmd, "/veh", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
	    if (PlayerInfo[playerid][pAdmin] < 6)
			{
			  SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
			  return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
				return 1;
			}
			new car;
			car = strval(tmp);
			if(car < 400 || car > 611) { SendClientMessage(playerid, COLOR_GREY, "  Vehicle Number can't be below 400 or above 611 !"); return 1; }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
				return 1;
			}
			new color1;
			color1 = strval(tmp);
			if(color1 < -1 || color1 > 126) { SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !"); return 1; }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
				return 1;
			}
			new color2;
			color2 = strval(tmp);
			if(color2 < -1 || color2 > 126) { SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !"); return 1; }
			new Float:X,Float:Y,Float:Z;
			GetPlayerPos(playerid, X,Y,Z);
			new carid = CreateVehicle(car, X,Y+5,Z+1, 0.0, color1, color2, 60000);
			CreatedCars[CreatedCar] = carid;
			CreatedCar ++;
			LinkVehicleToInterior(carid, GetPlayerInterior(playerid));
			SetVehicleVirtualWorld(carid, GetPlayerVirtualWorld(playerid));
			format(string, sizeof(string), "** Vehicle %d spawned.", carid);
			SendClientMessage(playerid, COLOR_GREY, string);
			new y, m, d;
			new h,mi,s;
			getdate(y,m,d);
			gettime(h,mi,s);
			format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has Spawned the Car [%d] (Color 1: %d | Color 2: %d) At His Position.",d,m,y,h,mi,s,sendername,carid,color1,color2);
			AdminLog(string);
		}
		return 1;
	}
Help would be really appreciated
Reply
#2

have a look in the LAdmin filterscript, it has a /car <ID/Name> command
http://forum.sa-mp.com/index.php?topic=36990.0
Reply
#3

Quote:
Originally Posted by Babul
have a look in the LAdmin filterscript, it has a /car <ID/Name> command
http://forum.sa-mp.com/index.php?topic=36990.0
I looked at the /car command but there is alot there and im really confused.Thanks for the help though.
Reply
#4

Here is the stuff needed to do that. Just copy it into your include or at the top of your script.

pawn Код:
new const VehicleNames[][] =
{
"Landstalker",
"Bravura",
"Buffalo",
"Linerunner",
"Perenniel",
"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",
"Squallo",
"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",
"SAN News Maverick",
"Rancher",
"FBI Rancher",
"Virgo",
"Greenwood",
"Jetmax",
"Hotring Racer",
"Sandking",
"Blista Compact",
"Police Maverick",
"Boxville",
"Benson",
"Mesa",
"RC Goblin",
"Hotring Racer 2",
"Hotring Racer 3",
"Bloodring Banger",
"Rancher 2",
"Super GT",
"Elegant",
"Journey",
"Bike",
"Mountain Bike",
"Beagle",
"Cropduster",
"Stuntplane",
"Tanker",
"Roadtrain",
"Nebula",
"Majestic",
"Buccaneer",
"Shamal",
"Hydra",
"FCR-900",
"NRG-500",
"HPV1000",
"Cement Truck",
"Towtruck",
"Fortune",
"Cadrona",
"FBI Truck",
"Willard",
"Forklift",
"Tractor",
"Combine Harvester",
"Feltzer",
"Remington",
"Slamvan",
"Blade",
"Freight",
"Brownstreak",
"Vortex",
"Vincent",
"Bullet",
"Clover",
"Sadler",
"Firetruck LA",
"Hustler",
"Intruder",
"Primo",
"Cargobob",
"Tampa",
"Sunrise",
"Merit",
"Utility Van",
"Nevada",
"Yosemite",
"Windsor",
"Monster A",
"Monster B",
"Uranus",
"Jester",
"Sultan",
"Stratum",
"Elegy",
"Raindance",
"RC Tiger",
"Flash",
"Tahoma",
"Savanna",
"Bandito",
"Freight Flat Trailer",
"Streak Trailer",
"Kart",
"Mower",
"Dune",
"Sweeper",
"Broadway",
"Tornado",
"AT400",
"DFT-30",
"Huntley",
"Stafford",
"BF-400",
"Newsvan",
"Tug",
"Petrol Trailer",
"Emperor",
"Wayfarer",
"Euros",
"Hotdog",
"Club",
"Freight Box Trailer",
"Article Trailer 3",
"Andromada",
"Dodo",
"RC Cam",
"Launch",
"Police Car (LSPD)",
"Police Car (SFPD)",
"Police Car (LVPD)",
"Police Ranger",
"Picador",
"S.W.A.T.",
"Alpha",
"Phoenix",
"Glendale Shit",
"Sadler Shit",
"Baggage Trailer A",
"Baggage Trailer B",
"Tug Stairs Trailer",
"Boxville 2",
"Farm Trailer",
"Utility Trailer"
};

stock bool:IsNumericChar(character) return character > 47 && character < 58;

stock GetCharsCount(const string[], ...)
{
new Count, num = numargs();
for(new n = 1; n<num; n++) for(new i; i<strlen(string); i++) if(getarg(n, 0) && string[i] == getarg(n, 0)) Count++;
return Count;
}

stock GetNumericCharsCount(const string[]) return GetCharsCount(string, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57);

stock bool:IsNumeric(const string[]) return GetNumericCharsCount(string) == strlen(string);

stock bool:GetNumericPartOfString(const string[], output[], &index)
{
new lenght = strlen(string);
if(!lenght || !GetNumericCharsCount(string)) return false;
while(index < lenght && !IsNumericChar(string[index])) index++;
new offset = index;
while(index < lenght && IsNumericChar(string[index])) output[index - offset] = string[index], index++;
return true;
}

stock GetVehicleModelFromName(const name[])
{
if(IsNumeric(name)) return strval(name);
for(new i; i<sizeof(VehicleNames); i++) if(strfind(VehicleNames[i], name, true) != -1) return i + 400;
new output[5], index;
if(GetNumericPartOfString(name, output, index) && strval(output) < 612 && strval(output) > 399) return strval(output);
return 0;
}
Just put this into the script:

pawn Код:
new Model = GetVehicleModelFromName(tmp);
Have fun.
Reply
#5

Quote:
Originally Posted by ¤Adas¤
Here is the stuff needed to do that. Just copy it into your include or at the top of your script.

[pawn]
Just put this into the script:

pawn Код:
new Model = GetVehicleModelFromName(tmp);
Have fun.
Where do I put this into the script?
Reply
#6

Omg, into the command
Reply
#7

pawn Код:
if(strcmp(cmd, "/veh", true) == 0)
    {
        if (PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
            new car = GetVehicleModelFromName(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
            new color1;
            color1 = strval(tmp);
            if(color1 < -1 || color1 > 126) return SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !");
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
            new color2;
            color2 = strval(tmp);
            if(color2 < -1 || color2 > 126) return SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !");
            new Float:X,Float:Y,Float:Z;
            GetPlayerPos(playerid, X,Y,Z);
            new carid = CreateVehicle(car, X,Y+5,Z+1, 0.0, color1, color2, 60000);
            CreatedCars[CreatedCar] = carid;
            CreatedCar ++;
            LinkVehicleToInterior(carid, GetPlayerInterior(playerid));
            SetVehicleVirtualWorld(carid, GetPlayerVirtualWorld(playerid));
            format(string, sizeof(string), "** Vehicle %d spawned.", carid);
            SendClientMessage(playerid, COLOR_GREY, string);
            new y, m, d;
            new h,mi,s;
            getdate(y,m,d);
            gettime(h,mi,s);
            format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has Spawned the Car [%d] (Color 1: %d | Color 2: %d) At His Position.",d,m,y,h,mi,s,sendername,carid,color1,color2);
            AdminLog(string);
        return 1;
    }
Reply
#8

Quote:
Originally Posted by ¤Adas¤
pawn Код:
if(strcmp(cmd, "/veh", true) == 0)
    {
        if (PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GRAD1, "  you are not authorized to use that command!");
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
            new car = GetVehicleModelFromName(tmp);
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
            new color1;
            color1 = strval(tmp);
            if(color1 < -1 || color1 > 126) return SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !");
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /veh [carid] [color1] [color2]");
            new color2;
            color2 = strval(tmp);
            if(color2 < -1 || color2 > 126) return SendClientMessage(playerid, COLOR_GREY, "  Color Number can't be below 0 or above 126 !");
            new Float:X,Float:Y,Float:Z;
            GetPlayerPos(playerid, X,Y,Z);
            new carid = CreateVehicle(car, X,Y+5,Z+1, 0.0, color1, color2, 60000);
            CreatedCars[CreatedCar] = carid;
            CreatedCar ++;
            LinkVehicleToInterior(carid, GetPlayerInterior(playerid));
            SetVehicleVirtualWorld(carid, GetPlayerVirtualWorld(playerid));
            format(string, sizeof(string), "** Vehicle %d spawned.", carid);
            SendClientMessage(playerid, COLOR_GREY, string);
            new y, m, d;
            new h,mi,s;
            getdate(y,m,d);
            gettime(h,mi,s);
            format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s Has Spawned the Car [%d] (Color 1: %d | Color 2: %d) At His Position.",d,m,y,h,mi,s,sendername,carid,color1,color2);
            AdminLog(string);
        return 1;
    }
Thanks a bunch It work's like a charm
Reply
#9

No problem
Reply
#10

Hmm. I have a problem with this,,,
Here are the Errors:
pawn Код:
C:\Users\Alen\Desktop\PROGRAMING\Serious-Gaming RolePlay\gamemodes\lsrp.pwn(921) : error 025: function heading differs from prototype
C:\Users\Alen\Desktop\PROGRAMING\Serious-Gaming RolePlay\gamemodes\lsrp.pwn(921) : error 021: symbol already defined: "IsNumeric"
And here is the line:
pawn Код:
stock bool:IsNumeric(const string[]) return GetNumericCharsCount(string) == strlen(string);
Pls Help..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)