SA-MP Forums Archive
Drop Object Back Of Vehicle - 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: Drop Object Back Of Vehicle (/showthread.php?tid=312351)



Drop Object Back Of Vehicle - sameer419 - 21.01.2012

Hey, i wanna know, if i pressed <KEY_FIRE> a object should drop back of playerid vehicle.
But the x and y position changes when we make turn, how should i make it the same??
Can't figure out, help pls.

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_FIRE))
    {
        new currentveh;
        currentveh = GetPlayerVehicleID(playerid);

        new Float:vehx, Float:vehy, Float:vehz;
        GetVehiclePos(currentveh, vehx, vehy, vehz); //x+0.13 y-5.30 z+0.27
        CreateObject(1518,vehx+0.13,vehy-5.30,vehz,0.00000000,0.00000000,0.00000000); //object(barrel4) (1)
    }
    return 1;
}



Re: Drop Object Back Of Vehicle - jamesbond007 - 21.01.2012

GetVehicleZAngle? idk


also might be possible with

GetVehicleRotationQuat

but u try and figure that one out!


Re: Drop Object Back Of Vehicle - sameer419 - 21.01.2012

But to create object we dont need floatz.
It works on some calculation and i m not perfect in maths.. :/


Re: Drop Object Back Of Vehicle - Universal - 21.01.2012

pawn Код:
stock GetXYBehindPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:angle,Float:distance)
{
    x2 = x - (distance * floatsin(-angle,degrees));
    y2 = y - (distance * floatcos(-angle,degrees));
}
Try this stock.


Re: Drop Object Back Of Vehicle - sameer419 - 21.01.2012

Thanks but it did'nt worked out..
anyone help appreciated!

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (PRESSED(KEY_FIRE))
    {
        /*if (IsPlayerInAnyVehicle(playerid))
        {
            AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
        }*/

        new currentveh;
        currentveh = GetPlayerVehicleID(playerid);

        new Float:vehx, Float:vehy, Float:vehz, Float:distance, Float:angle, Float:x2, Float:y2;
        GetVehiclePos(currentveh, vehx, vehy, vehz); //x+0.13 y-5.30 z+0.27
        GetVehicleDistanceFromPoint(currentveh, vehx, vehy, vehz);
        GetVehicleZAngle(currentveh, angle);
        GetXYBehindPoint(vehx, vehy, x2, y2, angle, distance);
        CreateObject(1225,x2,y2,vehz,0.00000000,0.00000000,0.00000000); //object(barrel4) (1)
    }
    return 1;
}
stock GetXYBehindPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:angle,Float:distance)
{
    x2 = x - (distance * floatsin(-angle,degrees));
    y2 = y - (distance * floatcos(-angle,degrees));
}



Re: Drop Object Back Of Vehicle - [XST]O_x - 21.01.2012

Instead of creating a variable for distance you should type the distance you would like the object to be created in.

Like this:

pawn Код:
GetXYBehindPoint(vehx, vehy, x2, y2, angle, 5);
CreateObject(1225,x2,y2,vehz,0.00000000,0.00000000,0.00000000);
That would create the object 5 units behind the car.


Re: Drop Object Back Of Vehicle - sameer419 - 21.01.2012

Thanks my frnd reputation + for bth