OneSync: intercepting game events (such as explosions)

Originally published at: https://cookbook.fivem.net/2019/08/19/onesync-intercepting-game-events-such-as-explosions/

The latest version of the Windows server added support for parsing and preventing routing of game events. This currently only supports parsing CExplosionEvent, but this might be a fairly useful one to prevent routing of ‘excessive’ explosions, or explosions that are ‘too close’ to a player and not of the correct weapon type. Here’s an…

19 Likes

Ok wow this is pretty fucking epic O.O

My hope is for this same method of verification to be able to be useable for all types of Client Events

Might be taxing but if not that would be megaepic

Good work team!

3 Likes

This looks pretty! Definitely use this :exploding_head:

Wow ! Anticheat update here i come !

1 Like

We’re using Sticky Bombs to test the event, it triggers the event on the server side; however it doesn’t cancel the event to stop the explosion.

Any ideas?

AddEventHandler('explosionEvent', function(sender, ev)
    if (ev.damageScale ~= 0.0) then
            CancelEvent()
            ev.damageScale = 0.0
            TriggerEvent('explosionEvent', sender, ev)
    end
end)
3 Likes

To add on to LanceGood’s post, this code whilst it does print the data, the event is not cancelled and explosions will still kill a player…

Such a shame, I was really looking forward to using this as soon as it came out…

AddEventHandler('explosionEvent', function(sender, ev)
    CancelEvent()
    print(GetPlayerName(sender), json.encode(ev))
end)
2 Likes

Weapon explosions are having a separate weapon damage event which is currently not hookable. This is mainly for script explosions as used by mass kill options in menus.

2 Likes

Does this mean using the above event will work for AddExplosion exploiting currently and stop all the modders from exploding using their menus? Also, is there an event which can handle all explosions?

Best Regards,
Badger

1 Like

The RPG will trigger this event.

Also, I’m currently having a problem with this event.
I’m getting spammed with apparently invalid explosions out of nowhere:

I’m thinking about just filtering out explosions with damageScale 0.

1 Like

Awesome. Please make other game event too like CreateVehicle, Ped ?

2 Likes

Might explain why most have stopped using explosions and now mass spawn vehicles on players, which is a difference I’ve noticed. Still, it is exciting and hope to see more from this.

We have protections on our server that prevents that & logs any that players may have made, so it is possible to make such.

I second this, along with GiveWeaponToPed

1 Like

entityCreated has existed for way, way longer than the explosion event, however?

I just found out about this earlier. Unfortunately, there isn’t anything on the forum regarding this, however?

Does it operate the same as the explosionEvent? for example:

AddEventHandler('entityCreated', function(sender, entity)
    print(GetPlayerName(sender), json.encode(entity))
end)

As I cannot seem to find any documentation on this.

Edit:

Found my answer:

AddEventHandler("entityCreated",  function(entity)
    print("Entity created" .. entity)
end)
3 Likes

So let me try to understand this if I create a new resource add those lines I will be able to stop the modders from exploding my server and spawn different stuff ? Or at least find out who is doing this ? But the question is: if completely delete the lines from natives, this will not help me much more then stopping it or cancel the event, sorry if I sound stupid asking this but I’m not a scripter and I still learning

Hello, what is the point of this event if we cant get source from this? (to get the player that created the entity) in the explosion event we can get source, position and much more and here i tried to get source and no success

NetworkGetEntityOwner?

6 Likes

This is great, but you should also do something for the spawning props. Simply hackers will spawned an blimp in your head and it will explode and will no longer be detected by this. It would be perfect to have a list of BL objects and if someone uses the CreateObject Or the AtachToEntity Any of these objects, Notify an administrator or get kicked

how to fix weapon damage with onesync ?
like shotgun weapon !
without onesync all i need to kill some one it 1 bullet
with onesync i need more than 4 bullet to kill some one

how to fix this issue ?

2 Likes