View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0008400||Multi Theft Auto : San Andreas||Scripting||public||2014-07-30 22:46||2014-08-27 14:46|
|Fixed in Version||1.4.1|
|Summary||0008400: Bug with setElementHealth in onClientPlayerDamage when hurt by a ped|
When setting element health lower than it is using onClientPlayerDamage when a pedestrian attacks you and you have over 100 health points, it always sets it to 100 and then starts to work properly.
|Steps To Reproduce|
function damage ( attacker, weapon, bodypart )
It is best seen if your health is 200. (with max_health stat 1000)
Only tested with 1.3.5-release-6162.3.000
|Tags||No tags attached.|
|Users sponsoring this issue|
Total Sponsorship = EUR 1
2014-08-20 20:41: Drakath (EUR 1)
Correction: using setElementHealth onClientPlayerDamage when a pedestrian attacks
Confirmed with v1.4-release-6751
Very strange bug, before setting the health it returns the correct value, after setting the health it returns 100.
Apparently something resets the health stat to 569 during onClientPlayerWeaponDamage. This leads to CClientPed::GetMaxHealth returning 100 as maximum health for setElementHealth.
Has nothing to do with peds hitting the player.
Alright, after another few hours of debugging I finally found the cause of this issue.
During world processing MTA switches peds and remote players into local player mode (CPlayerPed::ProcessControl instead of CPed::ProcessControl) to allow additional features. When this happens the stats array is temporarily being replaced by the ped's stats. CClientPlayer::GetStat however isn't aware of it and reads the (replaced) stats array if you try to access the localPlayer's stats during a remote ped's CPlayerPed::ProcessControl.
When a ped is hit or shot by another ped like in this case onClientPlayerDamage will be triggered from the attacking ped's ProcessControl function. This leads to CClientPlayer::GetMaxHealth returning the currently processed ped's max health, rather than the localPlayer's max health when called under the circumstances described in the bug report.