From 87b63204e2c9dbbb948e0dacec215bcafec3730d Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 4 Dec 2022 01:31:09 +0600 Subject: [PATCH] [VC | III]Add weapon spawn for peds --- src/pages/ped.cpp | 13 +++++++++++-- src/pages/weapon.cpp | 16 +++++++++------- src/pages/weapon.h | 6 ++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/pages/ped.cpp b/src/pages/ped.cpp index 6d38784..d907a15 100644 --- a/src/pages/ped.cpp +++ b/src/pages/ped.cpp @@ -228,16 +228,25 @@ void PedPage::SpawnPed(std::string& cat, std::string& name, std::string& model) ped->m_nPedFlags.bPedIsBleeding = m_Spawner.m_bPedBleed; ped->m_nWeaponAccuracy = m_Spawner.m_nAccuracy; ped->m_fHealth = m_Spawner.m_nPedHealth; -#ifdef GTASA + if (m_Spawner.m_nWeaponId != 0) { int model = 0; +#ifdef GTASA Command(m_Spawner.m_nWeaponId, &model); +#else + model = static_cast(m_Spawner.m_nWeaponId); + m_Spawner.m_nWeaponId = weaponPage.GetWeaponType(model); +#endif CStreaming::RequestModel(model, PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); Command(hplayer, m_Spawner.m_nWeaponId, 999); - } + + Command(model); +#ifdef GTA3 + Command(0, weaponType); #endif + } } } diff --git a/src/pages/weapon.cpp b/src/pages/weapon.cpp index 240b87a..a64bff5 100644 --- a/src/pages/weapon.cpp +++ b/src/pages/weapon.cpp @@ -143,17 +143,19 @@ static void ClearPlayerWeapon(eWeaponType weaponType) } } +int WeaponPage::GetWeaponModel(eWeaponType weaponType) +{ + int rtn = CallAndReturn(weaponType); // int __cdecl CPickups::ModelForWeapon(int a1) + return rtn; +} + // Implementation of opcode 0x605 (CLEO) -static eWeaponType GetWeaponTypeFromModel(int model) +eWeaponType WeaponPage::GetWeaponType(int model) { eWeaponType weaponType = WEAPONTYPE_UNARMED; - for (size_t i = 0; i < 37; i++) { - - int temp = CallAndReturn(i); // int __cdecl CPickups::ModelForWeapon(int a1) - - if (temp == model) + if (GetWeaponModel(static_cast(i)) == model) { weaponType = (eWeaponType)i; break; @@ -217,7 +219,7 @@ void WeaponPage::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std CStreaming::RequestModel(iModel, PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); - eWeaponType weaponType = GetWeaponTypeFromModel(iModel); + eWeaponType weaponType = GetWeaponType(iModel); Command(hplayer, weaponType, m_nAmmoCount); Command(iModel); #ifdef GTA3 diff --git a/src/pages/weapon.h b/src/pages/weapon.h index 1832ea1..3e4a0ec 100644 --- a/src/pages/weapon.h +++ b/src/pages/weapon.h @@ -58,6 +58,12 @@ public: void GiveWeaponToPlayer(std::string& weaponType); #else void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); + + // Returns weapon model from weaponType + int GetWeaponModel(eWeaponType weaponType); + + // Returns weaponType from model + eWeaponType GetWeaponType(int weaponModel); #endif };