Incognito Streamer
#1

Hello, I'm using a server which has many objects loaded dynamicly with CreateDynamicObject.
Now I've made a system where you can create a houses with furniture's.
Since there is no AttachDynamicObjectToDynamicObject I'm using the default GTA function (createobject,attachobjecttoobject). Now as there are to many objects some are dissapearing.
So I was wondering if anyone has a function to attach dynamic objects to another dynamic objects.

Thanks in advance.
Reply
#2

Well are the objects needed to be moved? Since this is only for the house furniture I assume that these objects are static, i.e. not moving.
If that's the case, since you already have the offsets, just apply them from the origin object to create a new dynamic object.
Reply
#3

Well, the houses can be placed anywahere. So the X,Y,Z offsets are diffrent in all occasions.
Thats why I need to use Attach to get the furniture's properly placed where they should be.
Reply
#4

Like I said, if you know the offsets, XYZ position and/or rotation of the object doesn't matter, using trigonometry you can still accomplish the same effect. YJIET a.k.a Stylock made a nice function for this. If you need my version, I can send it to you via PM.
Reply
#5

This is the third time in a week this application has come up and is pretty easy as a matter of fact.

pawn Code:
AttachObjectToObjectEx(attachoid, Float:off_x, Float:off_y, Float:off_z, Float:rot_x, Float:rot_y, Float:rot_z, &Float:X, &Float:Y, &Float:Z, &Float:RX, &Float:RY, &Float:RZ, pobject = 0) // By Stylock - http://forum.sa-mp.com/member.php?u=114165
{
        static
                Float:sin[3],
                Float:cos[3],
                Float:pos[3],
                Float:rot[3];
        if(pobject == 0)
        {
                GetObjectPos(attachoid, pos[0], pos[1], pos[2]);
                GetObjectRot(attachoid, rot[0], rot[1], rot[2]);
        }
        else if(pobject == 1)
        {
                GetPlayerObjectPos(pobject, attachoid, pos[0], pos[1], pos[2]);
                GetPlayerObjectRot(pobject, attachoid, rot[0], rot[1], rot[2]);
        }
        else if(pobject == 2)
        {
                GetDynamicObjectPos(pobject, attachoid, pos[0], pos[1], pos[2]);
                GetDynamicObjectRot(pobject, attachoid, rot[0], rot[1], rot[2]);
        }

       
        EDIT_FloatEulerFix(rot[0], rot[1], rot[2]);
        cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
        pos[0] = pos[0] + off_x * cos[1] * cos[2] - off_x * sin[0] * sin[1] * sin[2] - off_y * cos[0] * sin[2] + off_z * sin[1] * cos[2] + off_z * sin[0] * cos[1] * sin[2];
        pos[1] = pos[1] + off_x * cos[1] * sin[2] + off_x * sin[0] * sin[1] * cos[2] + off_y * cos[0] * cos[2] + off_z * sin[1] * sin[2] - off_z * sin[0] * cos[1] * cos[2];
        pos[2] = pos[2] - off_x * cos[0] * sin[1] + off_y * sin[0] + off_z * cos[0] * cos[1];
        rot[0] = asin(cos[0] * cos[1]); rot[1] = atan2(sin[0], cos[0] * sin[1]) + rot_z; rot[2] = atan2(cos[1] * cos[2] * sin[0] - sin[1] * sin[2], cos[2] * sin[1] - cos[1] * sin[0] * -sin[2]);
        cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
        rot[0] = asin(cos[0] * sin[1]); rot[1] = atan2(cos[0] * cos[1], sin[0]); rot[2] = atan2(cos[2] * sin[0] * sin[1] - cos[1] * sin[2], cos[1] * cos[2] + sin[0] * sin[1] * sin[2]);
        cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
        rot[0] = atan2(sin[0], cos[0] * cos[1]) + rot_x; rot[1] = asin(cos[0] * sin[1]); rot[2] = atan2(cos[2] * sin[0] * sin[1] + cos[1] * sin[2], cos[1] * cos[2] - sin[0] * sin[1] * sin[2]);
        cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
        rot[0] = asin(cos[1] * sin[0]); rot[1] = atan2(sin[1], cos[0] * cos[1]) + rot_y; rot[2] = atan2(cos[0] * sin[2] - cos[2] * sin[0] * sin[1], cos[0] * cos[2] + sin[0] * sin[1] * sin[2]);
        X = pos[0];
        Y = pos[1];
        Z = pos[2];
        RX = rot[0];
        RY = rot[1];
        RZ = rot[2];
}


EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
{
    EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
    if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
    && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
    {
        rot_y = 0.0000002;
    }
    return 1;
}

EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
{
    EDIT_FloatRemainder(rot_x, 360.0);
    EDIT_FloatRemainder(rot_y, 360.0);
    EDIT_FloatRemainder(rot_z, 360.0);
    return 1;
}

EDIT_FloatRemainder(&Float:remainder, Float:value)
{
    if(remainder >= value)
    {
        while(remainder >= value)
        {
            remainder = remainder - value;
        }
    }
    else if(remainder < 0.0)
    {
        while(remainder < 0.0)
        {
            remainder = remainder + value;
        }
    }
    return 1;
}
Reply
#6

Urgh I'm sorry to bother you but I don't completely understand this function.

Right now this is my piece:
Quote:

HouseInfo[t][HouseObjectID] = CreateObject(12991, HouseInfo[t][HX], HouseInfo[t][HY], HouseInfo[t][HZ]-0.9, 0, 0, HouseInfo[t][HA]+180);

HouseInfo[t][Wall1] = CreateObject(2395, HouseInfo[t][HX], HouseInfo[t][HY], HouseInfo[t][HZ]-0.9, 0, 0, HouseInfo[t][HA]+180);

AttachObjectToObject(HouseInfo[t][Wall1], HouseInfo[t][HouseObjectID], 2.01, 3.055, -2.73, 0.0, 0.0, 180.0, 1);

If it's not to much work for you could you please change this piece in the way it should be used with the function you just stated? I would highly appreciate it!
I believe if I see a given example I would have no struggles doing the rest myself.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)