WeeD1 Posted July 28, 2019 Posted July 28, 2019 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)
Other Languages Moderators Lord Henry Posted July 28, 2019 Other Languages Moderators Posted July 28, 2019 (edited) 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 July 28, 2019 by Lord Henry 1
WeeD1 Posted July 28, 2019 Author Posted July 28, 2019 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.
DNL291 Posted July 28, 2019 Posted July 28, 2019 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. 1
WeeD1 Posted July 28, 2019 Author Posted July 28, 2019 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)
[M]ister Posted July 28, 2019 Posted July 28, 2019 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) 1
[M]ister Posted July 28, 2019 Posted July 28, 2019 Acabei de testar aqui e funcionou... mas notei que a altura que você definiu para o colshape está muito pequena (1), e com isso não estava detectando os elementos, só aumentar um pouco que provavelmente funcionará. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now