Yes there is a way to do this quite easily your looking at making prefabricated object sets basically I will list the steps involved.
Exporting:
1.) Group objects to be exported to prefab
2.) Calculate group center
3.) Delta each object position by subtracting each X, Y, Z of each object from the X, Y, Z of the group center
4.) Save object positions to file
Importing.
1.) Get players position + generate object offset position
2.) Load prefab objects and delta offset the positions with the positions from step 1
That is pretty much it but it gets a lot more complex when you want to start rotating groups of objects but those are the basic steps to using prefabs.
Here is my GetGroupCenter() function this will have to be changed to work with your code but it shows the steps in obtaining that value.
pawn Код:
//--------------------------------------------------
stock GetGroupCenter(playerid, &Float:X, &Float:Y, &Float:Z)
{
// Number of objects grouped
new numobjects;
// Object array reference ID
new MSelID;
// High XYZ range
new Float:highX;
new Float:highY;
new Float:highZ;
// Low XYZ range
new Float:lowX;
new Float:lowY;
new Float:lowZ;
// Loop through grouped objects
for(new i = 0; i < MAX_OBJECTS; i++)
{
// No object selected in this group entry continue
if(GroupObjects[playerid][i] == INVALID_OBJECT_ID) continue;
// Object found in group
numobjects++;
// Gets the object array reference ID (Only for readability)
MSelID = GroupObjects[playerid][i];
// First iteration of group bounding box selection always assume first object is on the high end
if(numobjects == 1)
{
highX = objects[MSelID][ox];
highY = objects[MSelID][oy];
highZ = objects[MSelID][oz];
}
// Second iteration we will now have low values as well
else if(numobjects == 2)
{
if(objects[MSelID][ox] > highX)
{
lowX = highX;
highX = objects[MSelID][ox];
}
else lowX = objects[MSelID][ox];
if(objects[MSelID][oy] > highY)
{
lowY = highY;
highY = objects[MSelID][oy];
}
else lowY = objects[MSelID][oy];
if(objects[MSelID][oz] > highZ)
{
lowZ = highZ;
highZ = objects[MSelID][oz];
}
else lowZ = objects[MSelID][oz];
}
// Additional iterations we only need to check for higher or lower values
else
{
if(objects[MSelID][ox] > highX) highX = objects[MSelID][ox];
else if(objects[MSelID][ox] < lowX) lowX = objects[MSelID][ox];
if(objects[MSelID][oy] > highY) highY = objects[MSelID][oy];
else if(objects[MSelID][oy] < lowY) lowY = objects[MSelID][oy];
if(objects[MSelID][oz] > highZ) highZ = objects[MSelID][oz];
else if(objects[MSelID][oz] < lowZ) lowZ = objects[MSelID][oz];
}
}
// Not enough grouped objects return 0
if(numobjects <= 1) return 0;
// Calculate bounding box the group center is defined as the average between " (high + low) / 2 " for each X Y Z value
else
{
// new line[128];
// format(line, sizeof(line), "hx: %f hy: %f hz: %f lx: %f ly: %f lz: %f", highX, highY, highZ, lowX, lowY, lowZ);
// SendClientMessage(playerid, 0xFF00FFFF, line);
X = (highX + lowX) / 2;
Y = (highY + lowY) / 2;
Z = (highZ + lowZ) / 2;
}
return 1;
}