Jump to content

[HELP] Question about object destroying


Maruchan

Recommended Posts

Hello guys, how are you? I have a problem destroying the campfire, the wood is destroyed but I can't make the fire disappear. 
They could help me, I have tried but I do not understand how to solve it  :c
		 usedFires = {}
		 usedFireTimers = {}

function onPlayerMakeAFire(itemName)

		 setElementData(source,"Madera",getElementData(source,"Madera")-1)
		 local x,y,z = getElementPosition(source)
		 local xr,yr,zr = getElementRotation(source)
		 px, py, pz = getElementPosition(source)
		 prot = getPedRotation(source)
		 local offsetRot = math.rad(prot+90)
		 local vx = px + 1 * math.cos(offsetRot)
		 local vy = py + 1 * math.sin(offsetRot)
		 local vz = pz + 2
		 local vrot = prot+90
		 local wood = createObject(1463,vx,vy,pz-0.75,xr,yr,vrot)
		 usedFires[wood] = {}
		 setObjectScale(wood,0.55)
		 setElementCollisionsEnabled(wood, false)
		 setElementFrozen (wood,true)
		 local fire = createObject(3525,vx,vy,pz-0.75,xr,yr,vrot)
		 setObjectScale(fire,0)
		 local fireCol = createColSphere(x,y,z,2)
		 local fireColFar = createColSphere(x,y,z,10)
		 if usedFireTimers[source] and isTimer ( usedFireTimers[source][1] ) then
		 killTimer ( usedFireTimers[source][1] )
		 end
		 usedFireTimers[source] = { setTimer (checkPlayerNearFire,5000,1,source), fireColFar }
		 addEventHandler ( "onColShapeHit", fireColFar, fireColFarHit )
		 setElementData(fireCol,"parent",wood)
	     setElementData(wood,"parent",fireCol)
		 setElementData(fireCol,"Cocinar",true)
		 setPedWeaponSlot(source, 0)
		 fireX,fireY,fireZ = getElementPosition(fire)
		 triggerClientEvent(source,"FogataEncendida",source,fireX,fireY,fireZ)
		 triggerClientEvent(source,"refreshInventoryManual",source)
		 setPedAnimation (source,"BOMBER","BOM_Plant", -1, false, false, false, false)
		 setTimer(function()
		 destroyElement(fireCol)
		 destroyElement(fireColFar)
		 destroyElement(fire)
		 destroyElement(wood)
		 triggerClientEvent(source,"FogataApagada",source)
		 end,720000,1)
		 end
addEvent("onPlayerMakeAFire",true)
addEventHandler("onPlayerMakeAFire",getRootElement(),onPlayerMakeAFire)

function DestruirFogata(col)
		 wood = getElementData(col,'parent')
		 --
		 if wood and isElement(wood) then 
		 destroyElement(wood)
		 end
		 -- 
		 setPedAnimation (source,"BOMBER","BOM_Plant", -1, false, false, false, false)
end
addEvent("Destruir_Fogata", true)
addEventHandler("Destruir_Fogata", root, DestruirFogata)

 

Link to comment
  • Moderators
3 hours ago, Maruchan said:

I can't make the fire disappear.

Place the following line

setElementParent(fire, wood)

between:

setPedAnimation (source,"BOMBER","BOM_Plant", -1, false, false, false, false)
-- <
setTimer(function()

 

When destroyElement(wood) is called, propagation is applied and the same function will be executed for it's children. Which is in this case the fire element.

 

  • Thanks 1
Link to comment
6 hours ago, IIYAMA said:

Place the following line


setElementParent(fire, wood)

between:


setPedAnimation (source,"BOMBER","BOM_Plant", -1, false, false, false, false)
-- <
setTimer(function()

 

When destroyElement(wood) is called, propagation is applied and the same function will be executed for it's children. Which is in this case the fire element.

 

But this: setElementParent(fire, wood) -  is not the same as this: setElementData(fireCol,"parent",wood) ?????

Link to comment
  • Moderators
19 minutes ago, Maruchan said:

But this: setElementParent(fire, wood) -  is not the same as this: setElementData(fireCol,"parent",wood) ?????

That is correct, it is not the same.

  • setElementData does not modify the parent<>child relationship. It only makes a reference between the 2.
     
  • setElementParent does modify the parent<>child relationship:
  • Tre.png
  • And therefore you can use call-propagation. Using the destroyElement function on the parent will also apply the function on it's children.
  • Thanks 1
Link to comment
  • Patrick changed the title to [HELP] Question about object destroying
I really appreciate you, I have one last little thing that I can't fix. Is it possible to add a font to this? 
I have tried it this way but it doesn't work:
         gridlistItems["loot_colum"] = guiGridListAddColumn(gridlistItems["loot"],"LOOT",0.7)
         gridlistItems["loot_colum_amount"] = guiGridListAddColumn(gridlistItems["loot"],"",0.2)
	 	 guiSetFont(gridlistItems["loot_colum"],Fuente)

 

Edited by Maruchan
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...