Last active
November 9, 2018 11:09
-
-
Save carlos-menezes/d7ec513f1cfc10597bfdb68d8bc066d5 to your computer and use it in GitHub Desktop.
Move two objects and keep their distance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <a_samp> | |
#include <streamer> | |
#include <sscanf2> | |
#include <Pawn.CMD> | |
main() {} | |
new g_Objects[2]; | |
public OnGameModeInit() { | |
g_Objects[0] = CreateDynamicObject(2000, 165.72412, 1718.35168, 16.62031, 0.00000, 0.00000, 0.00000); // A | |
g_Objects[1] = CreateDynamicObject(2000, 160.16754, 1727.65771, 16.62031, 0.00000, 0.00000, 0.00000); // B | |
return 1; | |
} | |
CMD:move(playerid, params[]) { | |
// A = (3, 2) | |
// B = (5, 6) | |
// C = (6, 0) -> A after translation | |
// D = (8, 4) | |
new Float:newPos[3], // New position of A. | |
Float:aObjPos[3], // Initial position of A. | |
Float:bObjPos[3], // Initial position of B. | |
Float:distance[3]; // Coordinates difference between B and A. | |
if(sscanf(params, "fff", newPos[0], newPos[1], newPos[2])) return SendClientMessage(playerid, -1, "Usage: /move Float:x Float:y Float:z"); | |
GetDynamicObjectPos(g_Objects[0], aObjPos[0], aObjPos[1], aObjPos[2]); // Obtain the coordinates of A, passed by refence to aObjPos. | |
GetDynamicObjectPos(g_Objects[1], bObjPos[0], bObjPos[1], bObjPos[2]); // Obtain the coordinates of B, passed by refence to bObjPos. | |
// Calculating the distance between B and A's coordinates. | |
//distance[0] = bObjPos[0] - aObjPos[0]; | |
//distance[1] = bObjPos[1] - aObjPos[1]; | |
//distance[2] = bObjPos[2] - aObjPos[2]; | |
for(new i = 0; i < sizeof distance; i++) { | |
distance[i] = bObjPos[i] - aObjPos[i]; | |
} | |
SetDynamicObjectPos(g_Objects[0], newPos[0], newPos[1], newPos[2]); // Apply the input coordinates to object A. | |
SetDynamicObjectPos(g_Objects[1], newPos[0] + distance[0], newPos[1] + distance[1], newPos[2] + distance[2]); // To B, we apply A's coordinates + the distance between the coordinates of the initial positions. | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment