mtasa-blue
mtasa-blue copied to clipboard
Add the possibility to cancel `onPedDamage` event - QOL feature
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
- [X] I have read and understood the Security Policy and this issue is not about a cheat or security vulnerability.
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 )
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 (https://github.com/multitheftauto/mtasa-blue/issues/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
if the server sends packets to the client about ped damage then
cancelEventshould 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 the server sends packets to the client about ped damage then
cancelEventshould not send any synchronization packets and ignore everything. At least thats how I would see it to be the most reasonable and performant solutionWe 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
The sync packet covers a lot of information, not just health, so you can't just cancel it
https://github.com/multitheftauto/mtasa-blue/blob/1f2c6e75fb71b01f0053f151e766a232ed33692b/Server/mods/deathmatch/logic/CPedSync.cpp#L245-L264