From 9ca09bd61323c312e24e98c95b6e4f95c37c2c5c Mon Sep 17 00:00:00 2001 From: Rylxnd Date: Tue, 29 Aug 2023 10:04:12 -0400 Subject: [PATCH 1/2] Create & Expose "CreatePoolPedEnemy" to Lua Runtime --- ChaosMod/Components/LuaScripts.cpp | 1 + ChaosMod/Util/PoolSpawner.cpp | 42 ++++++++++++++++++++++++++++++ ChaosMod/Util/PoolSpawner.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/ChaosMod/Components/LuaScripts.cpp b/ChaosMod/Components/LuaScripts.cpp index 978a6ac0f..dda18c2cb 100644 --- a/ChaosMod/Components/LuaScripts.cpp +++ b/ChaosMod/Components/LuaScripts.cpp @@ -615,6 +615,7 @@ LuaScripts::ParseScriptRaw(std::string scriptName, std::string_view script, Pars E("GetAllPeds", GetAllPedsArray), E("CreatePoolPed", CreatePoolPed), + E("CreatePoolPedEnemy", CreatePoolPedEnemy), E("TeleportPlayer", [](float x, float y, float z, bool noOffset) { TeleportPlayer(x, y, z, noOffset); }), diff --git a/ChaosMod/Util/PoolSpawner.cpp b/ChaosMod/Util/PoolSpawner.cpp index 000aa747c..df42437d0 100644 --- a/ChaosMod/Util/PoolSpawner.cpp +++ b/ChaosMod/Util/PoolSpawner.cpp @@ -133,6 +133,48 @@ Ped CreatePoolPed(int pedType, Hash modelHash, float x, float y, float z, float return ped; } +Ped CreatePoolPedEnemy(int pedType, Hash modelHash, float x, float y, float z, float heading, Hash weaponHash, bool inPlayerVehicle) +{ + LoadModel(modelHash); + + Ped ped = CREATE_PED(pedType, modelHash, x, y, z, heading, true, false); + + Ped playerPed = PLAYER_PED_ID(); + Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false); + + static const Hash playerGroup = "PLAYER"_hash; + static const Hash civGroup = "CIVMALE"_hash; + static const Hash femCivGroup = "CIVFEMALE"_hash; + + Hash relationshipGroup; + ADD_RELATIONSHIP_GROUP("_GENERIC_HOSTILE_PED", &relationshipGroup); + SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, playerGroup); + SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, civGroup); + SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, femCivGroup); + + if (IS_PED_IN_ANY_VEHICLE(playerPed, false) && inPlayerVehicle) + { + SET_PED_INTO_VEHICLE(ped, GET_VEHICLE_PED_IS_IN(playerPed, false), -2); + } + + SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup); + SET_PED_HEARING_RANGE(ped, 9999.f); + SET_PED_CONFIG_FLAG(ped, 281, true); + + SET_PED_COMBAT_ATTRIBUTES(ped, 5, true); + SET_PED_COMBAT_ATTRIBUTES(ped, 46, true); + + GIVE_WEAPON_TO_PED(ped, weaponHash, 9999, true, true); + TASK_COMBAT_PED(ped, playerPed, 0, 16); + + SET_PED_FIRING_PATTERN(ped, 0xC6EE6B4C); + + SET_MODEL_AS_NO_LONGER_NEEDED(modelHash); + HandleEntity(ped); + + return ped; +} + Ped CreateRandomPoolPed(float x, float y, float z, float heading) { const auto &pedModels = Memory::GetAllPedModels(); diff --git a/ChaosMod/Util/PoolSpawner.h b/ChaosMod/Util/PoolSpawner.h index 93d990323..e07937c76 100644 --- a/ChaosMod/Util/PoolSpawner.h +++ b/ChaosMod/Util/PoolSpawner.h @@ -8,6 +8,8 @@ void ClearEntityPool(int distance = 0); Ped CreatePoolClonePed(Ped pedToClone); Ped CreatePoolPed(int pedType, Hash modelHash, float x, float y, float z, float heading); +Ped CreatePoolPedEnemy(int pedType, Hash modelHash, float x, float y, float z, float heading, Hash weapon, + bool inPlayerVehicle); Ped CreateRandomPoolPed(float x, float y, float z, float heading); Ped CreatePoolPedInsideVehicle(Vehicle vehicle, int pedType, Hash modelHash, int seatIdx); From 7e2d6395dc8ed6f8fd898f4a0021d8cb869a7ac9 Mon Sep 17 00:00:00 2001 From: Rylxnd Date: Tue, 29 Aug 2023 10:39:02 -0400 Subject: [PATCH 2/2] use CreateHostilePed --- ChaosMod/Components/LuaScripts.cpp | 2 +- ChaosMod/Util/PoolSpawner.cpp | 42 ------------------------------ ChaosMod/Util/PoolSpawner.h | 2 -- 3 files changed, 1 insertion(+), 45 deletions(-) diff --git a/ChaosMod/Components/LuaScripts.cpp b/ChaosMod/Components/LuaScripts.cpp index dda18c2cb..740a09a62 100644 --- a/ChaosMod/Components/LuaScripts.cpp +++ b/ChaosMod/Components/LuaScripts.cpp @@ -615,7 +615,7 @@ LuaScripts::ParseScriptRaw(std::string scriptName, std::string_view script, Pars E("GetAllPeds", GetAllPedsArray), E("CreatePoolPed", CreatePoolPed), - E("CreatePoolPedEnemy", CreatePoolPedEnemy), + E("CreateHostilePed", CreateHostilePed), E("TeleportPlayer", [](float x, float y, float z, bool noOffset) { TeleportPlayer(x, y, z, noOffset); }), diff --git a/ChaosMod/Util/PoolSpawner.cpp b/ChaosMod/Util/PoolSpawner.cpp index df42437d0..000aa747c 100644 --- a/ChaosMod/Util/PoolSpawner.cpp +++ b/ChaosMod/Util/PoolSpawner.cpp @@ -133,48 +133,6 @@ Ped CreatePoolPed(int pedType, Hash modelHash, float x, float y, float z, float return ped; } -Ped CreatePoolPedEnemy(int pedType, Hash modelHash, float x, float y, float z, float heading, Hash weaponHash, bool inPlayerVehicle) -{ - LoadModel(modelHash); - - Ped ped = CREATE_PED(pedType, modelHash, x, y, z, heading, true, false); - - Ped playerPed = PLAYER_PED_ID(); - Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false); - - static const Hash playerGroup = "PLAYER"_hash; - static const Hash civGroup = "CIVMALE"_hash; - static const Hash femCivGroup = "CIVFEMALE"_hash; - - Hash relationshipGroup; - ADD_RELATIONSHIP_GROUP("_GENERIC_HOSTILE_PED", &relationshipGroup); - SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, playerGroup); - SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, civGroup); - SET_RELATIONSHIP_BETWEEN_GROUPS(5, relationshipGroup, femCivGroup); - - if (IS_PED_IN_ANY_VEHICLE(playerPed, false) && inPlayerVehicle) - { - SET_PED_INTO_VEHICLE(ped, GET_VEHICLE_PED_IS_IN(playerPed, false), -2); - } - - SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup); - SET_PED_HEARING_RANGE(ped, 9999.f); - SET_PED_CONFIG_FLAG(ped, 281, true); - - SET_PED_COMBAT_ATTRIBUTES(ped, 5, true); - SET_PED_COMBAT_ATTRIBUTES(ped, 46, true); - - GIVE_WEAPON_TO_PED(ped, weaponHash, 9999, true, true); - TASK_COMBAT_PED(ped, playerPed, 0, 16); - - SET_PED_FIRING_PATTERN(ped, 0xC6EE6B4C); - - SET_MODEL_AS_NO_LONGER_NEEDED(modelHash); - HandleEntity(ped); - - return ped; -} - Ped CreateRandomPoolPed(float x, float y, float z, float heading) { const auto &pedModels = Memory::GetAllPedModels(); diff --git a/ChaosMod/Util/PoolSpawner.h b/ChaosMod/Util/PoolSpawner.h index e07937c76..93d990323 100644 --- a/ChaosMod/Util/PoolSpawner.h +++ b/ChaosMod/Util/PoolSpawner.h @@ -8,8 +8,6 @@ void ClearEntityPool(int distance = 0); Ped CreatePoolClonePed(Ped pedToClone); Ped CreatePoolPed(int pedType, Hash modelHash, float x, float y, float z, float heading); -Ped CreatePoolPedEnemy(int pedType, Hash modelHash, float x, float y, float z, float heading, Hash weapon, - bool inPlayerVehicle); Ped CreateRandomPoolPed(float x, float y, float z, float heading); Ped CreatePoolPedInsideVehicle(Vehicle vehicle, int pedType, Hash modelHash, int seatIdx);