Jump to content

[HELP] getAttachedElements / destroyElement


India

Recommended Posts

Hello, I get this warning's when i bury up zombies in DayZ game mode

Bad argument @'getAttachedElements' [Expected element at argument 1]

Bad argument @'destroyElement' [Expected element at argument 1]

function respawnZombieInTime ( zomb, immediatly )
	if exports.npc_hlc:isHLCEnabled ( zomb ) then
		exports.npc_hlc:disableHLCForNPC (zomb)
	end
	--if isElement ( getElementData ( zomb, "zombieShape" ) ) then destroyElement ( getElementData ( zomb, "zombieShape" ) ) end
	--if isElement ( getElementData ( zomb, "shapeFar" ) ) then destroyElement ( getElementData ( zomb, "shapeFar" ) ) end
	local resptimer = timeToRespawnZombie
	if immediatly then
		resptimer = 20000
	end
	setTimer ( function ( shape )
		local attaches = getAttachedElements ( zomb,1)
		if attaches then
			for ElementKey, ElementValue in ipairs ( attaches ) do
				if isElement ( ElementValue ) then
					destroyElement ( ElementValue )
				end
			end
		end
		destroyElement ( zomb,1)
		aliveZ = aliveZ - 1 
		if isElement ( shape ) then
			setElementData ( shape, "zSpawned", false )
			setElementData ( shape, "zombie", false )
		end
	end,resptimer, 1, getElementData ( zomb, "spawnShape" ) )
	--setElementData ( root, 'zombiesalive', getElementData ( root, 'zombiesalive' )-1 )
end

 

Link to comment
	setTimer ( function ( shape, zomb )
		local attaches = getAttachedElements ( zomb,1)
		if attaches then
			for ElementKey, ElementValue in ipairs ( attaches ) do
				if isElement ( ElementValue ) then
					destroyElement ( ElementValue )
				end
			end
		end
		destroyElement ( zomb,1)
		aliveZ = aliveZ - 1 
		if isElement ( shape ) then
			setElementData ( shape, "zSpawned", false )
			setElementData ( shape, "zombie", false )
		end
	end,resptimer, 1, getElementData ( zomb, "spawnShape" ), zomb )

 

Link to comment
1 hour ago, SpecT said:

	setTimer ( function ( shape, zomb )
		local attaches = getAttachedElements ( zomb,1)
		if attaches then
			for ElementKey, ElementValue in ipairs ( attaches ) do
				if isElement ( ElementValue ) then
					destroyElement ( ElementValue )
				end
			end
		end
		destroyElement ( zomb,1)
		aliveZ = aliveZ - 1 
		if isElement ( shape ) then
			setElementData ( shape, "zSpawned", false )
			setElementData ( shape, "zombie", false )
		end
	end,resptimer, 1, getElementData ( zomb, "spawnShape" ), zomb )

 

Still same, this lines gives warning;

local attaches = getAttachedElements ( zomb,1)

destroyElement ( zomb,1)

 

Link to comment

Well then the "zomb" element doesn't exist.
To prevent the errors you can put a check if "zomb" is an element in both the timer function and the respawnZombieInTime function and stop the execution of the function with "return".

Something like this:

function respawnZombieInTime ( zomb, immediatly )
	if not isElement(zomb) then
		return
	end
	if exports.npc_hlc:isHLCEnabled ( zomb ) then
		exports.npc_hlc:disableHLCForNPC (zomb)
	end
	--if isElement ( getElementData ( zomb, "zombieShape" ) ) then destroyElement ( getElementData ( zomb, "zombieShape" ) ) end
	--if isElement ( getElementData ( zomb, "shapeFar" ) ) then destroyElement ( getElementData ( zomb, "shapeFar" ) ) end
	local resptimer = timeToRespawnZombie
	if immediatly then
		resptimer = 20000
	end
	setTimer ( function ( shape, zomb )
		if not isElement(zomb) then
			return
		end
		local attaches = getAttachedElements ( zomb,1)
		if attaches then
			for ElementKey, ElementValue in ipairs ( attaches ) do
				if isElement ( ElementValue ) then
					destroyElement ( ElementValue )
				end
			end
		end
		destroyElement ( zomb,1)
		aliveZ = aliveZ - 1 -- this seems to be useless ??
		if isElement ( shape ) then
			setElementData ( shape, "zSpawned", false )
			setElementData ( shape, "zombie", false )
		end
	end,resptimer, 1, getElementData ( zomb, "spawnShape" ), zomb )
	--setElementData ( root, 'zombiesalive', getElementData ( root, 'zombiesalive' )-1 )
end

 

Edited by SpecT
  • Thanks 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...