mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

Add the possibility to cancel `onPedDamage` event - QOL feature

Open TracerDS opened this issue 1 year ago • 5 comments

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.

TracerDS avatar May 13 '24 16:05 TracerDS

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 )

FileEX avatar May 13 '24 18:05 FileEX

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

TracerDS avatar May 13 '24 18:05 TracerDS

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

FileEX avatar May 13 '24 19:05 FileEX

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

TracerDS avatar May 13 '24 20:05 TracerDS

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

FileEX avatar May 13 '24 21:05 FileEX