Jump to content

[HELP]Molotov


erisP

Recommended Posts

addEventHandler("onClientVehicleDamage", root, function()
if source == getPedOccupiedVehicle(localPlayer) then
local x,y,z = getElementPosition(localPlayer)
extinguishFire(x,y,z, 30)
end
end)

i did but the game crashes

 

How do I prevent the vehicle from being damaged when Molotov is thrown at the vehicle?

Link to comment
  • Moderators

Use onClientExplosion: https://wiki.multitheftauto.com/wiki/OnClientExplosion

And then clear the fires for 2 frames at minimal.

 

For the 2e frame, use the callNextFrame function.

(tableRemove variable)

https://gitlab.com/IIYAMA12/mta-communication-enchantment/-/blob/master/sync/sync_shared.lua#L46

(The function scope)

https://gitlab.com/IIYAMA12/mta-communication-enchantment/-/blob/master/sync/sync_shared.lua#L424

  • Like 1
Link to comment
12 minutes ago, IIYAMA said:

Use onClientExplosion: https://wiki.multitheftauto.com/wiki/OnClientExplosion

And then clear the fires for 2 frames at minimal.

 

For the 2e frame, use the callNextFrame function.

(tableRemove variable)

https://gitlab.com/IIYAMA12/mta-communication-enchantment/-/blob/master/sync/sync_shared.lua#L46

(The function scope)

https://gitlab.com/IIYAMA12/mta-communication-enchantment/-/blob/master/sync/sync_shared.lua#L424

I have no idea how to do what you say

Link to comment

Hello erisP,

have you tried calling the cancelEvent function inside of the onClientVehicleDamage event handler? You should check that the "theWeapon" parameter is the ID 37 which is the damage type ID for burning damage.

1 hour ago, erisP said:

i did but the game crashes

This is very interesting. What did you do to make the game crash? Have you simply spawned the Infernus vehicle and thrown a molotov at it?

  • Thanks 1
Link to comment
27 minutes ago, The_GTA said:

Merhaba erisP,

onClientVehicleDamage olay işleyicisinin içindeki CancellEvent işlevini çağırmayı denediniz mi? "TheWeapon" parametresinin, yakma hasarı için hasar tipi kimliği olan ID 37 olup olmadığını kontrol etmelisiniz.

Bu çok ilginç. Oyunun çökmesi için ne yaptın? Infernus aracını üretip ona molotof mu fırlattınız?

what i actually want to do I want to light and extinguish tool like setPedOnFire function but this function is not working in tool

34 minutes ago, The_GTA said:

 

This is very interesting. What did you do to make the game crash? Have you simply spawned the Infernus vehicle and thrown a molotov at it?

Try it if you wish, when you throw a Molotov at the player inside the vehicle, the player's game crashes.

Link to comment
5 minutes ago, erisP said:

what i actually want to do I want to light and extinguish tool like setPedOnFire function but this function is not working in tool

I don't understand the conflict situation that you describe.

  • do you want help to solve this setPedOnFire issue?
  • in what situation is the function not working?
  • what is that tool you are mentioning? does it have any kind of public name? is it your own tool?
Link to comment
1 saat önce erisP dedi ki:

addEventHandler("onClientVehicleDamage", root, function()
eğer kaynak == getPedOccupiedVehicle(localPlayer) ise
yerel x,y,z = getElementPosition(localPlayer) abuseFire
(x,y,z, 30)
end
end)

yaptım ama oyun kapanıyor

bunu yaptım ama oyun çöküyor nasıl düzgün çalıştırabilirim bu kodun düzgün çalışmasını istiyorum

for you to understand better;

https://github.com/multitheftauto/mtasa-blue/issues/1757

Edited by erisP
  • Like 1
Link to comment
14 minutes ago, erisP said:

for you to understand better;

Thank you for bringing up that MTA GitHub issue! It even looks like that code is equal to the one you posted, making me believe that you could be the same person. But I think that you should continue the correspondence inside of that GitHub issue because you insist on the crashfix. The crash seems to happen inside of GTA_SA.EXE executable space but I don't have the time to investigate at the moment.

Link to comment
  • Moderators
2 hours ago, erisP said:

I have no idea how to do what you say

For example (raw version without a lot of checks):

function onClientExplosion(x, y, z, theType)
	local vehicle = getPedOccupiedVehicle(localPlayer) 
	if vehicle then
		local x,y,z = getElementPosition(vehicle)
		extinguishFire(x, y, z, 30)
		callNextFrame(extinguishFire, x, y, z, 30)
	end
end
addEventHandler("onClientExplosion", root, onClientExplosion)

callNextFrame source code:

Spoiler

 

do
	local tableRemove = table.remove
  	local serverSide = triggerClientEvent and true or false
	
	local nextFrameCalls = {}
	
	local serverSideTimer
	

	local processing = false
	
	local function process ()
		
		--[[ 
			Do an empty check at the beginning of the function, this will make sure to make an extra run in case of heavy work load. 
			If the timer is killed or the addEventHandler is removed, then this has to be re-attached again every frame. This is not very healthy...
		]]
		
		if #nextFrameCalls == 0 then
			if serverSide then
				if serverSideTimer then
					
					if isTimer(serverSideTimer) then
						killTimer(serverSideTimer)
					end
					serverSideTimer = nil
					
				end
			else
				removeEventHandler("onClientRender", root, process)
			end
			
			processing = false
			return
		end
		
		
		-- In case of calling the function callNextFrame within the process, the loop type `repeat until` is required.
		repeat
			local item = nextFrameCalls[1]
			item.callback(unpack(item.content))
			tableRemove(nextFrameCalls, 1)
		until #nextFrameCalls == 0

	end
	
	
	
	function callNextFrame (callback, ...)
		if type(callback) == "function" then
			local newIndex = #nextFrameCalls + 1
			nextFrameCalls[newIndex] = {callback = callback, content = {...}}
			if not processing then
				if serverSide then
					serverSideTimer = setTimer(process, 50, 0)
				else
					addEventHandler("onClientRender", root, process)
				end
				processing = true
			end
			return true
		end
		return false
	end
end

 

 

Link to comment
  • Moderators
38 minutes ago, IIYAMA said:

I believe you for some unknown reason haha

Oh you are confused.

If you say first that you haven't tested something and also come to the conclusion that it is doesn't work. How do you come to that conclusion then?

At that moment I am a 1000x more confused than you are.

  • Thanks 1
  • Haha 1
Link to comment
12 minutes ago, IIYAMA said:

Oh you are confused.

If you say first that you haven't tested something and also come to the conclusion that it is doesn't work. How do you come to that conclusion then?

At that moment I am a 1000x more confused than you are.

sorry for the confusion what you said gave me a new idea and solved my problem thanks

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...