Skip to content

Commit 1712765

Browse files
committed
Fix issue #9817 (ped health XML attr doesn't work)
- By default a ped will be spawned at 100 health unless a health attribute is provided - Ped will be "spawned" even if they are spawned dead - Health is bound between 0 and 100 (I considered allowing health >100, but I went on the assumption that peds using this won't have any stats set)
1 parent 648c325 commit 1712765

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Server/mods/deathmatch/logic/CPed.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,20 @@ bool CPed::ReadSpecialData(void)
181181
return false;
182182
}
183183

184-
GetCustomDataFloat("health", m_fHealth, true);
184+
if (GetCustomDataFloat("health", m_fHealth, true))
185+
{
186+
// Limit it to 0-100 (we can assume max health is 100 because they can't change stats here)
187+
if (m_fHealth > 100)
188+
m_fHealth = 100;
189+
else if (m_fHealth < 0)
190+
m_fHealth = 0;
191+
}
192+
else
193+
{
194+
// Set health to 100 if not defined
195+
m_fHealth = 100.0f;
196+
}
197+
185198
GetCustomDataFloat("armor", m_fArmor, true);
186199

187200
if (GetCustomDataInt("interior", iTemp, true))

Server/mods/deathmatch/logic/CPedManager.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ CPed* CPedManager::CreateFromXML(CElement* pParent, CXMLNode& Node, CEvents* pEv
4848
return NULL;
4949
}
5050

51-
// Make sure hes alive (leave to scripts?)
52-
pPed->SetIsDead(false);
5351
pPed->SetSpawned(true);
54-
pPed->SetHealth(100.0f);
52+
53+
if (pPed->GetHealth() > 0)
54+
{
55+
pPed->SetIsDead(false);
56+
}
5557

5658
// Return the created Ped
5759
return pPed;

0 commit comments

Comments
 (0)