Skip to content

Add get/setVehicleWheelScale #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
4 commits merged into from
Aug 31, 2020
Merged

Add get/setVehicleWheelScale #1641

4 commits merged into from
Aug 31, 2020

Conversation

AlexTMjugador
Copy link
Member

These functions, related to issue #719, simply expose the wheel scale size attribute of the CVehicle class to clientside Lua scripts.

Considerations

Why?

As explained in the related issue above, custom vehicle models may have a different wheel size than the default model they replace. This wouldn't be an issue if GTA: SA somehow calculated ride height, wheel hitbox and possibly other data from the information contained in the model, but it doesn't. Singleplayer vehicle modifications handle differing wheel sizes by modifying the WheelScale_Front and WheelScale_Rear fields in data/vehicles.ide, which tell GTA the size of the front and rear wheel components so that it can calculate things properly, but script developers can't change those.

On the other hand, most replacement vehicle models with differing wheel sizes that I've seen are not too far off from the sizes of the default models. I believe that the most visible effect of this discrepancy is that vehicle mods look "sunken" into the ground in MTA: SA, while in singleplayer they don't. The setVehicleWheelScale function that this PR adds, while it doesn't affect how GTA: SA calculates the mentioned physical parameters for the model, allows to draw all the wheels of a vehicle taller or shorter, so that these small differences can be compensated and the custom model will look better. It may also add the possibility of enhancing car tunning scripts.

Why not?

Admittedly, these functions expose relatively unflexible functionality to scripts. Ideally, we should let scripts set the WheelScale_Front and WheelScale_Rear values independently, or even improve upon that and let them change the size of each wheel somehow, updating the physical parameters of the model too. However, I've heard that doing that is fairly complex, I don't really have the skills to successfully do a deep dive in GTA: SA internals, and maybe these functions are "good enough".

Isn't this PR already covered by setVehicleComponentScale?

It's not! For example, consider this runcode command:

crun for _, comp in pairs({ "wheel_lf_dummy", "wheel_rf_dummy", "wheel_lb_dummy", "wheel_rb_dummy" }) do localPlayer.vehicle:setComponentScale(comp, 2, 2, 2) end

Intuitively, running that while in a car should make the wheels 2x bigger, but it doesn't.

Why not fix setVehicleComponentScale instead?

That would be a good idea, but I don't know why setVehicleComponentScale doesn't work with wheels. I guess it may have something to do with the CVehicle attribute that this PR exposes, or other GTA stuff.

Added functions

float getVehicleWheelScale ( vehicle theVehicle )

Returns a decimal number that represents the scale multiplier in the vertical and horizontal axes that is applied for all the wheels of the vehicle. By default, 1.

bool setVehicleWheelScale ( vehicle theVehicle, float wheelScale )

Sets the wheel scale multiplier for all the wheels of the vehicle. A value of 1 draws the wheels with the default scale. A value of 0 is allowed, and it makes wheels disappear.

Screenshots

mta-screen_2020-08-28_23-25-35
mta-screen_2020-08-28_23-26-29
mta-screen_2020-08-28_23-30-10

These functions, related to issue #719, expose the wheel scale size
attribute of the CVehicle class to clientside Lua scripts.
@qaisjp
Copy link
Contributor

qaisjp commented Aug 28, 2020

Mad props to you, @AlexTMjugador — the PR is really high quality and very descriptive! Thank you

This keyword guarantees that these methods override the virtual methods in the CVehicle class, as intended.
@AlexTMjugador AlexTMjugador requested a review from qaisjp August 29, 2020 16:36
@Einheit-101
Copy link

I dont think this is a very good idea, maybe someone can find out why setVehicleComponentScale doesnt work with wheels and otherwise the server owner can still remodel his vehicle wheels, this is not a good fix for the missing vehicle wheel collision issue.

@AlexTMjugador
Copy link
Member Author

I dont think this is a very good idea, maybe someone can find out why setVehicleComponentScale doesnt work with wheels and otherwise the server owner can still remodel his vehicle wheels, this is not a good fix for the missing vehicle wheel collision issue.

I agree with your point, @Einheit-101. This PR, alone, feels like a kinda bad fix for that issue. However, in combination with #1644, it may be better. What do you think?

@ghost
Copy link

ghost commented Aug 30, 2020

setVehicleComponentScale was designed to only modify the wheel geometry. The reason why it doesn't affect the collision is that there's no code to modify the collision. We shouldn't touch setVehicleComponentScale because it takes 3 parameters for scale, and that's absurd. We're dealing with wheels here, it should only take 1 parameter, but it's too late to fix the function.

ghost pushed a commit that referenced this pull request Aug 31, 2020
* Add get/setVehicleModelFrontWheelSize and get/setVehicleModelRearWheelSize

These functions, related to issue #719, allow setting the front and
rear wheel size of a vehicle model that GTA: SA reads from the vehicle.ide
file. Moreover, in combination with #1641, all the wheels can then be
visually scaled per vehicle.

* Streamline API of new functions

The new API takes into account suggestions made by StrixG, LosFaul,
qaisjp and others. Thanks!

* Fix returning std::variant with std::unordered_map in new function parser

This fix is needed for the previous commit to compile. According to
@sbx320, the original author of the function parser, it seems correct.

* Replace newly introduced NULL by nullptr

* Remove optional arguments from getVehicleModelWheelSize

* Revert 0765cd3 and fix setVehicleModelFrontWheelSize instead

I changed the wrong function because of a mistake.
@ghost ghost merged commit be82d1c into multitheftauto:master Aug 31, 2020
@StrixG StrixG added the enhancement New feature or request label Aug 31, 2020
@StrixG StrixG added this to the 1.5.8 milestone Aug 31, 2020
@AlexTMjugador AlexTMjugador deleted the feature/wheel-scale branch August 31, 2020 17:45
@qaisjp qaisjp mentioned this pull request Aug 31, 2020
36 tasks
@Dutchman101
Copy link
Member

@AlexTMjugador Please add the below wiki pages:

https://wiki.multitheftauto.com/wiki/getVehicleWheelScale
https://wiki.multitheftauto.com/wiki/setVehicleWheelScale

@AlexTMjugador
Copy link
Member Author

@AlexTMjugador Please add the below wiki pages:

https://wiki.multitheftauto.com/wiki/getVehicleWheelScale
https://wiki.multitheftauto.com/wiki/setVehicleWheelScale

Added, thanks for the reminder!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants