Edit Vehicle Object problem -
GunZ75 - 22.08.2017
Hello Guys,
So i am having a problem with a code that creates an object, u edit it and in the end it attaches the object to the current used vehicle. However it aint attaching in the correct position. Here's the code:
Код:
if(strcmp(cmd, "/avehicleobject", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(IsPlayerInAnyVehicle(playerid))
{
tmp = strtok(cmdtext,idx);
if(PlayerInfo[playerid][pAdmin] >= 1336)
{
new slotid = strval(tmp);
tmp = strtok(cmdtext,idx);
if(slotid > 0 && slotid <= 1000)
{
new Float:pos[3];
GetVehiclePos(GetPlayerVehicleID(playerid), pos[0],pos[1], pos[2]);
new objectid = strval(tmp);
vehicleObjectEdit[slotid][GetPlayerVehicleID(playerid)] = CreateDynamicObject(objectid, pos[0],pos[1], pos[2],0,0,0);
EditDynamicObject(playerid, vehicleObjectEdit[slotid][GetPlayerVehicleID(playerid)]);
objectSlot[playerid] = slotid;
SetVehicleZAngle(GetPlayerVehicleID(playerid), 0.0);
}
}
}
}
return 1;
}
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
if(IsPlayerInAnyVehicle(playerid))
{
switch (response)
{
case EDIT_RESPONSE_CANCEL:
{
DestroyDynamicObject(objectid);
}
case EDIT_RESPONSE_FINAL:
{
SetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
SetVehicleZAngle(GetPlayerVehicleID(playerid), rz);
new Float:pos[4];
GetVehiclePos(GetPlayerVehicleID(playerid), pos[0],pos[1],pos[2]);
GetVehicleZAngle(GetPlayerVehicleID(playerid),pos[3]);
new Float:new_pos[4];
new_pos[0] = x - pos[0];
new_pos[1] = y - pos[1];
new_pos[2] = z - pos[2];
new_pos[3] = rz - pos[3];
new Float:final_pos[2];
final_pos[0] = (new_pos[0] * floatcos(new_pos[3],degrees)) + (new_pos[1] * floatsin(new_pos[3],degrees));
final_pos[1] = (new_pos[1] * floatcos(new_pos[3],degrees)) - (new_pos[0] * floatsin(new_pos[3],degrees));
AttachDynamicObjectToVehicle(objectid,GetPlayerVehicleID(playerid),final_pos[0],final_pos[1],new_pos[2],rx,ry,new_pos[3]);
new File: File1 = fopen("CRP_Scriptfiles/Cars/carobjects.cfg", io_append);
new objectString[500];
format(objectString, sizeof(objectString), "%d,%d,%f,%f,%f,%f,%f,%f",objectSlot[playerid], GetObjectModel(objectid),final_pos[0],final_pos[1],new_pos[2],rx,ry,new_pos[3]);
fwrite(File1, objectString);
fclose(File1);
objectSlot[playerid] = 0;
}
}
}
}
Re: Edit Vehicle Object problem -
GunZ75 - 22.08.2017
bump
Re: Edit Vehicle Object problem -
Pottus - 23.08.2017
You are going about it all wrong.
1.) Vehicle should always be facing north
2.) Use a dummy object to edit with (a pivot/point)
3.) Translate dummy object position/rotation to vehicle offsets
4.) Keep updating the position/rotation of the attached object to see result in real time
I can see what you are trying to do but your whole method is lousy.
Re: Edit Vehicle Object problem -
GunZ75 - 23.08.2017
Okay hum so i just keep the vehicle steady, facing a 90 degree z rotation and work with the GetVehiclePosition pivot point?
Re: Edit Vehicle Object problem -
GunZ75 - 23.08.2017
Still aint working. Could you specify more please? maybe in code?
Re: Edit Vehicle Object problem -
GunZ75 - 23.08.2017
bump
Re: Edit Vehicle Object problem -
GunZ75 - 24.08.2017
Please anyone??
Re: Edit Vehicle Object problem -
GunZ75 - 24.08.2017
bump
Re: Edit Vehicle Object problem -
GunZ75 - 25.08.2017
Another bump