SA-MP Forums Archive
Retrieving object position while attached to a car - 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: Retrieving object position while attached to a car (/showthread.php?tid=594664)



Retrieving object position while attached to a car - PaulDinam - 21.11.2015

I'm making a vehicle attachments system and when an object is attached to a vehicle and the player tries to edit it, it won't let him. So i'm trying to recreate the object everytime a player wants to adjust the position of it. However, I have no idea how to get the object's position. GetObjectPos wouldn't work normally because the object is attached.


Re: Retrieving object position while attached to a car - Abagail - 21.11.2015

If you are trying to get the attached position you need to offset it from the vehicle's coordinates.

pawn Код:
stock GetAttachedObjectPos(objectid, vehicleid, &Float: x, &Float: y, &Float: z)
{
    if(IsValidObject(objectid) && GetVehicleModel(vehicleid))
    {
            new Float: pos[3], Float: vpos[3];
            GetObjectPos(objectid, pos[0], pos[1], pos[2]);
            GetVehiclePos(vehicleid, vpos[0], vpos[1], vpos[2]);

            x = vpos[0]-pos[0];
            y = vpos[1]-pos[1];
            z = vpos[2]-pos[2];
            return 1;
    }

    else return 0;
}