[Help] Vehicle Spawning with name
#1

Hello guys, I'm trying to script a function to spawn a vehicle by name or id, but I can't get it to work. (Logic fail?)

I have all the vehicle names defined in an array (vehNames), followed by this code to get the ID of the vehicle

Код:
stock GetVehicleModelFromName(const vname[])
{
	for(new i = 0; i < 211; i++)
	{
		if(strfind(vehNames[i], vname, true) != -1) //Finds vehicle id from array
		{
			return i + 400; //Returns corresponding vehicle ID to vehicle name from the array
		}
	}
	return -1;
}
Here's the command I tried

Код:
CMD:v(playerid, params[])
{
		new vString[21];
		new vId;
		
	
	    vId = GetVehicleModelFromName(vString); //Gives the function vString, the array to hold the vehicle name to search the array, stores return value (vehicle ID) in vId
		
		new Float:x, Float:y, Float:z;
		new Float:FacingAngle;
		if(isnull(params))
		{
		    SendClientMessage(playerid, RED, "You did not input a parameter");
		}
                else
                {
		GetPlayerPos(playerid, x, y, z);
		GetPlayerFacingAngle(playerid, FacingAngle);
		CreateVehicle(vId, x, y, z, FacingAngle, -1, -1, 60);
                }
	        return 1;
}
Commented is my logic on how this works, can someone help me figure out where my logic fail is?
Reply
#2

When it spawns do you want a label to be attached to it? Or when the player spawns it. It will say,"You have spawned a %s"?
Reply
#3

Try not defining vname as a constant in the function.

Edit:
Didn't even see that you forgot to put this in your command.

pawn Код:
vId = strval(params);
Reply
#4

Quote:
Originally Posted by Tee
Посмотреть сообщение
When it spawns do you want a label to be attached to it? Or when the player spawns it. It will say,"You have spawned a %s"?
Yeah

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
Try not defining vname as a constant in the function.

Edit:
Didn't even see that you forgot to put this in your command.

pawn Код:
vId = strval(params);
I removed the constant from vname, and where should I assign vId = strval(params)? I figured all i needed was the vehicle name, and from there i can strfind it and get the ID of the vehicle from there
Reply
#5

Oops. I forgot you were using that function. Try using the command like this at the top.

pawn Код:
CMD:v(playerid, params[])
{
    new vId;

    vId = GetVehicleModelFromName(params);
Reply
#6

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
Oops. I forgot you were using that function. Try using the command like this at the top.

pawn Код:
CMD:v(playerid, params[])
{
    new vId;

    vId = GetVehicleModelFromName(params);
It is at the top
Reply
#7

No, you never assigned vString to anything. How is the function supposed to determine the vehicle id from an empty string?
Reply
#8

Quote:
Originally Posted by Backwardsman97
Посмотреть сообщение
No, you never assigned vString to anything. How is the function supposed to determine the vehicle id from an empty string?
OH. Facepalm. I didn't notice (params)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)