Skip to content

Commit 0326993

Browse files
committed
Added ability to force peds to spawn with specific weapons
1 parent 82a2dd7 commit 0326993

1 file changed

Lines changed: 64 additions & 33 deletions

File tree

ModelVariations/ModelVariations.cpp

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <CGeneral.h>
1111
#include <CMessages.h>
12+
#include <CModelInfo.h>
1213
#include <CPopulation.h>
1314
#include <CStreaming.h>
1415
#include <CTheZones.h>
@@ -31,7 +32,7 @@ using namespace plugin;
3132
std::string pedIniPath("ModelVariations_Peds.ini");
3233
std::string pedWepIniPath("ModelVariations_PedWeapons.ini");
3334
std::string vehIniPath("ModelVariations_Vehicles.ini");
34-
std::string settingsIniPath("ModelVariations_ModSettings.ini");
35+
std::string settingsIniPath("ModelVariations.ini");
3536

3637
std::string exeHashes[2] = { "a559aa772fd136379155efa71f00c47aad34bbfeae6196b0fe1047d0645cbd26", //HOODLUM
3738
"25580ae242c6ecb6f6175ca9b4c912aa042f33986ded87f20721b48302adc9c9" }; //Compact
@@ -41,6 +42,7 @@ std::set<std::pair<unsigned int, std::string>> modulesSet;
4142
std::set<std::pair<unsigned int, std::string>> callChecks;
4243

4344
CIniReader iniVeh;
45+
CIniReader iniSettings;
4446

4547
std::array<std::vector<unsigned short>, 16> pedVariations[300];
4648
std::array<std::vector<unsigned short>, 16> vehVariations[212];
@@ -563,7 +565,7 @@ class ModelVariations {
563565

564566
static CIniReader iniPed(pedIniPath);
565567
static CIniReader iniWeap(pedWepIniPath);
566-
static CIniReader iniSettings(settingsIniPath);
568+
iniSettings.SetIniPath(settingsIniPath);
567569
iniVeh.SetIniPath(vehIniPath);
568570

569571
static int currentWanted = 0;
@@ -908,59 +910,88 @@ class ModelVariations {
908910

909911
if (!pedRemoved)
910912
{
911-
auto wepFound = [ped] (int &i, std::vector<unsigned short> vec) {
912-
int activeSlot = ped->m_nActiveWeaponSlot;
913-
unsigned int random = CGeneral::GetRandomNumberInRange(0, (int)vec.size());
914-
913+
auto wepFound = [ped] (eWeaponType weaponId, eWeaponType originalWeaponId) -> bool {
915914
int weapModel = 0;
916-
Command<COMMAND_GET_WEAPONTYPE_MODEL>(vec[random], &weapModel);
915+
Command<COMMAND_GET_WEAPONTYPE_MODEL>(weaponId, &weapModel);
917916
if (weapModel >= 321)
918917
{
919918
CStreaming::RequestModel(weapModel, 2);
920919
CStreaming::LoadAllRequestedModels(false);
921920

922-
ped->ClearWeapon(ped->m_aWeapons[i].m_nType);
923-
ped->GiveWeapon((eWeaponType)(vec[random]), 9999, 0);
924-
ped->SetCurrentWeapon(activeSlot);
921+
if (originalWeaponId > 0)
922+
ped->ClearWeapon(originalWeaponId);
923+
else
924+
ped->ClearWeapons();
925+
Command<COMMAND_GIVE_WEAPON_TO_CHAR>(CPools::GetPedRef(ped), weaponId, 9999);
926+
//ped->GiveWeapon(weaponId, 9999, 0);
927+
return true;
925928
}
929+
return false;
926930
};
927931

928-
for (int i = 0; i < 13; i++)
929-
if (ped->m_aWeapons[i].m_nType > 0)
930-
{
931-
std::string slot = "SLOT" + std::to_string(i);
932-
std::vector<unsigned short> vec = iniLineParser(std::to_string(ped->m_nModelIndex), slot, &iniWeap);
933-
if (vec.empty())
932+
std::string section = std::to_string(ped->m_nModelIndex);
933+
std::string currentZoneString(currentZone);
934+
int mergeWeapons = iniWeap.ReadInteger(section, "MergeZonesWithGlobal", 0);
935+
936+
//if (ped->m_pVehicle != NULL)
937+
//currentVehicle = reinterpret_cast<CVehicleModelInfo*>(CModelInfo::GetModelInfo(ped->m_pVehicle->m_nModelIndex))->m_szGameName;
938+
939+
bool changeWeapon = true;
940+
bool wepChanged = false;
941+
942+
std::vector<unsigned short> vec = iniLineParser(section, "WEAPONFORCE", &iniWeap);
943+
if (!vec.empty())
944+
{
945+
eWeaponType forceWeapon = (eWeaponType)vec[CGeneral::GetRandomNumberInRange(0, vec.size())];
946+
if ((wepChanged = wepFound(forceWeapon, (eWeaponType)0)) == true)
947+
changeWeapon = (bool)CGeneral::GetRandomNumberInRange(0, 2);
948+
}
949+
950+
if ((changeWeapon || mergeWeapons == 0) && !(vec = iniLineParser(section, currentZoneString + "_WEAPONFORCE", &iniWeap)).empty())
951+
{
952+
eWeaponType forceWeapon = (eWeaponType)vec[CGeneral::GetRandomNumberInRange(0, vec.size())];
953+
wepChanged |= wepFound(forceWeapon, (eWeaponType)0);
954+
}
955+
956+
if (!wepChanged)
957+
for (int i = 0; i < 13; i++)
958+
if (ped->m_aWeapons[i].m_nType > 0)
934959
{
935-
if (CGeneral::GetRandomNumberInRange(0, 100) > 50)
960+
eWeaponType weaponId = ped->m_aWeapons[i].m_nType;
961+
bool changeZoneWeapon = true;
962+
bool changeZoneSlot = true;
963+
int currentSlot = ped->m_nActiveWeaponSlot;
964+
965+
std::string slot = "SLOT" + std::to_string(i);
966+
vec = iniLineParser(section, slot, &iniWeap);
967+
if (!vec.empty() && (wepChanged = wepFound((eWeaponType)vec[CGeneral::GetRandomNumberInRange(0, (int)vec.size())], ped->m_aWeapons[i].m_nType)) == true)
968+
changeZoneSlot = (bool)CGeneral::GetRandomNumberInRange(0, 2);
969+
970+
if (changeZoneSlot || mergeWeapons == 0)
936971
{
937972
slot = currentZone;
938973
slot += "_SLOT" + std::to_string(i);
939-
vec = iniLineParser(std::to_string(ped->m_nModelIndex), slot, &iniWeap);
974+
vec = iniLineParser(section, slot, &iniWeap);
940975
if (!vec.empty())
941-
wepFound(i, vec);
976+
wepChanged |= wepFound((eWeaponType)vec[CGeneral::GetRandomNumberInRange(0, (int)vec.size())], ped->m_aWeapons[i].m_nType);
942977
}
943-
}
944-
else
945-
wepFound(i, vec);
946978

979+
std::string wep = "WEAPON" + std::to_string(weaponId);
980+
vec = iniLineParser(section, wep, &iniWeap);
981+
if (!vec.empty() && (wepChanged = wepFound((eWeaponType)vec[CGeneral::GetRandomNumberInRange(0, (int)vec.size())], ped->m_aWeapons[i].m_nType)) == true)
982+
changeZoneWeapon = (bool)CGeneral::GetRandomNumberInRange(0, 2);
947983

948-
std::string wep = "WEAPON" + std::to_string(ped->m_aWeapons[i].m_nType);
949-
vec = iniLineParser(std::to_string(ped->m_nModelIndex), wep, &iniWeap);
950-
if (vec.empty())
951-
{
952-
if (CGeneral::GetRandomNumberInRange(0, 100) > 50)
984+
if (changeZoneWeapon || mergeWeapons == 0)
953985
{
954986
wep = currentZone;
955-
wep += "_WEAPON" + std::to_string(ped->m_aWeapons[i].m_nType);
956-
vec = iniLineParser(std::to_string(ped->m_nModelIndex), wep, &iniWeap);
987+
wep += "_WEAPON" + std::to_string(weaponId);
988+
vec = iniLineParser(section, wep, &iniWeap);
957989
if (!vec.empty())
958-
wepFound(i, vec);
990+
wepChanged |= wepFound((eWeaponType)vec[CGeneral::GetRandomNumberInRange(0, (int)vec.size())], ped->m_aWeapons[i].m_nType);
959991
}
992+
if (wepChanged)
993+
ped->SetCurrentWeapon(currentSlot);
960994
}
961-
else
962-
wepFound(i, vec);
963-
}
964995
}
965996
}
966997
};

0 commit comments

Comments
 (0)