mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

getVehicleWheelFrictionState not working on bikes

Open thealex-br opened this issue 11 months ago • 1 comments

Describe the bug

getVehicleWheelFrictionState throws ERROR: script/file.lua:line Invalid vehicle type when used in non "Automobile" vehicle types, this function is very useful to detect vehicle behavior and should work in all vehicle types, ~~or return false instead~~

Steps to reproduce

  1. enable debugscript 3

  2. run:

addEventHandler("onClientRender", root, function ()
    local veh = getPedOccupiedVehicle (localPlayer)
    
    if not veh then
        return false
    end
    
    dxDrawRectangle (0, 0, 300, 140, tocolor (0, 0, 0, 150))
    dxDrawText ("FRICTION FRONT LEFT = ".. getVehicleWheelFrictionState (veh, 0), 8, 10, 290, 40, tocolor (255, 255, 255), 1.5)
    dxDrawText ("FRICTION FRONT RIGHT = ".. getVehicleWheelFrictionState (veh, 2), 8, 40, 290, 70, tocolor (255, 255, 255), 1.5)
    dxDrawText ("FRICTION REAR LEFT = ".. getVehicleWheelFrictionState (veh, 1), 8, 70, 290, 100, tocolor (255, 255, 255), 1.5)
    dxDrawText ("FRICTION REAR RIGHT = ".. getVehicleWheelFrictionState (veh, 3), 8, 100, 290, 130, tocolor (255, 255, 255), 1.5)
end)
  1. enter a bike
  2. see errors

Version

Client: v1.6-release-22894 (Windows 10, 64-bit) Server: v1.6-release-22649 (Linux, 64-bit)

Additional context

No response

Relevant log output


Security Policy

  • [x] I have read and understood the Security Policy and this issue is not security related.

thealex-br avatar Jan 13 '25 21:01 thealex-br

this should fix it ? didn't test

int CLuaVehicleDefs::GetVehicleWheelFrictionState(CClientVehicle* pVehicle, unsigned char wheel)
{
    if (wheel < 0 || wheel > 3)
        throw std::invalid_argument("Invalid wheel number");

    const auto type = CClientVehicleManager::GetVehicleType(pVehicle->GetModel());
    if (type != CLIENTVEHICLE_CAR &&
        type != CLIENTVEHICLE_BIKE &&
        type != CLIENTVEHICLE_QUADBIKE &&
        type != CLIENTVEHICLE_MONSTERTRUCK)
        throw std::invalid_argument("Invalid vehicle type");

    return pVehicle->GetWheelFrictionState(wheel);
}

ColombuxMaximus avatar Jun 07 '25 14:06 ColombuxMaximus

this should fix it ? didn't test

It's a bit complicated, but figured out and works.

Xenius97 avatar Nov 12 '25 21:11 Xenius97