Jump to content

[HELP] Destruir elemento depois de um tempo.


Recommended Posts

Quando utilizo:

function aoSair(player)

	outputChatBox("| AVISO | você tem 30 segundos para voltar ao veículo.", player, 255,255,255, true)

	setTimer (function ( )

		destroyElement(source)

	end, 30000, 1)


end
addEventHandler("onVehicleExit", getRootElement(), aoSair)

o veículo não se destrói.

Erro: Expected element at argument 1, got nil. Imagino que o erro aconteça porquê depois do jogador sair, source não é mais veículo, mas não sei como resolver.

 

Outra coisa, estou usando esse método de destruir porque não consigo achar outra opção (sou novato em script).
Queria que o veículo retornasse ao seu lugar padrão depois de 30 segundos:

pegarEmprego = createMarker(1847.2760009766,-1873.8081054688,12.878125, "cylinder", 2, 255,255,255, 100)
ped = createPed(20, 1847.7249755859,-1873.9541015625,13.578125, 90, false)
setElementFrozen(ped, true)

function mule(BVOMule)

 car1 = createVehicle(414, 1780.3957519531,-1889.2502441406,13.38960647583,-0, 0, 268.3544921875)
 car2 = createVehicle(414, 1780.3957519531,-1889.2502441406-5,13.38960647583,-0, 0, 268.3544921875)
 car3 = createVehicle(414, 1780.3957519531,-1889.2502441406-10,13.38960647583,-0, 0, 268.3544921875)

end
addEventHandler("onResourceStart", resourceRoot, mule)

function aoEntrar(player)

	skin = getElementModel(player)
	gEM = getElementModel(source)

	if ( gEM == 414 ) then
		if skin == 20 then
			if getElementData(player, "Entregador") then

	else

	outputChatBox("| SERVIÇO | você precisa estar com a skin.", player)
	cancelEvent()

	end
	else

end
end
end
addEventHandler( "onVehicleStartEnter", getRootElement(), aoEntrar )

function msgEmprego(hitElement)

		if getElementType(hitElement) == "player" then
			if getElementData(hitElement, "Entregador") == false then

				outputChatBox("#ffffff| EMPREGO | digite #ff0000/conversar #ffffffpara conversar com o entregador.", hitElement, 255,255,25, true)

			end
		end
	end
addEventHandler("onMarkerHit", pegarEmprego, msgEmprego)

function aoSair(player)

	outputChatBox("| AVISO | você tem 30 segundos para voltar ao veículo.", player, 255,255,255, true)

	setTimer (function ( )

		destroyElement(source)

	end, 1000, 1)


end
addEventHandler("onVehicleExit", getRootElement(), aoSair)

function conversarComEntregador(playerSource)


	if isElementWithinMarker(playerSource, pegarEmprego) then
		if getElementModel(playerSource) == 20 then
			outputChatBox("#ffffffENTREGADOR: você já está com a roupa de entregador, pode trabalhar.", playerSource, 255,255,255, true)
		else
			outputChatBox("#ffffffENTREGADOR: lhe dei a roupa de entregador, pode ir trabalhar.", playerSource, 255,255,255, true)
			setPlayerSkin(playerSource, 20)
			setElementData(playerSource, "Entregador", true)
end
end
end
addCommandHandler("conversar", conversarComEntregador)



 

Link to comment
  • Other Languages Moderators

Sobre o primeiro problema:

source deixa de existir dentro de uma função de setTimer. Para evitar isso, você precisa passar o source como parâmetro de função no setTimer.

setTimer (function (theSource) -- theSource = source que foi passado como parâmetro.
	destroyElement (theSource)
end, 30000, 1, source) -- Passa o source como parâmetro de função do setTimer.

Sobre o segundo problema:

Para respawnar um veículo, você pode simplesmente definir a posição de respawn dele com setVehicleRespawnPosition e depois respawná-lo com respawnVehicle.

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