SA-MP Forums Archive
How do I calculate the gta cords from objects/car offsets? - 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: How do I calculate the gta cords from objects/car offsets? (/showthread.php?tid=489229)



How do I calculate the gta cords from objects/car offsets? - robanswe - 21.01.2014

How do I calculate the GTA cords from objects/car offsets?

For example how do I calculate the GTA cords from this offset: 1.051757,-2.713012,-0.012840 if the cars GTA cords are: -1377.2820,-256.9163,14.0373,328.7105

I have tried something like this:
x += (tmpX * floatsin(-angle, degrees));
x += (tmpX * floatcos(-angle, degrees));
y += (tmpY * floatsin(-angle, degrees));
y += (tmpY * floatcos(-angle, degrees));

But it didn't work.


Re: How do I calculate the gta cords from objects/car offsets? - Kyle - 21.01.2014

Not really 0.3z relevant, try scripting help section.


Re: How do I calculate the gta cords from objects/car offsets? - robanswe - 21.01.2014

Quote:
Originally Posted by KyleSmith
View Post
Not really 0.3z relevant, try scripting help section.
Yeah you're sort of right I had OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ); in my mind the whole time.


Re: How do I calculate the gta cords from objects/car offsets? - MP2 - 21.01.2014

Just add the offset to the coordinate. Simples.


Re: How do I calculate the gta cords from objects/car offsets? - robanswe - 21.01.2014

Quote:
Originally Posted by MP2
View Post
Just add the offset to the coordinate. Simples.
Thank you but I'm already doing this and it's only working when the angel is 0. If the angel is not 0 but instead like my example 328.7105 it will not work.


Re: How do I calculate the gta cords from objects/car offsets? - kurta999 - 21.01.2014

Not.

This will only work if your angle is 0.0.


Re: How do I calculate the gta cords from objects/car offsets? - robanswe - 21.01.2014

Quote:
Originally Posted by kurta999
View Post
Not.

This will only work if your angle is 0.0.
But I should be able to make some calculations from the offsets and the angel to get to the real cords? If not why? I mean I got the cars cords and it's angel + the offset. I can't understand why you can't calculate the real GTA cord from that.


Re: How do I calculate the gta cords from objects/car offsets? - kurta999 - 21.01.2014

I replyed for this:

Just add the offset to the coordinate. Simples.

Anyway, I found this:

http://forum.sa-mp.com/showthread.ph...68#post2854568


Re: How do I calculate the gta cords from objects/car offsets? - Pottus - 21.01.2014

Non-sense


Re: How do I calculate the gta cords from objects/car offsets? - Pottus - 21.01.2014

Ok I worked this out over several hours and found it's actually very very easy to do.

You'll need this by GamerZ
http://gpb.******code.com/svn/trunk/...icleMatrix.inc

Here is some test code.

pawn Code:
#include <a_samp>
#include <vmatrix>

public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if(hittype == BULLET_HIT_TYPE_VEHICLE)
    {
        new tmp, Float:x, Float:y, Float:z;

        // This will get the world offset based on vehicle rotation and return the
        // correct position to spawn an object
        PositionFromVehicleOffset(hitid,fX,fY,fZ, x, y, z);
        tmp = CreateObject(1974, x, y, z, 0.0, 0.0, 300.0);

        // Simple attach offsets are automatically calculated you just need to supply a offset for some objects
        AttachObjectToVehicle(tmp, hitid, fX,fY,fZ, 0.0, 0.0, 0.0);

        SetTimerEx("RemoveObject", 9000, false, "i", tmp);

    }
    return 1;
}

forward RemoveObject(id);
public RemoveObject(id)
{
    DestroyObject(id);
    return 1;
}