AddExplosion(x, y, z, 9, 0.9, 1, 0, 1065353216, 0) - Explosions not causing damage?

My exact code is:
AddExplosion(PlayerPos.x+1, PlayerPos.y+5, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)

But when I trigger the explosion, they don’t cause any damage. I tried adding the 9th parameter for enabling damage, and it makes no difference with or without, either way.

Any ideas?

Hello, I just tried this and I get well exploded and die :

local PlayerPos = GetEntityCoords(PlayerPedId())
AddExplosion(PlayerPos.x+1, PlayerPos.y+5, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)

Check in all your scripts if you have a script handling the event explosionEvent and using CancelEvent() on it

		local explosion = false
if explosion then
					local PlayerPos = GetEntityCoords(PlayerPedId(), true)
					AddExplosion(PlayerPos.x+1, PlayerPos.y+5, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
					AddExplosion(PlayerPos.x+4, PlayerPos.y+1, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
					AddExplosion(PlayerPos.x+0.5, PlayerPos.y+1.2, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
					TriggerEvent('chat:addMessage', {
					args = {closetObject .. ' Admin Test (Explosion)'}
					})
				end
		RegisterCommand('+explosion', function()
		explosion = true
		end, false)
		RegisterCommand('-explosion', function()
		explosion = false
		end, false)
		RegisterKeyMapping('+explosion', 'Create Explosion', 'keyboard', 'o')

I have it added to a keybind. What could be the issue?

Something like this :

RegisterCommand('explosion', function()
    local PlayerPos = GetEntityCoords(PlayerPedId(), true)
	AddExplosion(PlayerPos.x+1, PlayerPos.y+5, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
	AddExplosion(PlayerPos.x+4, PlayerPos.y+1, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
	AddExplosion(PlayerPos.x+0.5, PlayerPos.y+1.2, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
end, false)
RegisterKeyMapping('explosion', 'Create Explosion', 'keyboard', 'o')

I haven’t tested this yet, but I’m assuming your method works.

Also, I was wondering where is the documentation for in-game events? Like where did you discovered “explosionEvent”?

It doesn’t seem to be documented in the lost of client/server events.

1 Like

There is this that talk about explosionEvent but I don’t really know if there are much?
https://cookbook.fivem.net/2019/08/19/onesync-intercepting-game-events-such-as-explosions/

I know that there is currently a PR on the github repo which should support all those events Game events - Cfx.re Docs

1 Like

It doesn’t seem very well documented. One has to dig deeply in to the source of FiveM to uncover these events. Also, it looks like OneSync is required.

This looks like it’s being worked on and discussed as we speak actually.

AddEventHandler("CEventShockingGunshotFired"

I’ve noticed in line 2697 of the previously mentioned github link, they return generic event names, like CFireEvent is encoded as fireEvent

struct CFireEvent
{
	void Parse(rl::MessageBuffer& buffer);

	inline std::string GetName()
	{
		return "fireEvent";
	}
}

But on the Pull Request on the github you discovered, it looks like Fortahr wants to submit a new update that will correct the previously mentioned situation.

Fortahr (1 Hour ago)
Previous Emit/React versions merged, event names are now the same as the game event name itself, e.g.: “CEventShockingSeenNiceCar”.

Nice research.

1 Like

I tried your method, and still not taking damage.

That’s strange, are you sure that you have no handler for explosionEvent anywhere ?

I reduced my code to just your example only. I’m using Game build 2189, Not sure if that could be an issue?

I tested it on build 2545 but this should not be related. There has to be something (explosionEvent) blocking explosion damage. Does vehicle explosion, rpg, grenade explosions make damages on your server ?

Yes, every other explosion works fine. I’ve just disabled everything other than my script and it still doesn’t cause damage. Do you think that maybe because my script is a client script e.g. client.lua and not server.lua, that this would be an issue? The only thing in my code is what you suggested to try. That is the only thing I have running. The rest of FiveM is vanilla. I even tried the latest build.

client.lua

RegisterCommand('explosion', function()
    local PlayerPos = GetEntityCoords(PlayerPedId(), true)
	AddExplosion(PlayerPos.x, PlayerPos.y, PlayerPos.z, 9, 0.9, 1, 0, 1065353216, 0)
end, false)
RegisterKeyMapping('explosion', 'Create Explosion', 'keyboard', 'r')

server.cfg

ensure ExplosionScript

Am I missing something?

AddExplosion - FiveM Natives @ Cfx.re Docs is a client side native so this can’t be the issue.

At this point I don’t know :confused:

Maybe somebody else will have an idea :crossed_fingers:

So, when I use
AddOwnedExplosion(player, PlayerPos.x, PlayerPos.y-0.5, PlayerPos.z, 50, 0.9, 1, 0, 1065353216)

It damages and kills my character.

But, AddExplosion(PlayerPos.x, PlayerPos.y-0.5, PlayerPos.z, 50, 0.9, 1, 0, 1065353216, 0)
has no effect.

Hm…

How you got this to work is beyond me, I was reading a different thread and this issue was known / mentioned 7 months ago in June 2021.

I managed to create a work around for it though.

	if Citizen.InvokeNative(0xE3AD2BDBAEE269AC, PlayerPos.x, PlayerPos.y-0.5, PlayerPos.z, 17, 0.9, 1, 0, 0.99, 0) then
		SetPedConfigFlag(player,33,1) -- Sets Flag CPED_CONFIG_FLAG_DieWhenRagdoll if AddExplosion is invoked.
		print(GetPedConfigFlag(player,33)) -- Returns the value of CPED_CONFIG_FLAG_DieWhenRagdoll. 
	end

Oh, well then I have absolutely no idea of why it worked on my side XD

Nice job at finding a workaround anyway

Anyone else reading this thread, if you don’t want the character to die on ragDoll, just make the explosion to reduce health based on the distance to and from the explosion. You can figure it out.

SetEntityHealth(player,playerHealth-100) – Nearly Kills the player

NPCs are affected by it normally.

For other players on the server, it won’t cause damage. So you’ll need to generate a list of the nearest players, and then run that function for each player in the list.

1 Like

https://docs.fivem.net/
look up in here

Yep there’s no other way apparently, it seems that AddExplosion gives no damage in OneSync, unless it’s a AddOwnedExplosion owned by your own ped, most likely to prevent cheaters from exploiting it to kill everyone.