Skip to content

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

Merged
merged 9 commits into from
Feb 16, 2018

Conversation

ZReC
Copy link
Contributor

@ZReC ZReC commented May 29, 2017

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:

"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 👍

ZReC added 5 commits March 26, 2017 07:49
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 👍
@ZReC ZReC changed the title Feature/is vehicle wheel collided Function: isVehicleWheelCollided May 29, 2017
if ( !argStream.HasErrors () )
lua_pushboolean ( luaVM, pVehicle->IsWheelCollided ( wheel ) );
else
lua_pushboolean ( luaVM, false );

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;

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

@Necktrox Necktrox added the enhancement New feature or request label May 29, 2017
@CrosRoad95
Copy link

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 ) );
Copy link
Member

@Citizen01 Citizen01 May 30, 2017

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.

Copy link
Contributor Author

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" )
Copy link
Contributor

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 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eWheelPosition

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

@qaisjp
Copy link
Contributor

qaisjp commented May 30, 2017

I suggest the function is called doesVehicleWheelCollide or getVehicleWheelCollide.

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.

ZReC added 2 commits May 30, 2017 14:40
eWheels to eWheelPosition
@jushar
Copy link
Contributor

jushar commented Jul 29, 2017

Could you please refactor CVehicleSA::IsWheelCollided to use the appropriate member attributes of CVehicleSAInterface instead of manual offset calculations.

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;
  // ...
}

@ZReC
Copy link
Contributor Author

ZReC commented Jul 29, 2017

Not a bad idea, I'll do my best.

@CrosRoad95
Copy link

what if vehicle dont have 4 wheel? ex 3 ( dodo ) or motorbike ?

@ZReC
Copy link
Contributor Author

ZReC commented Jul 30, 2017

In vehicles of 3 wheels are combined 2 in 1, in motorbikes only the left

@ZReC
Copy link
Contributor Author

ZReC commented Jul 31, 2017

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:

//1440
unsigned char m_ucTrackNodeID;  // Current node on train tracks

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.
What do you think?

Note: the offset 0x590 if it is the vehicle type, type uint8_t and its values correspond to:
0 = car - plane | 5 = boat | 6 = train | 9 = bike

@jushar
Copy link
Contributor

jushar commented Jul 31, 2017

In my opinion would have to be rewritten this sector of the code, to make it more structured and manageable

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
@ZReC
Copy link
Contributor Author

ZReC commented Oct 6, 2017

Updated. Excuse me for the lack of activity, studies are killing me 😆

@Necktrox Necktrox merged commit 192445b into multitheftauto:master Feb 16, 2018
@patrikjuvonen patrikjuvonen added this to the 1.5.6 milestone Aug 7, 2018
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.

8 participants