Skip to content

Commit

Permalink
Add Ability to Set Vehicle Wheel Rotation (#3487)
Browse files Browse the repository at this point in the history
  • Loading branch information
gta191977649 authored Jun 30, 2024
1 parent 8403da5 commit aeb113d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
32 changes: 32 additions & 0 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "StdInc.h"
#include "CAutomobileSA.h"
#include "CBikeSA.h"
#include "CCameraSA.h"
#include "CColModelSA.h"
#include "CFxManagerSA.h"
Expand Down Expand Up @@ -494,6 +495,37 @@ void CVehicleSA::SetPlaneRotorSpeed(float fSpeed)
pInterface->m_fPropSpeed = fSpeed;
}

bool CVehicleSA::SetVehicleWheelRotation(float fWheelRot1, float fWheelRot2, float fWheelRot3, float fWheelRot4) noexcept
{
VehicleClass m_eVehicleType = static_cast<VehicleClass>(GetVehicleInterface()->m_vehicleSubClass);
switch (m_eVehicleType)
{
case VehicleClass::AUTOMOBILE:
case VehicleClass::MONSTER_TRUCK:
case VehicleClass::QUAD:
case VehicleClass::TRAILER:
{
auto pInterface = static_cast<CAutomobileSAInterface*>(GetInterface());
pInterface->m_wheelRotation[0] = fWheelRot1;
pInterface->m_wheelRotation[1] = fWheelRot2;
pInterface->m_wheelRotation[2] = fWheelRot3;
pInterface->m_wheelRotation[3] = fWheelRot4;
return true;
}
case VehicleClass::BIKE:
case VehicleClass::BMX:
{
auto pInterface = static_cast<CBikeSAInterface*>(GetInterface());
pInterface->m_afWheelRotationX[0] = fWheelRot1;
pInterface->m_afWheelRotationX[1] = fWheelRot2;
return true;
}
default:
return false;
}
return false;
}

float CVehicleSA::GetPlaneRotorSpeed()
{
auto pInterface = static_cast<CPlaneSAInterface*>(GetInterface());
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CVehicleSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
};
void SetHeliRotorSpeed(float fSpeed) { *reinterpret_cast<float*>(reinterpret_cast<unsigned int>(m_pInterface) + 2124) = fSpeed; };
void SetPlaneRotorSpeed(float fSpeed);
bool SetVehicleWheelRotation(float fWheelRot1, float fWheelRot2, float fWheelRot3, float fWheelRot4) noexcept;
void SetExplodeTime(unsigned long ulTime) { *reinterpret_cast<unsigned long*>(reinterpret_cast<unsigned int>(m_pInterface) + 1240) = ulTime; };
void SetRadioStatus(bool bStatus) { *reinterpret_cast<unsigned char*>(reinterpret_cast<unsigned int>(m_pInterface) + 0x1D3) = bStatus; };

Expand Down
8 changes: 8 additions & 0 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,14 @@ bool CClientVehicle::SetRotorSpeed(float fSpeed)
}
}

bool CClientVehicle::SetWheelsRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept
{
if (!m_pVehicle)
return false;

return m_pVehicle->SetVehicleWheelRotation(fRot1, fRot2, fRot3, fRot4);
}

bool CClientVehicle::IsHeliSearchLightVisible()
{
if (m_pVehicle && m_eVehicleType == CLIENTVEHICLE_HELI)
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class CClientVehicle : public CClientStreamElement

bool GetRotorSpeed(float&);
bool SetRotorSpeed(float);

bool SetWheelsRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept;
void SetHeliRotorSpeed(float fSpeed);
void SetPlaneRotorSpeed(float fSpeed);
bool IsHeliSearchLightVisible();
Expand Down
6 changes: 6 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void CLuaVehicleDefs::LoadFunctions()
{"setVehicleAdjustableProperty", SetVehicleAdjustableProperty},
{"setHelicopterRotorSpeed", SetHelicopterRotorSpeed},
{"setVehicleRotorSpeed", ArgumentParser<SetVehicleRotorSpeed>},
{"setVehicleWheelsRotation", ArgumentParser<SetVehicleWheelsRotation>},
{"setTrainDerailed", SetTrainDerailed},
{"setTrainDerailable", SetTrainDerailable},
{"setTrainDirection", SetTrainDirection},
Expand Down Expand Up @@ -2222,6 +2223,11 @@ bool CLuaVehicleDefs::SetVehicleRotorSpeed(CClientVehicle* pVehicle, float fSpee
return pVehicle->SetRotorSpeed(fSpeed);
}

bool CLuaVehicleDefs::SetVehicleWheelsRotation(CClientVehicle* pVehicle, float fRotation) noexcept
{
return pVehicle->SetWheelsRotation(fRotation, fRotation, fRotation, fRotation);
}

int CLuaVehicleDefs::SetTrainDerailed(lua_State* luaVM)
{
CClientVehicle* pVehicle = NULL;
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(SetVehicleAdjustableProperty);
LUA_DECLARE(SetHelicopterRotorSpeed);
static bool SetVehicleRotorSpeed(CClientVehicle* pVehicle, float fSpeed);
static bool SetVehicleWheelsRotation(CClientVehicle* pVehicle, float fRotation) noexcept;
LUA_DECLARE(SetTrainDerailed);
LUA_DECLARE(SetTrainDerailable);
LUA_DECLARE(SetTrainDirection);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class CVehicle : public virtual CPhysical
virtual void SetAdjustablePropertyValue(unsigned short usAdjustableProperty) = 0;
virtual void SetHeliRotorSpeed(float fSpeed) = 0;
virtual void SetPlaneRotorSpeed(float fSpeed) = 0;
virtual bool SetVehicleWheelRotation(float fRot1, float fRot2, float fRot3, float fRot4) noexcept = 0;
virtual void SetTaxiLightOn(bool bLightState) = 0;
virtual void SetExplodeTime(unsigned long ulTime) = 0;
virtual void SetRadioStatus(bool bStatus) = 0;
Expand Down

0 comments on commit aeb113d

Please sign in to comment.