Floats +REP -
Snoopythekill - 28.07.2015
Hello
How can i create a vehicle at a specific distance in front of another vehicle in a straight line ?
How can I create a vehicle at a specific distance in behind of another vehicle in a straight line ?
Don't know much about float variables and manipulation on them, what I want is to create a vehicle in front or behind of another and both must look to the same place(Angle).
Re: Floats +REP -
Evocator - 28.07.2015
Код:
stock GetXYInFrontOfVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
new
Float:a;
GetVehiclePos(vehicleid, x, y, a);
GetVehicleZAngle(vehicleid, a);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
stock GetXYBehindVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
new
Float:a;
GetVehiclePos(vehicleid, x, y, a);
GetVehicleZAngle(vehicleid, a);
x -= (distance * floatsin(-a, degrees));
y -= (distance * floatcos(-a, degrees));
}
Creating vehicle infront of the other:
Код:
GetVehiclePos(vehicleid, X, Y, Z);
GetXYInFrontOfVehicle(vehicleid, X, Y, 10.0);
CreateVehicle(.., X, Y, Z, 90.0 ...
Creating vehicle behind the other:
Код:
GetVehiclePos(vehicleid, X, Y, Z);
GetXYBehindVehicle(vehicleid, X, Y, 10.0);
CreateVehicle(.., X, Y, Z, 90.0 ...
Respuesta: Floats +REP -
Snoopythekill - 28.07.2015
Thanks, does not work, Perhaps this evil my code

.
PHP код:
CMD:front(playerid, params[])
{
new Float:pos[4], Float:fX, Float:fZ;
GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
GetVehicleModelInfo(GetPlayerVehicleID(playerid), VEHICLE_MODEL_INFO_SIZE, fX, pos[3], fZ);
GetXYInFrontOfVehicle(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[3]);
CreateVehicle(411, pos[0], pos[1], pos[2], pos[3], random(126), random(126), (60*60), 0);
return true;
}
CMD:behind(playerid, params[])
{
new Float:pos[4], Float:fX, Float:fZ;
GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
GetVehicleModelInfo(GetPlayerVehicleID(playerid), VEHICLE_MODEL_INFO_SIZE, fX, pos[3], fZ);
GetXYBehindVehicle(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[3]);
CreateVehicle(411, pos[0], pos[1], pos[2], pos[3], random(126), random(126), (60*60), 0);
return true;
}
Re: Floats +REP -
Vince - 28.07.2015
pos[3] is not the vehicle's angle, it is its length. Use normal variables to avoid confusions like that. Arrays, while more compact, are also slower for stuff like this.
Respuesta: Floats +REP -
Snoopythekill - 29.07.2015
Does not work, if anyone can give me an example of use with this code I thank you, the vehicle is created in the same position.
PHP код:
CMD:Front(playerid, params[])
{
new Float:fX, Float:fY, Float:fZ, Float:fD, Float:fA;
GetVehicleModelInfo(GetPlayerVehicleID(playerid), VEHICLE_MODEL_INFO_SIZE, fX, fD, fZ);
GetVehicleZAngle(GetPlayerVehicleID(playerid), fA);
GetVehiclePos(GetPlayerVehicleID(playerid), fX, fY, fZ);
GetXYInFrontOfVehicle(GetPlayerVehicleID(playerid), fX, fY, fD);
CreateVehicle(strval(params), fX, fY, fZ, fA, random(126), random(126), (60*60), 0);
return true;
}
Edit: The functions are working correctly, the mistake was mine when attempting to get the size to a vehiculoid when the parameter is modeloid. Thanks to Ralfie and Vince +REP.