SA-MP Forums Archive
hey how to detect this cords - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: hey how to detect this cords (/showthread.php?tid=180698)



hey how to detect this cords - iJumbo - 02.10.2010

hey how to detect this cord for make explosion




Re: hey how to detect this cords - playbox12 - 02.10.2010

Get the X Y Z, and ad +4 to the X and ?

pawn Код:
new Float: X, Float: Y, Float: Z;
GetPlayerPos(playerid, X, Y, Z);

CreateExplosion(X+4, Y, Z, 2, 10);
That will create +4 units in the X direction, do the same with Y, and X and Y at the same time for oblique

Or did I misunderstood your question?


Re: hey how to detect this cords - Mauzen - 02.10.2010

Samp rotations seem to be incopatible to the pawn sin/cos values, I have no idea why.

This means, at first, you need to invert the players facing angle.
The inverted angle now points to the front of the player, if you want to get a point e.g. 100° right of him or so, add an offset. I think -degrees to go right, and +degrees to go left (-90 would point to the right of the player, 180 to the back, ...)
Now you can use floatsin, floatcos and some basic math knowledge to calculate the point you want to have.

The result could look like this:

pawn Код:
public GetPlayerRelativeCoords(playerid, Float:angle, Float:distance, &Float:x, &Float:y, &Float:z)
{
    new Float:rot;
    GetPlayerFacingAngle(playerid, rot);
    rot = 360 - rot + angle;

    GetPlayerPos(playerid, x, y, z);
    x = x + floatsin(rot, degrees) * distance;
    y = y + floatcos(rot, degrees) * distance;
    return 1;
}
It may work, but i just wrote it from nothing + there is some green smoke here in my room, so i cant guarantee for it to work


Re: hey how to detect this cords - bigcomfycouch - 02.10.2010

pawn Код:
#define EXPLOSION_OFFSET                (3.5)

new
    Float:x,
    Float:y,
    Float:z;
GetPlayerPos(playerid, x, y, z);
CreateExplosion(x, y - EXPLOSION_OFFSET, z, 2, 3.0);
CreateExplosion(x, y + EXPLOSION_OFFSET, z, 2, 3.0);
CreateExplosion(x - EXPLOSION_OFFSET, y - EXPLOSION_OFFSET, z, 2, 3.0);
CreateExplosion(x + EXPLOSION_OFFSET, y + EXPLOSION_OFFSET, z, 2, 3.0);
CreateExplosion(x - EXPLOSION_OFFSET, y + EXPLOSION_OFFSET, z, 2, 3.0);
CreateExplosion(x + EXPLOSION_OFFSET, y - EXPLOSION_OFFSET, z, 2, 3.0);



Re: hey how to detect this cords - samgreen - 02.10.2010

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Samp rotations seem to be incopatible to the pawn sin/cos values, I have no idea why.

This means, at first, you need to invert the players facing angle.
The inverted angle now points to the front of the player, if you want to get a point e.g. 100° right of him or so, add an offset. I think -degrees to go right, and +degrees to go left (-90 would point to the right of the player, 180 to the back, ...)
Now you can use floatsin, floatcos and some basic math knowledge to calculate the point you want to have.

The result could look like this:

pawn Код:
public GetPlayerRelativeCoords(playerid, Float:angle, Float:distance, &Float:x, &Float:y, &Float:z)
{
    new Float:rot;
    GetPlayerFacingAngle(playerid, rot);
    rot = 360 - rot + angle;

    GetPlayerPos(playerid, x, y, z);
    x = x + floatsin(rot, degrees) * distance;
    y = y + floatcos(rot, degrees) * distance;
    return 1;
}
It may work, but i just wrote it from nothing + there is some green smoke here in my room, so i cant guarantee for it to work
Yep, just make this a stock. No need to be a public. Then call it like so:

pawn Код:
#define EXPLOSION_DISTANCE  3.5
#define EXPLOSION_TYPE      8
#define EXPLOSION_RADIUS    7.0

new Float:playerPos[4];
for (new angle = 0; angle < 360; angle += 45) {
    // Get the player's position and angle
    GetPlayerPos(playerid, playerPos[0], playerPos[1], playerPos[2]);
    GetPlayerFacingAngle(playerid, playerPos[3]);
   
    // Store the new position calculated by our function
    GetPlayerRelativeCoords(playerid, playerPos[3], EXPLOSION_DISTANCE, playerPos[0], playerPos[1], playerPos[2]);
   
    // Create the explosion
    CreateExplosion(playerPos[0], playerPos[1], playerPos[2], EXPLOSION_TYPE, EXPLOSION_RADIUS);
}
This code is not tested either, and there is also tons of green smoke in my room. Good luck!

Edit: Bigcomfycouch's solution will probably get the desired effect visually, but it is entirely wrong mathematically and it won't scale to larger distances.


Re: hey how to detect this cords - iJumbo - 02.10.2010

thx all works :d