Attaching other vehicles to the packer truck
#1

Hi,

Is it possible to attach other vehicles (cars usually) to the packer truck?
I've tested this before by driving vehicles onto the packer, but as soon as I start driving the packer, they fall off.
Reply
#2

pawn Код:
forward AttachVehicleToVehicle(vehid, attachid);
public AttachVehicleToVehicle(vehid, attachid)
{
        new Float:X,Float:Y,Float:Z,Float:A; //1344
        GetVehiclePos(vehid, X, Y, Z);
        GetVehicleZAngle(vehid, A);
        SetVehiclePos(attachid, X, Y +2.3, Z+1);
        SetVehicleZAngle(attachid, A);
        return 1;
}
Try this, there might be some errors, but i'm sure you can fix them yourself.
Reply
#3

No it isn't possible.

What I have done in the past is use a car object and attach that using AttachObjectToVehicle.
Reply
#4

And how can you convert a vehicle to an object?
Or are there built-in objects that resemble cars?

Or can you treat any vehicle as if it was an object?
Reply
#5

I tried this:
pawn Код:
new Object = CreateDynamicObject(562, x, y, z, 0.0, 0.0, rot);

    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, Object, E_STREAMER_DRAW_DISTANCE, 300.0);
to spawn an Elegy as object.

Somehow it works but I cannot see the Elegy object.
But it's there because I can bump into it and jump on top of it.
I just can't see it.

The same code is used to spawn a speedcamera object and that works perfectly.
Also, the draw distance can't be the problem, as the second line sets the drawdistance of the object to 300 meters (it works for my speedcams).

How to spawn a vehicle as an object, so it can be attached to the packer truck?
Reply
#6

There is a Filterscript created by Gamer_Z, maybe you could edit the script you could probably get what you wanted to do. | Link: Attach Vehicle To Vehicle V2
Reply
#7

I've looked at it already, it seems nice but the attached car jumps alot up/down.

Perhaps it's possible to do something like this under OnPlayerUpdate.
I'll try something soon.
Reply
#8

Tried it and it works, kinda.
But it's still un-realistic.
The Elegy floats above the packer and your camera is blocked by it when driving the Packer.
Lowering the Elegy until it touches the packer causes bad driving behaviour of the Packer and such abnormalities.
The Elegy was put in place each time OnPlayerUpdate was executed (30 times per second).
This pushed against the Packer and you couldn't drive the Packer properly anymore.

But the Elegy nicely followed the Packer, except when the packer was wiggling left and right because of non-flat terrain.
Also, driving on a ramp didn't cause the Elegy to tilt.

This was my test-code:
pawn Код:
new Elegy, Packer;

// This callback is called very frequently per second (about 30 times per second)
public OnPlayerUpdate(playerid)
{
    new Float:x, Float:y, Float:z, Float:rot;

    // Check if the player is inside the packer
    if (GetPlayerVehicleID(playerid) == Packer)
    {
        GetVehiclePos(Packer, x, y, z);
        GetVehicleZAngle(Packer, rot);

        SetVehiclePos(Elegy, x, y, z + 2.5);
        SetVehicleZAngle(Elegy, rot);
    }

    return 1;
}

// This callback gets called when the server initializes the filterscript
public OnFilterScriptInit()
{
    Elegy = CreateVehicle(562, 0.0, 0.0, 5.0, 0.0, 0, 0, 300);
    Packer = CreateVehicle(443, 10.0, 0.0, 5.0, 0.0, 0, 0, 300);

    return 1;
}
Maybe some of this could be used for the Leviatan helicopter to transport vehicles that way.
Perhaps using a fast timer instead of OnPlayerUpdate, as this could lag the server when there are 100 players online.

It doesn't have to be a real vehicle that you can drive.
It would be used as a new job-type for truckers, who could transport vehicles from one location to another.
The spawned vehicle doesn't really need to drive at all. It's only use would be aestethical, to make it seem the Packer is transporting a real vehicle.

But I still can't spawn a vehicle as an object, which would be the best.
Then it would really move together with the Packer.
Reply
#9

Fastest solution I came up with (probably while you were writing your last post, I didn't see it). Basically, I just got offset from packer and the location where the cars should be.

pawn Код:
public OnPlayerCommandText(playerid, const cmdtext[])
{

    if(strcmp(cmdtext, "/packer", true) == 0)
    {
        new packer, admirals[2];

        // spawn packer near player
        new Float:px, Float:py, Float:pz;
        GetPlayerPos(playerid, px, py, pz);

        #define packerx (px + 5.0)
        #define packery (py + 5.0)
        #define packerz (pz)

        packer = CreateVehicle(443, packerx, packery, packerz, 180.0, 0, 0, 0);

        // spawn admirals on packer
        admiral[0] = CreateVehicle(445, packerx + 0.060059, packery - 0.259766, packerz + 2.167205, 180.0f, 0, 0, 0);
        admiral[1] = CreateVehicle(445, packerx - 0.174805, packery + 7.21752, packerz + 0.114706, 180.0f, 0, 0, 0);

        #undef packerx, packery, packerz
        return 1;
    }

    return 1;
}
The result is: http://imgur.com/VsOZiSK
It's actually driveable!

Offsets are (as you can see in the script):
pawn Код:
// vehicle 1
x = + 0.060059
y = - 0.259766
z = + 2.167205

// vehicle 2
x = - 0.174805
y = + 7.21752
z = + 0.114706
You could also take a look at https://sampforum.blast.hk/showthread.php?tid=198885 and maybe use some of the code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)