Jump to content

[Question] Operating a Packer and getting its loading area matrix through LUA scripting.


xPeacefulDreams

Recommended Posts

Hello everyone,

I've recently created a resource that allows players to attach vehicles to the Packer (vehicle carrier), drive it somewhere, and unload it by pressing a button. This is all working properly except for two things I have questions about:

1. I can't find a way to programmatically raise or lower the loading area of the Packer (see screenshots below). As a player, pressing 2 raises it and pressing 8 lowers it. I'd like to be able to raise/lower it in a script so I can make sure the cars actually align with it. I tried using setVehicleDoorOpenRatio and setVehicleLandingGearDown hoping it was classified as a door or landing gear, but it unfortunately isn't.

2. Is there a way to grab the matrix/position/rotation of the loading area instead of the entire vehicle so I can properly align the cars to it at all times? It would look a lot better than in screenshot 1 where the cars float above the loading area.

 

To better explain the issue:

Screenshot 1: This is how it looks if you spawn a packer and attach vehicles to it. You manually have to raise the loading area in order for it to look proper:

spacer.png

 

Screenshot 2: This is what the packer should look like. Ideally, I'd attach the vehicles to the loading area instead of the entire vehicle, so that they don't float when the loading area is lowered.

spacer.png

Link to comment
  • Moderators
40 minutes ago, xPeacefulDreams said:

1. I can't find a way to programmatically raise or lower the loading area of the Packer (see screenshots below). As a player, pressing 2 raises it and pressing 8 lowers it. I'd like to be able to raise/lower it in a script so I can make sure the cars actually align with it. I tried using setVehicleDoorOpenRatio and setVehicleLandingGearDown hoping it was classified as a door or landing gear, but it unfortunately isn't.

The following function will give you the information about raise/lowering:

https://wiki.multitheftauto.com/wiki/GetVehicleAdjustableProperty

 

If you get both states per vehicle.

- When the vehicle is raised

* Position (attach offset)

* Rotation (attach offset)

 

- When the vehicle is lowered.

* Position (attach offset)

* Rotation (attach offset)

 

You should be able to compute interpolation (position/rotation) by using the adjustable property.

 

 

 

 

 

Edited by IIYAMA
Link to comment

Hello IIYAMA,

Thanks so much for your quick response. Running getVehicleAdjustableProperty reveals 2500 (when raised) and 0 (when lowered) for the Packer.

I also just discover getVehicleComponents. Using that I found out that the loading area is called misc_a. Using getComponentPosition and getComponentRotation, I can create vectors and a matrix, which I can hopefully use to position the vehicles properly. If not, I'll try the interpolating!

Thanks again. I was stuck with this for quite a while.

 

  • Like 1
Link to comment
  • Moderators
43 minutes ago, xPeacefulDreams said:

Hi IIYAMA,

an additional question based on your recommendation.

I noticed the functions used for adjusting the loading area are client side. What would be the best way to sync this with other clients?

 

Good question.

It is not an easy thing to build this without cause performance/network issues. You will have to balance it out what you think is important. The best synchronization and most optimised version requires the most code.

Note: The adjustable property is already synchronized.

 

At the very basic.

Client(only):

- When somebody has entered an vehicle with an adjustable property, you know that it might change.

- Check each frame if the value has changed, then change the offset.

 

Incorrect information:

Now to optimise that (so that not every client is checking it every frame when it is not even used...)

Server:

- When a player enters a vehicle that can use the adjustable property. (You can also add a bindkey of the player that can lower/raise it, but that can be less reliable) Add the vehicle to a table serverside.

- Let the server do the checking, if the adjustable property has changed. (max 1 timer + loop for all vehicles that are checked).

- Inform all clients that the value can be changed. Do this max every 30/60/<check time> seconds. [trigger] = send over vehicle

 

Client:

- Check every frame for all vehicles (from a table) that might change the property. And update the offset.

- Each vehicle has it's own (stop checking) <END time> which is: <NOW time>(getTickCount) + <check time> (same timing as serverside).

{
	vehicle = vehicle,
	endTime = getTickCount() + checkTime
}

 

- Keep checking per vehicle until  <NOW time> is higher than <END time>, then remove the vehicle from the table.

- When the adjustable property is changed clientside. Extend the <END time>. <NOW time> + <check time> = new <END time>.

 

These are more or less the conditions for the ultimate experience: network usage and performance. You might need to add some extra stuff serverside for new players.

 

 

 

 

 

 

 

 

 

 

Edited by IIYAMA
Link to comment

Thanks for the tips!
 

I managed to make it all work through getting the matrices and basing the offsets off of that. It can use some optimization, but it's working.

An example:

spacer.png

I created a quick sync script that adds Packers with attached vehicles to a list on onElementStreamIn and removes them on onElementStreamOut. That list then gets iterated through and it updates the offsets. I will try the way you proposed it as well. I'm curious as to what works best :)
 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...