Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions code/components/extra-natives-five/src/PopulationNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

#include "Resource.h"
#include "ResourceScriptingComponent.h"
#include <Hooking.Stubs.h>

namespace rage
{
using Vec3V = DirectX::XMVECTOR;
}

static hook::cdecl_stub<void(const char*)> _loadPopGroups([]
{
Expand All @@ -18,6 +24,12 @@ static hook::cdecl_stub<void()> _reloadPopGroups([]
return hook::get_pattern("74 4D 48 8B C8 E8 ? ? ? ? 33 DB", -0x1E);
});

static hook::cdecl_stub<void(rage::Vec3V*, bool, float, float, float, float, float, bool, int, int)> _GeneratePedsAtScenarioPoints([]
{
return hook::get_pattern("48 8B C4 48 89 58 ? 48 89 70 ? 57 48 83 EC ? 8B 9C 24");
});


static fx::OMPtr<IScriptHost> GetCurrentScriptHost()
{
fx::OMPtr<IScriptRuntime> runtime;
Expand Down Expand Up @@ -84,4 +96,24 @@ static InitFunction initFunction([]
UnloadPopGroups();
}
});

fx::ScriptEngine::RegisterNativeHandler("GENERATE_PEDS_AT_SCENARIO_POINTS", [](fx::ScriptContext& context)
{
float x = context.GetArgument<float>(0);
float y = context.GetArgument<float>(1);
float z = context.GetArgument<float>(2);
auto allowDeepInteriors = context.GetArgument<bool>(3);
auto rangeOutOfViewMin = context.GetArgument<float>(4);
auto rangeOutOfViewMax = context.GetArgument<float>(5);
auto rangeInViewMin = context.GetArgument<float>(6);
auto rangeInViewMax = context.GetArgument<float>(7);
auto rangeFrustumExtra = context.GetArgument<float>(8);
auto doInFrustumTest = context.GetArgument<bool>(9);
auto maxPeds = context.GetArgument<int>(10);
auto maxInteriorPeds = context.GetArgument<int>(11);

rage::Vec3V popControlCentre = DirectX::XMVectorSet(x, y, z, 0.0f);
_GeneratePedsAtScenarioPoints(&popControlCentre, allowDeepInteriors, rangeOutOfViewMin, rangeOutOfViewMax, rangeInViewMin, rangeInViewMax,
rangeFrustumExtra, doInFrustumTest, maxPeds, maxInteriorPeds);
});
});
50 changes: 50 additions & 0 deletions ext/native-decls/GeneratePedsAtScenarioPoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
ns: CFX
apiset: client
game: gta5
---
## GENERATE_PEDS_AT_SCENARIO_POINTS

```c
void GENERATE_PEDS_AT_SCENARIO_POINTS(float popControlCentreX, float popControlCentreY, float popControlCentreZ, BOOL allowDeepInteriors, float rangeOutOfViewMin, float rangeOutOfViewMax, float rangeInViewMin, float rangeInViewMax, float rangeFrustumExtra, bool doInFrustumTest, int maxPeds, int maxInteriorPeds);
```

Generates peds for scenario points in the provided view range, optionally include / exclude interiors.
this operation is quite costly, so try not to call it to frequently.

## Parameters
* **popControlCentreX**: X position of the control center.
* **popControlCentreY**: Y position of the control center.
* **popControlCentreZ**: Z position of the control center.
* **allowDeepInteriors**: Allows peds to generate deep inside interiors.
* **rangeOutOfViewMin**: Min range at which peds generate outside the players view, keep within ~10 meters of max value.
* **rangeOutOfViewMax**: Max range at which peds generate outside the players view, keep within ~10 meters of min value.
* **rangeInViewMin**: Min range at which peds generate inside the players view, keep within ~10 meters of max value.
* **rangeInViewMax**: Max range at which peds generate inside the players view, keep within ~10 meters of min value.
* **rangeFrustumExtra**: extends frustum distance.
* **doInFrustumTest**: if true, check if the scenario point can be seen by the player.
* **maxPeds**: Maximum amount of peds to generate.
* **maxInteriorPeds**: Maximum amount of interior peds to generate.

## Examples
```lua
Citizen.CreateThread(function()
while true do
Citizen.Wait(5000) -- generate peds every 5 seconds
local playerPed = PlayerPedId()
local pos = GetEntityCoords(playerPed)
local x, y, z = table.unpack(pos)
local allowDeepInteriors = false
local rangeOutOfViewMin = 10.0
local rangeOutOfViewMax = 20.0
local rangeInViewMin = 20.0
local rangeInViewMax = 30.0
local rangeFrustumExtra = 50.0
local doInFrustumTest = false
local maxPeds = 100
local maxInteriorPeds = 100
GeneratePedsAtScenarioPoints(x, y, z, allowDeepInteriors, rangeOutOfViewMin, rangeOutOfViewMax, rangeInViewMin, rangeInViewMax,
rangeFrustumExtra, doInFrustumTest, maxPeds, maxInteriorPeds)
end
end, false)
```