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

Add the possibility to cancel onPedDamage event - QOL feature #3387

Open
1 task done
TracerDS opened this issue May 13, 2024 · 5 comments
Open
1 task done

Add the possibility to cancel onPedDamage event - QOL feature #3387

TracerDS opened this issue May 13, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@TracerDS
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Right now to cancel ped's damage you have to use onClientPedDamage or do an extensive check with onPedWasted + setElementHealth.
Cancelling the event will be a very good QOL feature.

Describe the solution you'd like

Be able to cancel onPedDamage event

Describe alternatives you've considered

No response

Additional context

No response

Security Policy

  • I have read and understood the Security Policy and this issue is not about a cheat or security vulnerability.
@TracerDS TracerDS added the enhancement New feature or request label May 13, 2024
@FileEX
Copy link
Contributor

FileEX commented May 13, 2024

Damage Handler is located on the client side and this is where the onClientPedDamage event is sent and, depending on its status, the handler returns the result.

The server-side event works based on the synchronization packet, where the amount of HP is compared between packets. I think a reasonable solution would be to set the HP amount to something like "current HP + loss" if the event was canceled.

However, I don't know what happens when the ped/player dies? Then, despite the event being canceled, onPedWasted will be sent + the invicible bug will probably appear (#414 )

@TracerDS
Copy link
Contributor Author

TracerDS commented May 13, 2024

Damage Handler is located on the client side and this is where the onClientPedDamage event is sent and, depending on its status, the handler returns the result.

The server-side event works based on the synchronization packet, where the amount of HP is compared between packets. I think a reasonable solution would be to set the HP amount to something like "current HP + loss" if the event was canceled.

if the server sends packets to the client about ped damage then cancelEvent should not send any synchronization packets and ignore everything. At least thats how I would see it to be the most reasonable and performant solution

However, I don't know what happens when the ped/player dies? Then, despite the event being canceled, onPedWasted will be sent + the invicible bug will probably appear (#414 )

Yeah we would need to check if loss >= currentHP and not run onPedWasted if the event was cancelled and ped died

I tried to implement it but its a lot of complicated work

@FileEX
Copy link
Contributor

FileEX commented May 13, 2024

if the server sends packets to the client about ped damage then cancelEvent should not send any synchronization packets and ignore everything. At least thats how I would see it to be the most reasonable and performant solution

We can't stop sending the sync packet and ignore everything. These packets concern general data synchronization between clients and the server, not just health. Canceling the sending of synchronization packets after canceling the event will cause desynchronization bugs

@TracerDS
Copy link
Contributor Author

if the server sends packets to the client about ped damage then cancelEvent should not send any synchronization packets and ignore everything. At least thats how I would see it to be the most reasonable and performant solution

We can't stop sending the sync packet and ignore everything. These packets concern general data synchronization between clients and the server, not just health. Canceling the sending of synchronization packets after canceling the event will cause desynchronization bugs

If its about health only then how would that cause desync with other players? For other ped related packets, sure. However if we are cancelling the damage event then only the packets responsible for ped's health should be ignored

@FileEX
Copy link
Contributor

FileEX commented May 13, 2024

The sync packet covers a lot of information, not just health, so you can't just cancel it

if (Data.ucFlags & 0x08)
{
// Less health than last time?
float fPreviousHealth = pPed->GetHealth();
pPed->SetHealth(Data.fHealth);
if (Data.fHealth < fPreviousHealth)
{
// Grab the delta health
float fDeltaHealth = fPreviousHealth - Data.fHealth;
if (fDeltaHealth > 0.0f)
{
// Call the onPedDamage event
CLuaArguments Arguments;
Arguments.PushNumber(fDeltaHealth);
pPed->CallEvent("onPedDamage", Arguments);
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants