22.08.2017, 21:40
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:
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; } } } }