Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invincible peds #777

Merged
9 commits merged into from
Apr 20, 2020
Merged

Fix invincible peds #777

9 commits merged into from
Apr 20, 2020

Conversation

FileEX
Copy link
Contributor

@FileEX FileEX commented Jan 14, 2019

Fixes #414

Bug description
The only way to respawn a ped is with setElementHealth, yet after calling setElementHealth on a dead ped, the server returns true for isPedDead. You can't damage the ped any more even though ped.health == 100.

To reproduce

crun setElementPosition(localPlayer, 1968, -2033, 13)
srun a = createPed(0, 1967, -2025, 13)
-- Kill the ped
srun isPedDead(a) -- true
srun setElementHealth(a, 100)
srun isPedDead(a) -- true (should be false)
-- Shoot the ped, it won't take damage

Now isPedDead returns false after setElementHealth on dead ped. And ped after setElementHealth(ped,100) isn't invicibles, and will got damage.

Fixed also ArranTuna issue from previous PR

I've tested this PR and well it works but there's an issue. After killing the ped and doing setElementHealth(a, 100) the ped gets back up again but then falls down dead again 1 second later. It's alive state is correct but it acts dead, streaming out and back in shows it as stood up. However if I call setElementHealth a second time the ped stands up correctly. Strange.

@botder botder added the bug Something isn't working label Jan 31, 2019
@qaisjp qaisjp assigned ArranTuna and unassigned ArranTuna Feb 11, 2019
@qaisjp qaisjp added this to the 1.5.7 milestone Feb 11, 2019
@qaisjp
Copy link
Contributor

qaisjp commented Feb 11, 2019

Thanks for the bugfix. Code looks fine but won't approve as I haven't actually tested it.

This change isn't limited to peds, so in what way does this change affect players?

@qaisjp qaisjp added the feedback Further information is requested label Feb 11, 2019
Copy link
Collaborator

@ArranTuna ArranTuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works.

@FileEX
Copy link
Contributor Author

FileEX commented Feb 11, 2019

It does not affect players in any way. It only causes that the 'reborn' ped is not indestructible.

@patrikjuvonen patrikjuvonen changed the title Fix invincible peds WIP: Fix invincible peds Feb 23, 2019
@qaisjp qaisjp modified the milestones: 1.5.7, Backlog Aug 2, 2019
@qaisjp qaisjp changed the title WIP: Fix invincible peds Fix invincible peds Mar 23, 2020
@qaisjp
Copy link
Contributor

qaisjp commented Mar 23, 2020

@FileEX what can we do to help you fix this issue?

(@patrikjuvonen i've removed the WIP prefix because it didn't look like this PR was a draft — feel free to undo my undo)

@ghost
Copy link

ghost commented Apr 2, 2020

@patrikjuvonen is right. The crash comes from m_pTaskManager->RemoveTask(TASK_SIMPLE_DEAD);
You are passing a task type to m_pTaskManager->RemoveTask instead of passing the primary task index. There are only 5 primary tasks. Take a look at this:

enum
{
    TASK_PRIORITY_PHYSICAL_RESPONSE = 0,
    TASK_PRIORITY_EVENT_RESPONSE_TEMP,
    TASK_PRIORITY_EVENT_RESPONSE_NONTEMP,
    TASK_PRIORITY_PRIMARY,
    TASK_PRIORITY_DEFAULT,
    TASK_PRIORITY_MAX
};

This means the range of primary task index is 0 to 4. The value of TASK_SIMPLE_DEAD is 218; hence it causes a crash.

TASK_SIMPLE_DEAD is set to TASK_PRIORITY_EVENT_RESPONSE_NONTEMP. This means, your code should look like this if you want to remove the task:

m_pTaskManager->RemoveTask(TASK_PRIORITY_EVENT_RESPONSE_NONTEMP);

Obviously, this requires testing. We'll have to confirm that it doesn't cause any bugs.

@FileEX
Copy link
Contributor Author

FileEX commented Apr 3, 2020

Changed

@ghost ghost merged commit e43d34f into multitheftauto:master Apr 20, 2020
@qaisjp qaisjp removed the feedback Further information is requested label Apr 20, 2020
@patrikjuvonen patrikjuvonen added this to the 1.5.8 milestone Apr 20, 2020
qaisjp added a commit that referenced this pull request Apr 23, 2020
Reopens #414

Reverts #777

This reverts commit e43d34f.
@qaisjp
Copy link
Contributor

qaisjp commented Apr 23, 2020

Reverted in 159d291

@patrikjuvonen patrikjuvonen removed this from the 1.5.8 milestone Apr 24, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using setElementHealth on a dead ped makes it invincible
5 participants