Jump to content

Bad argument @ 'destroyElement'


Recommended Posts

Posted

server.lua:73: Bad argument @ 'destroyElement' [Expected element at argument 1]

function showPanel(thePlayer)
  accountname = getAccountName(getPlayerAccount(thePlayer))
  if isObjectInACLGroup("user." .. accountname, aclGetGroup("Painel-R7")) then
    triggerClientEvent(thePlayer, "R7", getRootElement())
   else
  end
end
function onResStart()
  for index, player in ipairs(getElementsByType("player")) do
    bindKey(player, "z", "down", showPanel)
  end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onResStart)
function onPlayerJoin()
  bindKey(source, "z", "down", showPanel)
end
addEventHandler("onPlayerJoin", getRootElement(), onPlayerJoin)
function cleanAll(player)
  for index, player in ipairs(getElementsByType("player")) do
    unbindKey(player, "z", "down", showPanel)
  end
end
addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), cleanAll)

veh = {}
function criarxx()
    if veh[source] and isElement( veh[source] ) then destroyElement( veh[source] ) 
 veh[source] = nil 
 end
    local x,y,z = getElementPosition(source)
    veh[source] = createVehicle(579, x,y,z + 2)
 warpPedIntoVehicle (source,veh[source])
end
addEvent("carror7",true)
addEventHandler("carror7",root,criarxx)

function arm ()
     giveWeapon( source, 24, 9999, true )
	 giveWeapon( source, 8, 9999, true )
	 giveWeapon( source, 27, 9999, true )
	 giveWeapon( source, 31, 9999, true )
	 giveWeapon( source, 29, 50, true )
	 giveWeapon( source, 33, 9999, true )
end
addEvent("armar7",true)
addEventHandler ( "armar7", getRootElement(), arm )

function arm2 ()
	 giveWeapon( source, 4, 9999, true )
	 giveWeapon( source, 22, 9999, true )
	 giveWeapon( source, 26, 9999, true )
	 giveWeapon( source, 32, 9999, true )
	 giveWeapon( source, 31, 9999, true )
	 giveWeapon( source, 34, 9999, true )
	 giveWeapon( source, 46, 1, true )
end
addEvent("armar72",true)
addEventHandler ( "armar72", getRootElement(), arm2 )

function skin ()
     setPedSkin ( source, 106 )
end
addEvent("skinsr7",true)
addEventHandler ( "skinsr7", getRootElement(), skin )

function skin2 ()
     setPedSkin ( source, 58 )
end
addEvent("skinsr72",true)
addEventHandler ( "skinsr72", getRootElement(), skin2 )

function destrui ()
destroyElement ( veh[source] )
end
addEvent ("destroir7", true)
addEventHandler ("destroir7", getRootElement(), destrui)
addEventHandler ("onPlayerLogout", root, destrui)
addEventHandler ("onPlayerQuit", root, destrui)
addEventHandler ("onPlayerWasted", root, destrui)

function vidacoleter7 ()
	 setPedArmor ( source, 100 )
	 setElementHealth( source, 200 )
end
addEvent("vidaecoleter7",true)
addEventHandler ( "vidaecoleter7", getRootElement(), vidacoleter7 )

 

Posted
function destrui ()
	if veh[source] and isElement(veh[source]) then -- verifica se o elemento existe na tabela
		destroyElement ( veh[source] )
	end
end

 

  • Like 2

Please do not PM me with scripting related question nor support, use the forums instead.

  • Moderators
Posted
13 hours ago, DNL291 said:

function destrui ()
	if veh[source] and isElement(veh[source]) then -- verifica se o elemento existe na tabela
		destroyElement ( veh[source] )
	end
end

 

Recomenda-se anular a variável após destruir o elemento dela. Para desocupar o espaço na memória.

function destrui ()
	if veh[source] and isElement(veh[source]) then
		destroyElement ( veh[source] )
		veh[source] = nil
	end
end

 

  • Thanks 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
6 hours ago, Lord Henry said:

Recomenda-se anular a variável após destruir o elemento dela. Para desocupar o espaço na memória.


function destrui ()
	if veh[source] and isElement(veh[source]) then
		destroyElement ( veh[source] )
		veh[source] = nil
	end
end

 

Exatamente. Tinha esquecido de colocar no código.

Please do not PM me with scripting related question nor support, use the forums instead.

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...