View Full Version : EditObject, AttachObjectToVehicle

12/07/2017, 10:41 PM
Hello, I have a little problem, I can't resolove it, 2days non-stop trying everything, I'm not so good at math with sin/cos, so maybe... someone has solution for this? I searched all over the forum, ******... and no results, I found only script who wasn't finished, it only works perfect with X, Y, Z, RX, RY, RZ cord when vehicle rotation(RX, RY) is 0.0000. When vehicle rotation is not 0.00000, then it starts bugging, I'm 100% sure, that fRotX, fRotY needs to create with floatsin/floatcos functions, but how?

My code example:

CMD:object(playerid, params[])
if(PlayerLogged[playerid] == 0) return 1;
if(!IsPlayerInAnyVehicle(playerid)) return 1;

new Float:x, Float:y, Float:z;
GetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
new objectid = CreateObject(2706, x, y, z, 0.0, 0.0, 0.0);
EditObject(playerid, objectid);

public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
if(response == EDIT_RESPONSE_FINAL)
new Float:vX, Float:vY, Float:vZ, Float:vRX, Float:vRY, Float:vRZ, Float:oX, Float:oY, Float:oZ, Float:oRZ, Float:oAX, Float:oAY;
GetVehiclePos(GetPlayerVehicleID(playerid), vX, vY, vZ);
GetVehicleRotation(GetPlayerVehicleID(playerid),vR X,vRY,vRZ);

oX = fX-px;
oY = fY-py;
oZ = fZ-pz;
oRZ = fRotZ-vRZ;
oAX = oX*floatcos(vRZ, degrees)+oY*floatsin(vRZ, degrees);
oAY = -oX*floatsin(vRZ, degrees)+oY*floatcos(vRZ, degrees);
AttachObjectToVehicle(objectid, GetPlayerVehicleID(playerid), oAX, oAY, oZ, fRotX, fRotY, oRZ);

if(response == EDIT_RESPONSE_CANCEL)
SendClientMessage(playerid, COLOR_LIGHTRED, "Canceled!");

13/07/2017, 12:26 AM
The vehicles needs to be always facing north 0.0 and should be on flat ground. You also need to use a editobject then translate your edit to another object. Look through here.