Jump to content

Mover a função para outra dimensão


Recommended Posts

Opa gente! Estou com um problema, alguém consegue me ajudar? Seguinte, quero mover o script para funcionar apenas na dimensão 100. Já testei algumas formas e nenhuma funcionou, alguém poderia me ajudar por favor?

script server-side

local vZones = {
    {x = 190, y = -489, z = 980, width = 65, depth = 60, height = 1},
}

local z = {}
function initvZones()
if ( getElementDimension ( source ) == 100 ) then    --- Tentativa
    if vZones and #vZones ~= 0 then
        for _,v in ipairs (vZones) do
            if v then
                if v.x and v.y and v.z and v.width and v.depth and v.height then
                    local c = createColCuboid (v.x, v.y, v.z, v.width, v.depth, v.height)
                    if c then
                        z[c] = true
                        for _,v in ipairs (getElementsByType("player")) do
                            if isElementWithinColShape (v, c) then
                                killPed (v)
                            end
                        end
                        addEventHandler ("onElementDestroy", c,
                            function()
                                if z[source] then
                                    z[source] = nil
                                end
                            end
                        )
                        addEventHandler ("onColShapeHit", c,
                            function (h, d)
                                if h and d and isElement(h) and getElementType (h) == "player" then
                                killPed (h)
                                end
                            end
                        )
                    end
                end
            end
        end
    end
end
end
addEventHandler ("onResourceStart", resourceRoot, initvZones)

 

Link to comment
  • Other Languages Moderators

source não é o jogador no evento onResourceStart. Preste atenção na Wiki.

local vZones = {
	{x = 190, y = -489, z = 980, width = 65, depth = 60, height = 1},
}

local z = {}
function initvZones()
	if vZones and #vZones ~= 0 then
		for _,v in ipairs (vZones) do
			if v then
				if v.x and v.y and v.z and v.width and v.depth and v.height then
					local c = createColCuboid (v.x, v.y, v.z, v.width, v.depth, v.height)
					if c then
						z[c] = true
						for _,thePlayer in ipairs (getElementsByType("player")) do
							if (getElementDimension (thePlayer) == 100) then -- Tentativa de verdade.
								if isElementWithinColShape (thePlayer, c) then
									killPed (thePlayer)
								end
							end
							addEventHandler ("onElementDestroy", c, function() -- Não recomendo fazer isso dentro de loops.
								if z[source] then
									z[source] = nil
								end
							end)
							addEventHandler ("onColShapeHit", c, function (h, d) -- Prefira usar nomes fáceis de identificar em vez de letras.
								if h and isElement(h) and getElementType (h) == "player" then
									killPed (h)
								end
							end)
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onResourceStart", resourceRoot, initvZones)

 

Edited by Lord Henry
  • Thanks 1
Link to comment

Obrigado. E no caso se o elemento for um veículo, no lugar do thePlayer, usaria "Vehicle" ?

Desculpa a pergunta, estou aprendendo, dei uma olhada na página de elementos do OnResouceStart e queria ver algo relacionado aos veículos.

Link to comment
  • Moderators

Sim, getElementsByType("vehicle") vai funcionar da mesma forma, basta iterar a tabela de todos veículos retornada e o valor será o elemento-veículo assim como está no loop dos players.

O evento "onResourceStart" não têm nada a ver com isso, ele só está sendo chamado internamente quando o resource é ligado e não fornece nenhum parâmetro ou "elementos" para isso.

  • Thanks 1
Link to comment

Bom, testei aqui e não funcionou comigo. Poderia me dizer onde estou errando?

local vZones = {
    {x = 190, y = -489, z = 980, width = 65, depth = 60, height = 1},
}

local z = {}
function initvZones()
    if vZones and #vZones ~= 0 then
        for _,v in ipairs (vZones) do
            if v then
                if v.x and v.y and v.z and v.width and v.depth and v.height then
                    local c = createColCuboid (v.x, v.y, v.z, v.width, v.depth, v.height)
                    if c then
                        z[c] = true
                        for _,thePlayer in ipairs (getElementsByType("vehicle")) do
                            if (getElementDimension (thePlayer) == 100) then
                                if isElementWithinColShape (thePlayer, c) then
                                    destroyElement(thePlayer)
                                end
                            end
                            addEventHandler ("onElementDestroy", c, function()
                                if z[source] then
                                    z[source] = nil
                                end
                            end)
                            addEventHandler ("onColShapeHit", c, function (h, d)
                                if h and isElement(h) and getElementType (h) == "vehicle" then
                                    destroyElement (h)
                                end
                            end)
                        end
                    end
                end
            end
        end
    end
end
addEventHandler ("onResourceStart", resourceRoot, initvZones)

 

Link to comment

Tente:

local vZones = {
	{x = 190, y = -489, z = 980, width = 65, depth = 60, height = 1},
}

local z = {}
function initvZones()
	if vZones and #vZones ~= 0 then
		for _,v in ipairs (vZones) do
			if v then
				if v.x and v.y and v.z and v.width and v.depth and v.height then
					local c = createColCuboid (v.x, v.y, v.z, v.width, v.depth, v.height)
					setElementDimension(c,100)
					if c then
						z[c] = true
						for _,veh in ipairs (getElementsByType("vehicle")) do
							if (getElementDimension (veh) == 100) then
								if isElementWithinColShape (veh, c) then
									destroyElement(veh)
								end
							end
						end
						addEventHandler ("onElementDestroy", c, function()
							if z[source] then
								z[source] = nil
							end
						end)
						addEventHandler ("onColShapeHit", c, function (h, d)
							if h and isElement(h) and getElementType (h) == "vehicle" and d then
								destroyElement(h)
							end
						end)
					end
				end
			end
		end
	end
end
addEventHandler ("onResourceStart", resourceRoot, initvZones)

 

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