Skip to content

Commit

Permalink
feat(extra-natives/five): GET_ENTITY_HEALTH_FLOAT
Browse files Browse the repository at this point in the history
  • Loading branch information
packfile committed Nov 17, 2023
1 parent bb270ff commit 583877d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions code/components/extra-natives-five/src/EntityExtraNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,19 @@ static InitFunction initFunction([]()
}

context.SetResult<bool>(result);
});

fx::ScriptEngine::RegisterNativeHandler("GET_ENTITY_HEALTH_FLOAT", [](fx::ScriptContext& context)
{
float health = 0.0f;
if (fwEntity* entity = rage::fwScriptGuid::GetBaseFromGuid(context.GetArgument<int>(0)))
{
// TODO: Change to use IsOfType<CPhysical>() once fixed for b2802+ (currently fails to check inherited types)
if (entity->IsOfType<CPed>() || entity->IsOfType<CVehicle>() || entity->IsOfType<CObject>())
{
health = static_cast<CPhysical*>(entity)->GetHealth();
}
}
context.SetResult(health);
});
});
19 changes: 19 additions & 0 deletions code/components/gta-streaming-five/include/EntitySystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,25 @@ class STREAMING_EXPORT fwEntity : public rage::fwRefAwareBase
Matrix4x4 m_transform;
char m_pad4[48];
void* m_netObject;
};

class CEntity : public fwEntity
{

};

class CDynamicEntity : public CEntity
{

};

class CPhysical : public CDynamicEntity
{
public:
inline float GetHealth()
{
return *(float*)((char*)this + 0x280);
}
};

STREAMING_EXPORT class VehicleSeatManager
Expand Down
16 changes: 16 additions & 0 deletions ext/native-decls/GetEntityHealthFloat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
ns: CFX
apiset: client
---
## GET_ENTITY_HEALTH_FLOAT

```c
float GET_ENTITY_HEALTH_FLOAT(Entity entity);
```
Gets the health of an entity directly in its floating-point form. Unlike [GET_ENTITY_HEALTH](#_0xEEF059FAD016D209) this does not round the value.
## Parameters
* **entity**:
## Return value

0 comments on commit 583877d

Please sign in to comment.