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(gamestate/server): add GET_ENTITY_TYPE_RAW native #2945

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

Conversation

tens0rfl0w
Copy link
Contributor

@tens0rfl0w tens0rfl0w commented Nov 18, 2024

Goal of this PR

While working on #2940 it was mentioned that there is currently no way to get the specific entity type on the server-side.
This implements a new custom (server) native to get the specific NetObjEntity type of a networked entity.

How is this PR achieving the goal

Reading entity->type and returning the specific type as an int on calling GET_ENTITY_TYPE_RAW.

This PR applies to the following area(s)

FiveM, RedM, Natives, Server

Successfully tested on

Game builds: 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 RedM Issues/PRs related to RedM label Nov 18, 2024
@AvarianKnight
Copy link
Contributor

GET_ENTITY_TYPE_RAW might be a better name here, it matches other natives

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Nov 19, 2024
Implements a new custom (server) native to get the specific NetObjEntity type of a networked entity.
@tens0rfl0w tens0rfl0w force-pushed the feat/gamestate_server/GetEntityTypeSpecificNative branch from bfec75d to c2ad330 Compare November 19, 2024 00:39
@tens0rfl0w
Copy link
Contributor Author

I agree that _RAW fits better here, I also changed the return value for an invalid entity to -1 to match the behavior of GET_VEHICLE_TYPE_RAW.

Thanks for the feedback!

@tens0rfl0w tens0rfl0w changed the title feat(gamestate/server): add GET_ENTITY_TYPE_SPECIFIC native feat(gamestate/server): add GET_ENTITY_TYPE_RAW native Nov 19, 2024
Copy link
Contributor

@iridium-cfx iridium-cfx left a comment

Choose a reason for hiding this comment

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

I'm not a huge fan of returning the raw integer value. Maybe use GetNetObjEntityName to return the string value instead?

@tens0rfl0w
Copy link
Contributor Author

My intention was to match existing other custom native implementations like: GET_VEHICLE_TYPE_RAW. I would argue that comparing to an int is less user-error prone and also faster in some cases (though this probably doesn't really matter).

But of course, if you prefer returning the type as a string here, I will change this👍🏼

@AvarianKnight
Copy link
Contributor

I'm not a huge fan of returning the raw integer value. Maybe use GetNetObjEntityName to return the string value instead?

Would it not be better to just make two natives new natives for this and have one return the string and one return the raw integer value?

GET_NET_OBJ_TYPE -> returns as string (though maybe not specifically from GetNetObjEntityName as the CNetObj substring is a bit redundant
GET_NET_OBJ_TYPE_RAW -> returns as int

I don't think many people (though i could be a bit biased here) really care about the string representation unless they're debugging.

@slashkeyvalue
Copy link
Contributor

I also prefer strings due to the fact that we don't have enums or equivalents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RedM Issues/PRs related to RedM triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants