Jump to content

isElementWithinMarker


Recommended Posts

Estou desenvolvendo um resource de assalto a lojinha que utiliza tabelas para criar os markers que vão dentro das lojinhas, porém me deparei com um problema no desenvolvimento, ao usar o isElementWithinMarker ele só me permite assaltar no último marker criado, tentei resolver isso de diversas formas mas todas obtive o mesmo problema :( 

--< server-side >
function startAssaltoGF(source)
    if isElement(source) then 
        if estaNoMarkerGF(source) == true then 
            if isGuestAccount(getPlayerAccount(source)) then 
                outputChatBox("#cd4747[ERRO]:#ffffffVocê deve estar logado para assaltar uma loja", source, 255, 255, 255, true)
            else 
                outputChatBox("#cd4747[INFO]:#ffffffIniciando assalto.", source, 255, 255, 255, true)
                setPedAnimation(source, "bomber", "bom_plant", -1, true, false, true)
                toggleAllControls(source, false)
                setTimer(
                    function() 
                        givePlayerMoney(source, 1000) 
                        outputChatBox("Você recebeu o dinheiro", source, 255, 255, 255, true)
                        toggleAllControls(source, true)
                        setPedAnimation(source, nil)
                    end, 10000, 1)
            end
        end 
    end 
end

local marker = {}

for i, v in ipairs(configLojinhaGF.pos) do 
marker[i] = createMarker(v[1], v[2], v[3]-1, "cylinder", 1.5, 255, 0, 0, 50)
    addEventHandler("onMarkerHit", marker[i], mostrarAssaltoGF)
    addEventHandler("onMarkerLeave", marker[i], tirarAssaltoGF)

    function estaNoMarkerGF(element)
        if isElement(element) then 
            if isElementWithinMarker(element, marker[i]) then 
                return true 
            else 
                return false 
            end 
        end 
    end
end
  
--< shared-side/config>
configLojinhaGF = {
    pos = {
        {-2499.488, -617.549, 132.563},
        {-2499.318, -612.605, 132.563},
    },

}

obs: já tentei colocar a function do assalto dentro do for com:

isElementWithinMarker(source, marker[i])

porém obtive o mesmo resultado. Desde já obrigado pela atenção! :) 

Link to comment

Não sei se é bug de visualização do fórum, mas você não colocou a função de verificar dentro do loop de criação dos markers não né?

Você precisa fazer um loop em todos os markers da tabela, e se o elemento declarado no parâmetro estiver nesse marker, vai retornar true e parar o loop, se não estiver, ele vai para o próximo marker até acabar, e se acabar sem achar nenhum ele vai retornar false.

function estaNoMarkerGF(element)
  for i, v in pairs(marker) do
    if isElementWithinMarker(element, v) then
      return true
    end
  end
  return false
end

 

Edited by ber
  • 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...