Is it possible to convert... EditObject and AttachObjectToVehicle
#1

So that when I use EditObject for an object which is attached to a vehicle, it will de-attach and let me use the editor, when I click save it will then convert the X,Y,Z to the Vehicle Offsets and re-attach?

So basically,

I need an equasion / algorithm to convert real world GTA X,Y,Z to Vehicle Offsets and vice versa.

Regards
Reply
#2

Anyone?
Reply
#3

so you want to edit Objects with EditObject and after saving the object you want to attach it to a car?
if that's the case,
i once worked on a script which should do just that.

it's not finished cuz i paused scripting some months ago,
but i remember the coordinate conversion worked fine.
I tested it with spoilers as far as i can remember.

Here's the unfinished script free 2 use 4 anyone
PHP код:
/*
================================================================================
             __________________________________________________
            |  ______________________________________________  |
            | |   ___________  *     ______________          | |
            | |* |  _________|      |  ____________|*        | |
            | |     | |                | |                      | |
            | |     | |                | | *             *      | |
            | |     | |          *     | |                      | |
            | |     | |   *            | |     *                | |
            | |* | |                | |                  *   | |
            | |     | |   *            | |   *                  | |
            | |     | |_________  *    | |                      | |
            | | *|  _________|      | |*        *            | |
            | |     | |                | |*            *        | |
            | |  | |           *    | |         *            | |
            | |     | |    *           | |                      | |
            | |     | |  *             | |     *           *    | |
            | | *| |_________       | |____________*         | |
            | |     |___________|  *   |______________|         | |
            | |______________________________________________| |
            |__________________________________________________|
================================================================================
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Last line worked on: 187
----------INFO------------
This script's main goal is it to
successfully edit an Object with the EditObject feature
and attach it to a certain vehicle.
Development start: 07.09.2013
Development end: --.--.---
Developer: East_Crips aka Earl_Brown aka TheDarknessBoSS aka CutX
*/
#include <a_samp>
#include <YSI\y_commands>
#include <easydialog>
#define gray 0x8C8C8CFF
#define white 0xFFFFFFFF
#define red 0xFF0000FF
new str8hgn86[90];
#define SFM(%0,%1,%2,%3) format(str8hgn86, sizeof(str8hgn86),%2,%3) && SendClientMessage(%0, %1, str8hgn86)
enum ob_option
{
    
attached,
    
ob_name[11],
    
Float:X,
    
Float:Y,
    
Float:Z,
    
Float:rX,
    
Float:rY,
    
Float:rZ,
}
new 
CO[MAX_PLAYERS][5][ob_option],
    
MyObjects[MAX_PLAYERS][5],
    
MyMax[MAX_PLAYERS],
    
CurrentObject[MAX_PLAYERS][2],
    
HostCar[MAX_PLAYERS];
main()
{
    print(
"EC-Car Toys has been loaded successfully!");
}
//---------Commands - Main--------
YCMD:cartoys(playeridparams[], help)
{
    if(
help) return SendClientMessage(playerid,gray,"/cartoys Is used to display the Car-Toys Main Menu.");
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You have to be in your car!");
    if(!
IsValidVehicle(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,red,"This isn't a valid Vehicle!");
    
ShowDialog(playeridShow:mainDIALOG_STYLE_LIST"Menu","Buy new Objects\nEdit an Object\nDelete an Object","Okey","Cancel");
    return 
1;
}
//--Dialogprocessing - Section----
Dialog:main(playeridresponselistiteminputtext[])
{
    if(!
response) return 1;
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You have to be in your car!");
    switch(
listitem)
    {
        case 
0ShowDialog(playeridShow:buynewDIALOG_STYLE_LIST"Buy new Objects","Spoiler 1\t$5,000\nSpoiler 2\t$5,000\nSpoiler 3\t$5,000\nSpoiler 4\t$5,000\nSpoiler 5\t$5,000\nSpoiler 6\t$5,000\n\
                Spoiler 7\t$5,000\nSpoiler 8\t$5,000\nSpoiler 9\t$5,000\nSpoiler 10\t$5,000\nSpoiler 11\t$5,000\nSpoiler 12\t$5,000\nSpoiler 13\t$5,000\nSpoiler 14\t$5,000\nSpoiler 15\t$5,000\nSpoiler 16\t$5,000\n\
                Spoiler 17\t$5,000\nSpoiler 18\t$5,000\nSpoiler 19\t$5,000"
,"Buy","Back");
        case 
1:
        {
            new 
tempS[23],s[85];
            for(new 
ob,ov,a=5;ob<a;ob++,ov+=2)
            {
            
format(tempS,sizeof tempS,"%s | Slot %d\n",CO[playerid][ob][ob_name],ov);
            
strcat(s,tempS);
            }
            
ShowDialog(playeridShow:editDIALOG_STYLE_LIST"Edit an Object",s,"Edit","Back");
        }
        case 
2: print("2");
    }
    return 
1;
}
Dialog:buynew(playeridresponselistiteminputtext[])
{
    if(!
response) return ShowDialog(playeridShow:mainDIALOG_STYLE_LIST"Menu","Buy new Objects\nEdit an Object\nDelete an Object","Okey","Cancel");
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You have to be in your car!");
    if(
MyMax[playerid] == 5) return SendClientMessage(playerid,red,"You can only have 10 Objects!");
    
MyMax[playerid]++;
    new 
s[11], listitem;
    
n++;
    
format(s,sizeof s,"Spoiler %d",n);
    
CO[playerid][MyMax[playerid]][ob_name] = s;
    
CO[playerid][MyMax[playerid]][attached] = 0;
    switch(
listitem)
    {
        case 
0MyObjects[playerid][MyMax[playerid]] = 1164;
        case 
1MyObjects[playerid][MyMax[playerid]] = 1163;
        case 
2MyObjects[playerid][MyMax[playerid]] = 1162;
        case 
3MyObjects[playerid][MyMax[playerid]] = 1147;
        case 
4MyObjects[playerid][MyMax[playerid]] = 1146;
        case 
5MyObjects[playerid][MyMax[playerid]] = 1139;
        case 
6MyObjects[playerid][MyMax[playerid]] = 1138;
        case 
7MyObjects[playerid][MyMax[playerid]] = 1060;
        case 
8MyObjects[playerid][MyMax[playerid]] = 1058;
        case 
9MyObjects[playerid][MyMax[playerid]] = 1050;
        case 
10MyObjects[playerid][MyMax[playerid]] = 1049;
        case 
11MyObjects[playerid][MyMax[playerid]] = 1023;
        case 
12MyObjects[playerid][MyMax[playerid]] = 1016;
        case 
13MyObjects[playerid][MyMax[playerid]] = 1015;
        case 
14MyObjects[playerid][MyMax[playerid]] = 1014;
        case 
15MyObjects[playerid][MyMax[playerid]] = 1003;
        case 
16MyObjects[playerid][MyMax[playerid]] = 1002;
        case 
17MyObjects[playerid][MyMax[playerid]] = 1001;
        case 
18MyObjects[playerid][MyMax[playerid]] = 1000;
    }
    
SFM(playerid,white,"Object: %s has been added to Slot %d",CO[playerid][MyMax[playerid]][ob_name],MyMax[playerid]);
    
GivePlayerMoney(playerid,-5000);
    return 
1;
}
Dialog:edit(playeridresponselistiteminputtext[])
{
    if(!
response) return ShowDialog(playeridShow:mainDIALOG_STYLE_LIST"Menu","Buy new Objects\nEdit an Object\nDelete an Object","Okey","Cancel");
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You have to be in your car!");
    if(!
CO[playerid][listitem][attached])
    {
    new 
Float:p[3];
    
GetVehiclePos(GetPlayerVehicleID(playerid),p[0],p[1],p[2]);
    
CurrentObject[playerid][0] = CreateObject(MyObjects[playerid][listitem],p[0],p[1],p[2]+1.5,0.0,0.0,0.0);
    
CO[playerid][listitem][attached] = 1;
    }
    
CurrentObject[playerid][1] = listitem;//Slot
    
HostCar[playerid] = GetPlayerVehicleID(playerid);
    
SendClientMessage(playerid,white,"You can now Edit the Object. You can also get out of the car and");
    
SendClientMessage(playerid,white,"hold the sprint key to get a better view.");
    
EditObject(playerid,CurrentObject[playerid][0]);
    return 
1;
}
//--------------------------------
public OnPlayerEditObject(playeridplayerobjectobjectidresponseFloat:fXFloat:fYFloat:fZFloat:fRotXFloat:fRotYFloat:fRotZ)
{
    new 
Float:oXFloat:oYFloat:oZ,Float:orXFloat:orYFloat:orZ;
    
GetObjectPos(objectidoXoYoZ);
    
GetObjectRot(objectidorXorYorZ);
    new 
Float:vXFloat:vYFloat:vZ;
    
GetVehiclePos(HostCar[playerid],vX,vY,vZ);
    switch(
response)
    {
        case 
0:
        {
            
oX floatsub(oX,vX);
            
oY floatsub(oY,vY);
            
oZ floatsub(oZ,vZ);
            
AttachObjectToVehicle(objectid,HostCar[playerid],oXoYoZorXorYorZ);
            
SendClientMessage(playerid,red,"You canceled the Editing-Mode without saving!");
        }
        case 
1:
        {
            
CO[playerid][CurrentObject[playerid][1]][X] = floatsub(fX,vX);
            
CO[playerid][CurrentObject[playerid][1]][Y] = floatsub(fY,vY);
            
CO[playerid][CurrentObject[playerid][1]][Z] = floatsub(fZ,vZ);
            
CO[playerid][CurrentObject[playerid][1]][rX] = fRotX;
            
CO[playerid][CurrentObject[playerid][1]][rY] = fRotY;
            
CO[playerid][CurrentObject[playerid][1]][rZ] = fRotZ;
            
AttachObjectToVehicle(objectid,HostCar[playerid],CO[playerid][CurrentObject[playerid][1]][X],CO[playerid][CurrentObject[playerid][1]][Y],CO[playerid][CurrentObject[playerid][1]][Z],CO[playerid][CurrentObject[playerid][1]][rX],CO[playerid][CurrentObject[playerid][1]][rY],CO[playerid][CurrentObject[playerid][1]][rZ]);
            
SendClientMessage(playerid,white,"Successfully edited the Object.");
        }
        case 
2: {}//Editing the object
    
}
    return 
1;
}
stock IsValidVehicle(vehicleid)
{
    switch(
GetVehicleModel(vehicleid))
    {
        case 
417425447460469476487488497511512513,
             
519520548553563577592593509481510462,
             
448581522461521523463586468471472473,
             
493595484430453452446454: return 0;
    }
    return 
1;

Reply
#4

That won't really work very well, besides your better off using commands so you don't lose precision when setting rotations.

Now I think it is possible to do but you would have to have the cars rotation exactly at 0.0 not very practical just use commands.
Reply
#5

It can be done, and I can make it for you, but the only problem is that it might take some time to do it.. I'll see what I can come up with in the next few days, and hopefully make an appealing reply to this thread.
Reply
#6

Again, it's a bad idea your cars objects will have very poor positioning because editing objects in this way has absolutely no precision so if you have say two of the same objects offset on the x-axis they will never align correctly. I really don't see doing this offering much reward for the effort involved. The fact that no one has really done it yet should be a sign enough given the multiple unsuccessful attempts that it is a bad idea just use commands.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)