diff --git a/code/components/extra-natives-five/src/PopulationNatives.cpp b/code/components/extra-natives-five/src/PopulationNatives.cpp index d72679c672..29597c2193 100644 --- a/code/components/extra-natives-five/src/PopulationNatives.cpp +++ b/code/components/extra-natives-five/src/PopulationNatives.cpp @@ -7,6 +7,12 @@ #include "Resource.h" #include "ResourceScriptingComponent.h" +#include + +namespace rage +{ + using Vec3V = DirectX::XMVECTOR; +} static hook::cdecl_stub _loadPopGroups([] { @@ -18,6 +24,12 @@ static hook::cdecl_stub _reloadPopGroups([] return hook::get_pattern("74 4D 48 8B C8 E8 ? ? ? ? 33 DB", -0x1E); }); +static hook::cdecl_stub _GeneratePedsAtScenarioPoints([] +{ + return hook::get_pattern("48 8B C4 48 89 58 ? 48 89 70 ? 57 48 83 EC ? 8B 9C 24"); +}); + + static fx::OMPtr GetCurrentScriptHost() { fx::OMPtr runtime; @@ -84,4 +96,24 @@ static InitFunction initFunction([] UnloadPopGroups(); } }); + + fx::ScriptEngine::RegisterNativeHandler("GENERATE_PEDS_AT_SCENARIO_POINTS", [](fx::ScriptContext& context) + { + float x = context.GetArgument(0); + float y = context.GetArgument(1); + float z = context.GetArgument(2); + auto allowDeepInteriors = context.GetArgument(3); + auto rangeOutOfViewMin = context.GetArgument(4); + auto rangeOutOfViewMax = context.GetArgument(5); + auto rangeInViewMin = context.GetArgument(6); + auto rangeInViewMax = context.GetArgument(7); + auto rangeFrustumExtra = context.GetArgument(8); + auto doInFrustumTest = context.GetArgument(9); + auto maxPeds = context.GetArgument(10); + auto maxInteriorPeds = context.GetArgument(11); + + rage::Vec3V popControlCentre = DirectX::XMVectorSet(x, y, z, 0.0f); + _GeneratePedsAtScenarioPoints(&popControlCentre, allowDeepInteriors, rangeOutOfViewMin, rangeOutOfViewMax, rangeInViewMin, rangeInViewMax, + rangeFrustumExtra, doInFrustumTest, maxPeds, maxInteriorPeds); + }); }); diff --git a/ext/native-decls/GeneratePedsAtScenarioPoints.md b/ext/native-decls/GeneratePedsAtScenarioPoints.md new file mode 100644 index 0000000000..82b4f83368 --- /dev/null +++ b/ext/native-decls/GeneratePedsAtScenarioPoints.md @@ -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) +``` \ No newline at end of file