SA-MP Forums Archive
Floats +REP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Floats +REP (/showthread.php?tid=583511)



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(playeridparams[])
{
    new 
Float:pos[4], Float:fXFloat:fZ;
    
GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
    
GetVehicleModelInfo(GetPlayerVehicleID(playerid), VEHICLE_MODEL_INFO_SIZEfXpos[3], fZ);
    
GetXYInFrontOfVehicle(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[3]);
    
CreateVehicle(411pos[0], pos[1], pos[2], pos[3], random(126), random(126), (60*60), 0);
    return 
true;
}
CMD:behind(playeridparams[])
{
    new 
Float:pos[4], Float:fXFloat:fZ;
    
GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
    
GetVehicleModelInfo(GetPlayerVehicleID(playerid), VEHICLE_MODEL_INFO_SIZEfXpos[3], fZ);
    
GetXYBehindVehicle(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[3]);
    
CreateVehicle(411pos[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(playeridparams[])
{
    new 
Float:fXFloat:fYFloat:fZFloat:fDFloat:fA;
    
GetVehicleModelInfo(GetPlayerVehicleID(playerid), VEHICLE_MODEL_INFO_SIZEfXfDfZ);
    
GetVehicleZAngle(GetPlayerVehicleID(playerid), fA);
    
GetVehiclePos(GetPlayerVehicleID(playerid), fXfYfZ);
    
GetXYInFrontOfVehicle(GetPlayerVehicleID(playerid), fXfYfD);
    
CreateVehicle(strval(params), fXfYfZfArandom(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.