PDA

View Full Version : AttachObjectToVehicle teleports object to blueberry


reckst4r
23/10/2013, 08:37 PM
Hi. I'm trying to attach an object to a vehicle, but everytime I do that, the object just gets teleported to Blueberry.

AttachObjectToVehicle(LoadBox[vehicleid][ForkliftObject], vehicleid, 0, 0.9, -0.2, 0, 0, 0);

reckst4r
24/10/2013, 11:44 AM
bump

Aliassassin123456
24/10/2013, 11:48 AM
1. the LoadBox[vehicleid][ForkliftObject] must be valid object
2. the position of LoadBox[vehicleid][ForkliftObject] must be: 0.0,0.0,0.0
also see here: http://wiki.sa-mp.com/wiki/AttachObjectToVehicle

Konstantinos
24/10/2013, 11:52 AM
2. the position of LoadBox[vehicleid][ForkliftObject] must be: 0.0,0.0,0.0

Nope. You can change the offset and the rotation of it.

And yes, LoadBox[vehicleid][ForkliftObject] must be valid (create the object and assign the objectid to that).

reckst4r
24/10/2013, 11:56 AM
I've added the missing .0 to the position & rotation, and I've made sure that the forklift object is valid, and yet it doesn't appear.

Aliassassin123456
24/10/2013, 12:08 PM
Nope. You can change the offset and the rotation of it.

AttachObjectToVehicle never reset the position of object, example if you need to attach object to this offset of vehicle: 1.0,1.0,1.0 if we set offset of Object to 1.0,1.0,1.0 we can't use 1.0,1.0,1.0 in AttachObjectToVehicle if we do it Object doesn't go to your intentional position :)

reckst4r
24/10/2013, 12:16 PM
The position of the object that is to be attached to the vehicle isn't 1.0,1.0,1.0

Aliassassin123456
24/10/2013, 12:34 PM
You need to do something like this:

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVING)
{
LoadBox[GetPlayerVehicleID(playerid)][ForkliftObject] = CreateObject(2000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
AttachObjectToVehicle(LoadBox[GetPlayerVehicleID(playerid)][ForkliftObject], GetPlayerVehicleID(playerid), 0, 0.9, -0.2, 0, 0, 0);
}
return 1;
}

reckst4r
24/10/2013, 12:41 PM
This is the code where it creates the object & attaches it to the vehicle

LoadBox[vehicleid][ForkliftObject] = CreateObject(964,-1077.59997559,4274.39990234,3.40000010,0.00000000, 0.00000000,0.00000000);
AttachObjectToVehicle(LoadBox[vehicleid][ForkliftObject], vehicleid, 0.0, 0.9, -0.2, 0.0, 0.0, 0.0);


It's under a command, so it doesn't really fit under OnPlayerStateChange in this case :P

Aliassassin123456
24/10/2013, 12:45 PM
i told you use 0.0,0.0,0.0 for offset of CreateObject !
Try this:

LoadBox[vehicleid][ForkliftObject] = CreateObject(964,0.0, 0.0, 0.0, 0.00000000, 0.00000000, 0.00000000);
AttachObjectToVehicle(LoadBox[vehicleid][ForkliftObject], vehicleid, 0.0, 0.9, -0.2, 0.0, 0.0, 0.0);

Konstantinos
24/10/2013, 12:51 PM
You even posted a link of the Wiki which shows that you can use offset with any value, it's not obligatory to be 0.0

AttachObjectToVehicle(objectid, vehicleid, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);


This tutorial (http://forum.sa-mp.com/showthread.php?t=267742) even shows that you can use any offset and rotation values, that's not the problem.

reckst4r
24/10/2013, 12:52 PM
Oh, well.. In that case, I misunderstood you before. It's still not working, unfortunently.

Threshold
24/10/2013, 01:07 PM
None of you have considered the fact that 'vehicleid' may be the wrong or invalid value in this case. Show us where you get this 'vehicleid' from.

reckst4r
24/10/2013, 01:55 PM
new vehicleid = GetPlayerVehicleID(playerid);

It's right below

CMD:loadbox(playerid, params[])
{

Threshold
24/10/2013, 03:40 PM
Hmm... show us the whole loadbox command.

reckst4r
24/10/2013, 04:34 PM
CMD:loadbox(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid == FactoryVehicle[2] || vehicleid == FactoryVehicle[3] ||vehicleid == FactoryVehicle[4] || GetVehicleModel(vehicleid) == 530)
{
new string[128];
if(!LoadBox[vehicleid][ForkliftLoaded])
{
new BoxTaken;
if(IsPlayerInRangeOfPoint(playerid, 5, -1107.9978,4244.9966,3.40000010))
{
if(CountBoxes() < MAX_BOXES)
{
LoadBox[vehicleid][ForkliftLoaded] = 1;
LoadBox[vehicleid][ForkliftObject] = CreateObject(964,0.0, 0.0, 0.0, 0.00000000, 0.00000000, 0.00000000);
AttachObjectToVehicle(LoadBox[vehicleid][ForkliftObject], vehicleid, 0.0, 0.9, -0.2, 0.0, 0.0, 0.0);
SendClientMessage(playerid, COLOR_GREY, "You've successfully loaded the box!");
DespawnBox();
SetTimer("SpawnBox", 30000, 0);
for(new i = 0; i < sizeof(BoxInfo); i++)
{
if(!BoxInfo[i][bxActive])
{
BoxInfo[i][InVehicle] = vehicleid;
BoxInfo[i][GunsInBox] = 50;
BoxInfo[i][bxActive] = 1;
LoadBox[vehicleid][vBoxID][0] = i;
break;
}
}
BoxFound = 1;
}
else return SendClientMessage(playerid, COLOR_GREY, "The factory is at full capacity. Wait for the current boxes to be delivered.");
}
else
{
new Float:bX, Float: bY, Float: bZ;
for(new i = 0; i < sizeof(BoxInfo); i++)
{
if(BoxInfo[i][bxActive])
{
GetDynamicObjectPos(BoxInfo[i][bxObject], bX, bY, bZ);
if(IsPlayerInRangeOfPoint(playerid, 5.0, bX, bY, bZ))
{
DestroyObject(BoxInfo[i][bxObject]);
BoxInfo[i][InVehicle] = vehicleid;
LoadBox[vehicleid][ForkliftLoaded] = 1;
LoadBox[vehicleid][ForkliftObject] = CreateObject(964,-1077.59997559,4274.39990234,3.40000010,0.00000000, 0.00000000,0.00000000);
AttachObjectToVehicle(LoadBox[vehicleid][ForkliftObject], vehicleid, 0, 0.9, 0, 0, 0, 0);
DestroyDynamic3DTextLabel(BoxInfo[i][bxLabel]);
BoxFound = 1;
break;
}
}
}
}
if(!BoxFound) return SendClientMessage(playerid, COLOR_GREY, "You are not near any boxes!");

}
else
{
new Float: vX, Float: vY, Float: vZ;
GetVehiclePos(vehicleid, vX, vY, vZ);
GetXYInFrontOfPlayer(playerid, vX, vY, 2);
DestroyObject(LoadBox[vehicleid][ForkliftObject]);
LoadBox[vehicleid][ForkliftLoaded] = 0;
LoadBox[vehicleid][vBoxID][0] = 0;
for(new i = 0; i < sizeof(BoxInfo); i++)
{
if(BoxInfo[i][InVehicle] == vehicleid)
{
BoxInfo[i][InVehicle] = 0;
BoxInfo[i][bxObject] = AddObject(964,vX,vY,vZ-0.8,0.00000000,0.00000000,0.00000000);
BoxInfo[i][bxX] = bX;
BoxInfo[i][bxY] = bY;
BoxInfo[i][bxZ] = bZ-0.8;
format(string, sizeof(string), "Box S/N: #%d\n High Tech Materials: %d/50", i, BoxInfo[i][GunsInBox]);
BoxInfo[i][bxLabel] = CreateDynamic3DTextLabel(string, COLOR_ORANGE, BoxInfo[i][bxX],BoxInfo[i][bxY],BoxInfo[i][bxZ]+1, 20.0, _, _, 1, 0, 0, _, 20.0);
break;
}
}
SendClientMessage(playerid, COLOR_GREY, "The box has been dropped on the ground!");
return 1;

}
}
else
{
return SendClientMessage(playerid, COLOR_GREY, "You are not in a forklift!");
}
return 1;
}

reckst4r
27/10/2013, 02:35 PM
Bump

reckst4r
28/10/2013, 11:27 AM
Bump