PDA

View Full Version : how to attach an object to an object by a command ?


Jhony_Blaze
09/03/2014, 12:14 PM
The title says it all, how can I attach an object to a other object with a command,also how t can I do it that the same command can do other thing too: Example opening a gate and at the same time attaching an object to different object.


Thanks!Hope you understand what I mean!

arakuta
09/03/2014, 12:20 PM
This is simple! All you have to know is basics about creating some commands!

http://forum.sa-mp.com/showthread.php?t=280476

To attach an objecto into another object use this:

http://wiki.sa-mp.com/wiki/AttachObjectToObject

To 'open' gates, just move them using this:

http://wiki.sa-mp.com/wiki/MoveObject

To 'close' gates, just move them back to the original position.

Try, and post your doubts here ;D

The final result should be like this:

CMD:opengateandattach(playerid)
{
//MoveObect...
//AttachObjectToObject...
SendClientMessage(playerid,-1,"You opened the gate!");
// Don't forget a way to close the gate, and a check to know if the gate is open will be also good ;)
return 1;
}

Jhony_Blaze
09/03/2014, 12:42 PM
This is simple! All you have to know is basics about creating some commands!

http://forum.sa-mp.com/showthread.php?t=280476

To attach an objecto into another object use this:

http://wiki.sa-mp.com/wiki/AttachObjectToObject

To 'open' gates, just move them using this:

http://wiki.sa-mp.com/wiki/MoveObject

To 'close' gates, just move them back to the original position.

Try, and post your doubts here ;D

The final result should be like this:

CMD:opengateandattach(playerid)
{
//MoveObect...
//AttachObjectToObject...
SendClientMessage(playerid,-1,"You opened the gate!");
// Don't forget a way to close the gate, and a check to know if the gate is open will be also good ;)
return 1;
}



Tried that but didn't worked out well..

arakuta
09/03/2014, 12:46 PM
Tried that but didn't worked out well..

What did you tried? Post here, so we can help you.

Jhony_Blaze
09/03/2014, 01:00 PM
Sure this is how I tried to make it:


CMD:bay1o(playerid, params[])
{
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
SendClientMessage(playerid, COLOR_GREEN,"Bay 1 is open");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 16.3944, 1);

return 1;
}

RenovanZ
09/03/2014, 01:04 PM
Sure this is how I tried to make it:


CMD:bay1o(playerid, params[])
{
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
SendClientMessage(playerid, COLOR_GREEN,"Bay 1 is open");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 16.3944, 1);

return 1;
}

This
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
The first 2 parameters is objectid, not modelid.

Jhony_Blaze
09/03/2014, 01:08 PM
This
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
The first 2 parameters is objectid, not modelid.

Those are the object ids, the first one is the object I want to attach to the other object, and the second one is the object to attach the object to

Jhony_Blaze
09/03/2014, 01:24 PM
Okay now I made the object to appear, this is how all the script looks like, but now the gate wont open:

CMD:bay1o(playerid, params[])
{
Gate1[playerid] = CreateObject(1238, -269.2469, 1187.2875, 23.1069, 0.0000, 0.0000, 0.0000);
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
SendClientMessage(playerid, COLOR_GREEN,"Bay 1 is open");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 16.3944, 1);
return 1;
}

RenovanZ
09/03/2014, 01:30 PM
Okay now I made the object to appear, this is how all the script looks like, but now the gate wont open:

CMD:bay1o(playerid, params[])
{
Gate1[playerid] = CreateObject(1238, -269.2469, 1187.2875, 23.1069, 0.0000, 0.0000, 0.0000);
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
SendClientMessage(playerid, COLOR_GREEN,"Bay 1 is open");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 16.3944, 1);
return 1;
}

objectid, is just like this.

CMD:bay1o(playerid, params[])
{
Gate1[playerid] = CreateObject(bla);
ObjectToAttached[playerid] = CreateObject(bla);
AttachObjectToObject(Gate1[playerid], ObjectToAttached[playerid], blablaa);
and so on
}

Not the modelid of your object.

Pottus
09/03/2014, 01:38 PM
There is a few ways to do this, in fact I just got a great idea of adding support to Texture Studio to export groups of objects to a FS that wouldn't require any kind of special editor you would just need to specify the center object all offsets can then be calculated by subtracting that objects X,Y,Z from all objects. The good news is that is such an easy extension for me to add, the bad news I'm not ready to release the next version of Texture Studio yet.

Jhony_Blaze
09/03/2014, 01:53 PM
Okay, now everything is fine with this

CMD:bay1o(playerid, params[])
{
SendClientMessage(playerid, COLOR_GREEN,"Bay 1 is open");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 16.3944, 1);
Gate1[playerid] = CreateObject(1238, -269.2469, 1187.2875, 23.1069, 0.0000, 0.0000, 0.0000);
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
return 1;
}


Gate is opening and the object attaches, not the only thing I need is how do I destroy the object ?

This is what I tried but this won't destroy the object and my gate won't close either.

CMD:bay1c(playerid, params[])
{
Gate1[playerid] = DestroyObject(1238);
SendClientMessage(playerid, COLOR_RED,"Bay 1 is closed");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 20.6691, 1);
return 1;
}

RenovanZ
09/03/2014, 01:57 PM
Okay, now everything is fine with this

CMD:bay1o(playerid, params[])
{
SendClientMessage(playerid, COLOR_GREEN,"Bay 1 is open");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 16.3944, 1);
Gate1[playerid] = CreateObject(1238, -269.2469, 1187.2875, 23.1069, 0.0000, 0.0000, 0.0000);
AttachObjectToObject(1238, 1262, -269.2437, 1187.3073, 23.1069, 0.0000, 0.0000, 0.0000, 1);
return 1;
}


Gate is opening and the object attaches, not the only thing I need is how do I destroy the object ?

This is what I tried but this won't destroy the object and my gate won't close either.

CMD:bay1c(playerid, params[])
{
Gate1[playerid] = DestroyObject(1238);
SendClientMessage(playerid, COLOR_RED,"Bay 1 is closed");
MovePlayerObject(playerid, Gate1[playerid], -254.7196, 1209.9005, 20.6691, 1);
return 1;
}

DestroyObject(Gate1[playerid]);

Jhony_Blaze
09/03/2014, 02:04 PM
DestrouObject(Gate1[playerid]);


Thanks, the object disappears but the gate won't close..any idea ?

Jhony_Blaze
09/03/2014, 04:55 PM
Thanks for the help guys, at the end everything is fine ! Thanks again!