Spawn multiple objects at ANY location and move them together.
#1

Hey there guys, I've made a TV using paintings and I made a stance aswell etcetera, now I want to use them for more interiors and preferbly spawn them, is there a possibility to spawn them the way the objects are placed by each other at any location and move them by example /move x y z without loosing it's form?

If yes, please explain me how this works.

Thanks in advance.
Reply
#2

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;
}
Reply
#3

Can you explain this in an easier way? Or do this for me? It's really hard to understand for me, basically my object is a TV which are these codes:

Код:
tv = CreateObject(2258, 250.509780, -176.675003, 11.042193, 0.000000, 0.000000, 0.000000);
SetObjectMaterial(tv, 0, 2258, "none", "none", -16777216);
tv1 = CreateObject(2074, 249.850082, -176.462387, 10.599217, -87.000007, 0.000000, 0.000000);
SetObjectMaterial(tv1, 0, 2074, "none", "none", -65536);
tv2 = CreateObject(2258, 249.158233, -176.677307, 11.042193, 0.000000, 0.000000, 0.000000);
SetObjectMaterial(tv2, 0, 2258, "none", "none", -16777216);
Reply
#4

I don't know how else to explain it, I can't do it for you but I can let you use some tools that will let you do it yourself.
Reply
#5

Okay, I wanna give it a try with the tools you are talking about

Thanks in Advance.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)