Jump to content

[DUVIDA] Verificação objeto hit marker


Recommended Posts

Boa Noite estou tentando fazer uma verificação que o objeto(caixa) após ele encosta no marker vai destruir ele. So que não estou conseguindo verificar ser realmente a caixa encostou no marker

server-side
 

function Job_Iniciar(thePlayer)
	for i, posicoescaixas in ipairs (posicoes_caixas) do
		if isElement(posicoescaixas) then
		destroyElement (posicoescaixas)
		posicoescaixas = nil
		end
	end
	posicoes_caixas = {
		createObject (1221, 2785.559, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 1.2, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 2.4, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 3.6, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 4.8, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 1.2, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 2.4, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 3.6, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 4.8, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
	}
	if isElement(Caminhao[thePlayer]) and isElement(Empilhadeira[thePlayer]) then
		destroyElement(Caminhao[thePlayer])
		destroyElement(Empilhadeira[thePlayer])
		Empilhadeira[thePlayer] = nil
		Caminhao[thePlayer] = nil
	end
	caixa = createObject (1221, 2785.559, -2408.001, 13.634 -0.1, 0, 0, 180)
	Empilhadeira[thePlayer] = createVehicle(530, 2775.257, -2403.802, 13.792, 0.994, 0.046, 1.751)
	attachElements( caixa, Empilhadeira[thePlayer], 0, 0.6, 0.4)
	Caminhao[thePlayer] = createVehicle(456, 2768.087, -2418.615, 14.032, 0.224, -0.256, 98.052)
	Marker_Descarregar = createMarker (2773.011, -2417.931, 13.657 -1, "cylinder", 1.9, 20, 70, 230, 180)
	addEventHandler("onMarkerHit", Marker_Descarregar, Job_Descarregar)
end
addEventHandler("onMarkerHit", Job_Marker, Job_Iniciar)

function Job_Descarregar(source)
	if getElementType(source) == "object" then
		outputChatBox("Teste", source, 255, 255, 255, true)
	end
end

 

Link to comment
  • Moderators

Poderia explicar como o script funciona? Há um loop na tabela 'posicoes_caixas' antes da tabela ser definida. Também seria melhor definir a tabela fora da função e preferencialmente fazer o script client-side.

Se tiver se referindo ao object da variável 'caixa', você pode criar a função do "onMarkerHit" dentro da própria função e depois só verificar o hitElement com a referência da variável.

Link to comment

O Script é um emprego de carregador que você tem que pegar a caixa com a empilhadeira e leva ate o caminhão. O loop das "posicoes_caixas" é as caixas que é criada após o script iniciar, digamos que vai mostrar a onde o jogador deve para pegar a caixa.

Sim estou referindo ao object da variável caixa.

Link to comment
  • Moderators

Entendi, acho que assim deve funcionar:

function Job_Iniciar(thePlayer)
    if posicoes_caixas and type(posicoes_caixas) == "table" then -- verificar antes se existe a tabela
    	for i, posicoescaixas in ipairs (posicoes_caixas) do
	    	if isElement(posicoescaixas) then
		        destroyElement (posicoescaixas)
                posicoescaixas = nil
            end
        end
    end
	posicoes_caixas = {
		createObject (1221, 2785.559, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 1.2, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 2.4, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 3.6, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 4.8, -2408.001, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 1.2, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 2.4, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 3.6, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
		createObject (1221, 2785.559 + 4.8, -2408.001 - 20, 13.634 -0.4, 0, 0, 180),
	}
	if isElement(Caminhao[thePlayer]) and isElement(Empilhadeira[thePlayer]) then
		destroyElement(Caminhao[thePlayer])
		destroyElement(Empilhadeira[thePlayer])
		Empilhadeira[thePlayer] = nil
		Caminhao[thePlayer] = nil
	end
	local caixa = createObject (1221, 2785.559, -2408.001, 13.634 -0.1, 0, 0, 180)
	Empilhadeira[thePlayer] = createVehicle(530, 2775.257, -2403.802, 13.792, 0.994, 0.046, 1.751)
	attachElements( caixa, Empilhadeira[thePlayer], 0, 0.6, 0.4)
	Caminhao[thePlayer] = createVehicle(456, 2768.087, -2418.615, 14.032, 0.224, -0.256, 98.052)
    Marker_Descarregar = createMarker (2773.011, -2417.931, 13.657 -1, "cylinder", 1.9, 20, 70, 230, 180)
    
    addEventHandler( "onMarkerHit", Marker_Descarregar, 
        function ( hitElement )
            if hitElement == caixa then
                -- código
            end
        end
    )
end
addEventHandler("onMarkerHit", Job_Marker, Job_Iniciar)

Edit: Deixe o script client-side, vai evitar conflito com outros player do server e sobrecarrega menos o servidor por fazer no cliente.

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