-
-
Notifications
You must be signed in to change notification settings - Fork 472
Function: isVehicleWheelCollided #146
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
Function: isVehicleWheelCollided #146
Conversation
This function detect if car wheel is on air or in collision. Example: isVehicleWheelCollided ( theVehicle, "rear_left" ) or isVehicleWheelCollided ( theVehicle, 1 ) The wheels are: "front_left" or 0 "rear_left" or 1 "front_right" or 2 "rear_right" or 3 Bikes only have front / rear left wheel . If someone has a better name for the function please comment 👍
if ( !argStream.HasErrors () ) | ||
lua_pushboolean ( luaVM, pVehicle->IsWheelCollided ( wheel ) ); | ||
else | ||
lua_pushboolean ( luaVM, false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() );
is missing here
@@ -913,6 +915,20 @@ int CLuaVehicleDefs::GetVehicleWheelStates ( lua_State* luaVM ) | |||
return 1; | |||
} | |||
|
|||
int CLuaVehicleDefs::IsVehicleWheelCollided ( lua_State* luaVM ) | |||
{ | |||
CClientVehicle* pVehicle = NULL; eWheels wheel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using nullptr
instead of NULL
Next can you add function getVehicleWheelContactMaterial(vehicle,wheel) it can be used for detect if player drive over grass |
By Necktrox
@@ -917,16 +917,17 @@ int CLuaVehicleDefs::GetVehicleWheelStates ( lua_State* luaVM ) | |||
|
|||
int CLuaVehicleDefs::IsVehicleWheelCollided ( lua_State* luaVM ) | |||
{ | |||
CClientVehicle* pVehicle = NULL; eWheels wheel; | |||
CClientVehicle* pVehicle = nullptr; eWheels wheel; | |||
CScriptArgReader argStream ( luaVM ); | |||
argStream.ReadUserData ( pVehicle ); | |||
argStream.ReadEnumStringOrNumber ( wheel ); | |||
|
|||
if ( !argStream.HasErrors () ) | |||
lua_pushboolean ( luaVM, pVehicle->IsWheelCollided ( wheel ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should return 1;
right after that line, with that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I realized later
(I'm stupid..)
ADD_ENUM ( REAR_LEFT_WHEEL, "rear_left" ) | ||
ADD_ENUM ( FRONT_RIGHT_WHEEL, "front_right" ) | ||
ADD_ENUM ( REAR_RIGHT_WHEEL, "rear_right" ) | ||
IMPLEMENT_ENUM_END ( "wheels" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it wheel-position
instead
@@ -492,6 +492,12 @@ IMPLEMENT_ENUM_BEGIN ( eCursorType ) | |||
ADD_ENUM ( CURSORTYPE_SEG_SIZING, "segment_sizing" ) // segment sizing cursor (note: not in use) | |||
IMPLEMENT_ENUM_END ( "cursor-type" ) | |||
|
|||
IMPLEMENT_ENUM_BEGIN ( eWheels ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eWheelPosition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I change the label of the enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
I suggest the function is called Also, perhaps we should instead only support text arguments or number arguments. I lean towards only supporting text arguments. The simpler and easier to understand, the better. This is up for discussion. |
eWheels to eWheelPosition
Could you please refactor E.g.: bool CVehicleSA::IsWheelCollided(std::uint8_t wheelPosition) // eWheelPosition might also be better here
{
CVehicleSAInterface* vehicle = GetInterface();
switch (vehicle->wheelType) // or whatever this is exactly
{
case 0:
if (wheelPosition < 4)
return vehicle->wheelCollisionState[wheelPosition] == 4.0f;
// ...
} |
Not a bad idea, I'll do my best. |
what if vehicle dont have 4 wheel? ex 3 ( dodo ) or motorbike ? |
In vehicles of 3 wheels are combined 2 in 1, in motorbikes only the left |
Jusonex, I have problems implementing the code to CVehicleSAInterface, it turns out that from offset 0x5A0 (1440 decimal) CVehicleSAInterface should give rise to a class more specific of the type of vehicle in particular (CAutomobile, CBike, CHeli, CTrain, CPlane) But instead the class extends with variables of different types of vehicles as of trains:
In my opinion would have to be rewritten this sector of the code, to make it more structured and manageable, meanwhile could graft the code of the collision but would not be the most appropriate. Note: the offset 0x590 if it is the vehicle type, type uint8_t and its values correspond to: |
Yes, that's the way to go - not as a part of this PR though. I'd say update as much as possible (e.g. 0x590) and leave the rest as it is. |
CVehicleSAInterface size it was not according to offset of m_fBurningTime
Updated. Excuse me for the lack of activity, studies are killing me 😆 |
This function detect if car wheel is on air or in collision.
Example:
isVehicleWheelCollided ( theVehicle, "rear_left" )
or
isVehicleWheelCollided ( theVehicle, 1 )
or
theVehicle.isWheelCollided ( "front_right" )
The wheels are:
Bikes only have front / rear left wheel .
If someone has a better name for the function please comment 👍