• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] HELP! how to edit a dynamic object attached to vehicle stucked position
#4
An example how to attach a object to vehicle correctly :
Code:
new inEditingMode[MAX_PLAYERS];

CMD:test(playerid, params[])
{
    if (inEditingMode[playerid] || !IsPlayerInAnyVehicle(playerid))
        return 1;
    
    new objectid, Float:VehPos[3];
    GetVehiclePos(GetPlayerVehicleID(playerid), VehPos[0], VehPos[1], VehPos[2]);
    objectid = CreateDynamicObject(11701, VehPos[0], VehPos[1], VehPos[2], 0, 0, 0);
    EditDynamicObject(playerid, objectid);
    inEditingMode[playerid] = 1;
    return 1;
}

public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    if(response == EDIT_RESPONSE_UPDATE)
    {
        return 1;
    }
    if(response == EDIT_RESPONSE_FINAL && inEditingMode[playerid])
    {
        inEditingMode[playerid] = 0;
    
        if (!IsPlayerInAnyVehicle(playerid))
            return 0;
    
        new Float:ofx, Float:ofy, Float:ofz;
        new Float:ofaz, Float:finalx, Float:finaly;
        new Float:px, Float:py, Float:pz, Float:roz;
        GetVehiclePos(GetPlayerVehicleID(playerid), px, py, pz);
        GetVehicleZAngle(GetPlayerVehicleID(playerid), roz);
        ofx = x-px;
        ofy = y-py;
        ofz = z-pz;
        ofaz = rz-roz;
        finalx = ofx*floatcos(roz, degrees)ꇼ*floatsin(roz, degrees);
        finaly = -ofx*floatsin(roz, degrees)ꇼ*floatcos(roz, degrees);
      
        SendClientMessage(playerid, 0x58ACFAFF, "The object attached to your vehicle.");
        AttachDynamicObjectToVehicle(objectid, GetPlayerVehicleID(playerid), finalx, finaly, ofz, rx, ry, ofaz);
    }
    return 1;
}
  Reply


Messages In This Thread
RE: HELP! how to edit a dynamic object attached to vehicle stucked position - by Radical - 2021-04-17, 07:39 PM

Forum Jump: