I was wondering how to use this snippet, OneSync: intercepting game events (such as explosions) I have onesync and we desperatly need to block explosions because of modders and because our gas stations randomly explode.
Simply have a list of explosions you want to block (https://runtime.fivem.net/doc/natives/#_0xE3AD2BDBAEE269AC) and check if a blocked explosion is being created.
You can get fancy with it by also checking the damage scale, if it’s visible, audible etc. (See ev
variable)
I use it like so
local BlockedExplosions = {1, 2, 4, 5, 25, 32, 33, 35, 36, 37, 38}
AddEventHandler(
"explosionEvent",
function(sender, ev)
for _, v in ipairs(BlockedExplosions) do
if ev.explosionType == v then
CancelEvent()
-- ban the creator or so but be careful. always check owner id in some other ways to confirm he's cheating
return
end
end
end
)
If you want to block all explosions, just use the snippet on the cookbook
Can you explain check owner id and ban? I blocked all explosions but didn’t know who send that event.
If you have a quick look at the cookbook post, it has some great information. Here is a quick snippet from the post:
AddEventHandler('explosionEvent', function(sender, ev)
print(GetPlayerName(sender), json.encode(ev))
end)
The cookbook post can be found here. You can use “sender” to identify the player.
Yes I read. Currently this is my code. It just prevent explosionEvent but don’t really know who send that event. Because there are a lot normal player (not hack) sent that event too. That why I’m asking how to check owner id is cheat/hack
AddEventHandler('explosionEvent', function(sender, ev)
print(GetPlayerName(sender), json.encode(ev))
if ev.ownerNetId == 0 then
CancelEvent()
end
if ev.posX == 0.0 and ev.posY == 0.0 then
CancelEvent()
end
end)
What snippet? And what lua? server or client?
This link can help you https://cookbook.fivem.net/2019/08/19/onesync-intercepting-game-events-such-as-explosions/
explosionEvent is marked as an server event-side, just look on the link.
You don’t understand what i am asking. I mean, Where does that code go? Do i need to implement into a script and add some more code or should it be ready to go?
It’s code for server side. Add it wherever you want and manipulate the data you get (sender
and ev
table) however you want. It’s up to you how you want to handle explosions.
You can do many things; disabling all explosions, just certain types, only ones that have a high damage scale, only ones that are invisible, only in a certain area and so on.
I don’t understand what local BlockedExplosions means = {1, 2, 4, 5, 25, 32, 33, 35, 36, 37, 38}
Where did you get these numbers?
Can you explain quickly or tell us which number corresponds to which?
Thank you.
They are from the enum that are in the native description (see link in my first post). It’s not very complete though, but the ones I listed are most explosions you don’t want on a roleplay server. Things like rocket launcher explosions, grenade, tank shells etc.
On my side the explosions still work.
I don’t understand how this should work.
I have put in this form :
client.lua (2.0 KB) server.lua (384 Bytes) __resource.lua (146 Bytes)
Dont try to ban the cheater there is a cheat outside that changes the source …
hey i try this and its doesnt work for me can you help me?
It only blocks the explosion for other clients. It definitely does work. Damage might go through, that’s unavoidable.
can you send me the code in lua file and the resource or what ever i need that it will work pls?
It’s literally here lol [Help] Disabling Explosions
If you don’t know how to create a resource, then you should really read about that https://docs.fivem.net/docs/scripting-manual/introduction/
ok thx
its should be server.lua or client.lua?
and do you have discord or somthing i can be in contact with you if i got stuck?
You listen for onesync server explosions server side.