[Help] Vehicle Spawning with name -
Placebo - 28.03.2011
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?
Re: [Help] Vehicle Spawning with name -
Tee - 28.03.2011
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"?
Re: [Help] Vehicle Spawning with name -
Backwardsman97 - 28.03.2011
Try not defining vname as a constant in the function.
Edit:
Didn't even see that you forgot to put this in your command.
Re: [Help] Vehicle Spawning with name -
Placebo - 28.03.2011
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.
|
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
Re: [Help] Vehicle Spawning with name -
Backwardsman97 - 28.03.2011
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);
Re: [Help] Vehicle Spawning with name -
Placebo - 28.03.2011
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
Re: [Help] Vehicle Spawning with name -
Backwardsman97 - 28.03.2011
No, you never assigned vString to anything. How is the function supposed to determine the vehicle id from an empty string?
Re: [Help] Vehicle Spawning with name -
Placebo - 28.03.2011
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)