SA-MP Forums Archive
Edit attached vehicle object. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Edit attached vehicle object. (/showthread.php?tid=424700)



Edit attached vehicle object. - newbienoob - 23.03.2013

Hey. I'm trying to edit an attached vehicle object. But I couldn't.

pawn Код:
CMD:vo(playerid,params[])
{
    new Float:x,Float:y,Float:z, model;
    GetVehiclePos(GetPlayerVehicleID(playerid),x,y,z);
    if(sscanf(params,"i",model)) return SendClientMessage(playerid,-1,"no");
    obj = CreateObject(model,x,y,z,0,0,0,100);
    AttachObjectToVehicle(obj,GetPlayerVehicleID(playerid),x,y,z,0,0,0);
    EditObject(playerid,obj);
    return 1;
}
I can see the GUI and mouse cursor, but I can't move or rotate it. Does anyone know how to edit an attached vehicle object?

Oh and, can anyone solve this problem?
https://sampforum.blast.hk/showthread.php?tid=423580&page=2


Re: Edit attached vehicle object. - Stylock - 23.03.2013

Just use SetObjectPos instead of AttachObjectToVehicle, and after you're done editing, simply subtract the vehicle's position from the object's position and you get the offsets.


Re: Edit attached vehicle object. - newbienoob - 23.03.2013

Quote:
Originally Posted by YJIET
Посмотреть сообщение
Just use SetObjectPos instead of AttachObjectToVehicle,
Then how am I supposed to attach the object to vehicle if I don't use AttachObjectToVehicle?


Re: Edit attached vehicle object. - Stylock - 23.03.2013

Quote:
Originally Posted by newbienoob
Посмотреть сообщение
Then how am I supposed to attach the object to vehicle if I don't use AttachObjectToVehicle?
By using the offsets?

EDIT: It looks like you're misusing the function anyway.


Re: Edit attached vehicle object. - newbienoob - 23.03.2013

What? Sorry, I don't understand. Can you show me an example?


Re: Edit attached vehicle object. - Scenario - 23.03.2013

Basically, he's saying that you can create the object, edit the object and put this code underneath OnPlayerEditObject. In the code below, it basically takes the XYZ position of the object and subtracts the vehicle's position FROM the object's coordinates.

I didn't even know that was possible until I saw this... the only issue with the code below is that it doesn't set the proper rotation when attaching the object to the vehicle. I'm not sure how I'd accomplish that.

pawn Код:
new
            Float:fPos[3]
        ;
       
        GetVehiclePos(GetPlayerVehicleID(playerid), fPos[0], fPos[1], fPos[2]);    
        printf("\n\nOBJECT OFFSETS: %f, %f, %f, %f, %f, %f\n\n", x-fPos[0], y-fPos[1], z-fPos[2], rx, ry, rz);
       
        AttachDynamicObjectToVehicle(objectid, GetPlayerVehicleID(playerid), x-fPos[0], y-fPos[1], z-fPos[2], rx, ry, rz);



Re: Edit attached vehicle object. - Stylock - 23.03.2013

I think the vehicle needs to be facing north the get the correct rotation offsets.


Re: Edit attached vehicle object. - Scenario - 23.03.2013

If you're facing East, West, SE, or SW, this code seems to work just fine. It's only when you're facing North/South that it won't work properly. I'm working on a fix, though!

pawn Код:
if(response == EDIT_RESPONSE_FINAL)
    {
        new
            Float:fPos[6],
            Float:temp
        ;
       
        GetVehiclePos(GetPlayerVehicleID(playerid), fPos[0], fPos[1], fPos[2]);
        GetVehicleRotationQuat(GetPlayerVehicleID(playerid), temp, fPos[3], fPos[4], fPos[5]);
        printf("\n\nOBJECT OFFSETS: %f, %f, %f, %f, %f, %f\n\n", x-fPos[0], y-fPos[1], z-fPos[2], fPos[3], fPos[4], fPos[5]);
       
        AttachDynamicObjectToVehicle(objectid, GetPlayerVehicleID(playerid), x-fPos[0], y-fPos[1], z-fPos[2], fPos[3], fPos[4], fPos[5]);      
        SendClientMessage(playerid, COLOR_GREEN, "Results printed to server log.");
    }



Re: Edit attached vehicle object. - newbienoob - 23.03.2013

Hmm.. so I need to;
- Create object
- Edit object
#OnPlayerEdit(Dynamic)Object (EDIT_RESPONSE_FINAL)
- Attach it to vehicle.

?


Re: Edit attached vehicle object. - Scenario - 23.03.2013

Yes.