Skip to content
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

feat(server/gamestate): vehicles natives #3071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spacevx
Copy link
Contributor

@spacevx spacevx commented Jan 15, 2025

Goal of this PR

  • Added IS_VEHICLE_IN_AIR
  • Added IS_VEHICLE_DROWNING
  • Added GET_PED_DEATH_STATE to check if a player is alive, dying or dead.

How is this PR achieving the goal

By exposing fields in datanodes that were already read, (i couldn't find doc about DeathState_Max tho)

This PR applies to the following area(s)

Server, Natives

Successfully tested on

Game builds: 3095, 3258

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Jan 15, 2025
* Added IS_VEHICLE_IN_AIR
* Added IS_VEHICLE_DROWNING
* Added GET_DEATH_STATE to check if a player is alive, dying or dead.
@github-actions github-actions bot added invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Jan 15, 2025
@Heisenberg691
Copy link

DeathState_Max acts as a boundary marker. It defines the range of valid eDeathState values.
And why do we need IS_VEHICLE_IN_AIR when there is IS_ENTITY_IN_AIR?

@spacevx
Copy link
Contributor Author

spacevx commented Jan 16, 2025

DeathState_Max acts as a boundary marker. It defines the range of valid eDeathState values. And why do we need IS_VEHICLE_IN_AIR when there is IS_ENTITY_IN_AIR?

Good to know thanks, and IS_ENTITY_IN_AIR is client side, a server side native is still better.

@AvarianKnight
Copy link
Contributor

IS_ENTITY_IN_AIR

They're saying to reuse the name

@spacevx
Copy link
Contributor Author

spacevx commented Jan 31, 2025

IS_ENTITY_IN_AIR

They're saying to reuse the name

U mean to rename IS_VEHICLE_IN_AIR by IS_ENTITY_IN_AIR?

@Bossman02
Copy link

IS_ENTITY_IN_AIR

They're saying to reuse the name

U mean to rename IS_VEHICLE_IN_AIR by IS_ENTITY_IN_AIR?

If the native can work with all the entities that will be the correct name

@spacevx
Copy link
Contributor Author

spacevx commented Feb 2, 2025

IS_ENTITY_IN_AIR

They're saying to reuse the name

U mean to rename IS_VEHICLE_IN_AIR by IS_ENTITY_IN_AIR?

If the native can work with all the entities that will be the correct name

Need to check, since it's in vehicle data node not sure but will test

DeathState_Alive = 0, // The ped is alive
DeathState_Dying = 1, // The ped is in the process of dying
DeathState_Dead = 2, // The ped is dead
DeathState_Max = 3 // Maximum health? maybe
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It is just an indicator that the enum has ended. Just a utility - e.g. can be used to iterate through all values of the enum (i = 0; i < DeathState_Max; ++i) or check that enum values never take more than x bits of space (assert(DeathState_Max < (1 << 3))). Some other enums in the game have this _Max value as well

Lets either remove or update the comment accordingly.

return vn ? vn->isDrowning : false;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_PED_DEATH_STATE", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: move this to somewhere around line 800 so its near other GET_PED_* natives (e.g. GET_PED_MAX_HEALTH).

@@ -805,6 +813,8 @@ struct SyncTreeBase

virtual CVehicleGameStateNodeData* GetVehicleGameState() = 0;

virtual CVehicleScriptGameStateNodeData* GetVehicleGameScript() = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this PR is missing the following code in SyncTrees_Five.h. It doesn't build without it as it can't instantiate SyncTree class that is now abstract.

	virtual CVehicleScriptGameStateNodeData* GetVehicleGameScript() override
	{
		auto[hasVdn, vehScriptNode] = this->template GetData<CVehicleScriptGameStateDataNode>();

		return (hasVdn) ? &vehScriptNode->data : nullptr;
	}

@Nobelium-cfx
Copy link
Contributor

Also - please resolve merge conflicts with master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Requires changes before it's considered valid and can be (re)triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants