28.03.2011, 21:42
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
Here's the command I tried
Commented is my logic on how this works, can someone help me figure out where my logic fail is?
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;
}
Код:
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;
}


