Jump to content

Finalizo a rota mas o marker não aparece


Recommended Posts

Fiz um script de emprego de ifood mas quando eu finalizo a rota ele não reaparece o marker inicial.

OBS: (sei que destruí o elemento mas não sei como volta-lo no final)

 
local MarkerIniciar = createMarker(1198.36206, -1454.21411, 13,"cylinder",1.2,255,255,255,100)
local MarkerFinalizar = createMarker(1197.54395, -1437.23108, 13,"cylinder",1.2,255,255,255,100)

veiculo = {}
function inicio(player)

    local quantidade = exports["[HS]Inventory_system_2"]:getItem(player, 'cafe')
    if  quantidade == 14 then  
        exports["[HS]Notify_System"]:notify(player, 'Você não tem pizzas suficientes', 'error') return end
   
    if veiculo[player] and isElement(veiculo[player]) then destroyElement(veiculo[player])
        veiculo[player] = nil
    end
    veiculo[player] = createVehicle(521, 1216.10876, -1478.08972, 13.54688)
    warpPedIntoVehicle(player, veiculo[player])
    setElementVisibleTo(Marker1, player, true)
    setElementVisibleTo(Blip1, player, true)
    if veiculo[player] and isElement(veiculo[player]) then destroyElement(MarkerIniciar)
    exports["[HS]Notify_System"]:notify(player, 'Vá até o local marcado em seu mapa para fazer sua primeira entrega', 'info')
end
end
addEventHandler("onMarkerHit", MarkerIniciar, inicio)

function fim(player)
    if veiculo[player] and isElement(veiculo[player]) then
        createElement(MarkerIniciar)
        destroyElement(veiculo[player])
        setElementVisibleTo(BlipFinalizar , player, false)
        setElementVisibleTo(MarkerFinalizar , player, false)
        exports["[HS]Notify_System"]:notify(player, 'Você guardou a moto com sucesso e finalizou seu expediente', 'success')
    end
end
addEventHandler("onMarkerHit", MarkerFinalizar, fim)
 
   
Edited by Lord Henry
Código convertido de texto para Lua.
Link to comment
  • Scripting Moderators

Hi,

Your thread has been moved to the Portuguese scripting section so you can get better assistance in your native language.
Make sure to always use English when posting outside this language-specific section!

Link to comment

 

On 26/01/2023 at 17:47, ABR said:

Fiz um script de emprego de ifood mas quando eu finalizo a rota ele não reaparece o marker inicial.

OBS: (sei que destruí o elemento mas não sei como volta-lo no final)

 
local MarkerIniciar = createMarker(1198.36206, -1454.21411, 13,"cylinder",1.2,255,255,255,100)
local MarkerFinalizar = createMarker(1197.54395, -1437.23108, 13,"cylinder",1.2,255,255,255,100)

veiculo = {}
function inicio(player)

    local quantidade = exports["[HS]Inventory_system_2"]:getItem(player, 'cafe')
    if  quantidade == 14 then  
        exports["[HS]Notify_System"]:notify(player, 'Você não tem pizzas suficientes', 'error') return end
   
    if veiculo[player] and isElement(veiculo[player]) then destroyElement(veiculo[player])
        veiculo[player] = nil
    end
    veiculo[player] = createVehicle(521, 1216.10876, -1478.08972, 13.54688)
    warpPedIntoVehicle(player, veiculo[player])
    setElementVisibleTo(Marker1, player, true)
    setElementVisibleTo(Blip1, player, true)
    if veiculo[player] and isElement(veiculo[player]) then destroyElement(MarkerIniciar)
    exports["[HS]Notify_System"]:notify(player, 'Vá até o local marcado em seu mapa para fazer sua primeira entrega', 'info')
end
end
addEventHandler("onMarkerHit", MarkerIniciar, inicio)

function fim(player)
    if veiculo[player] and isElement(veiculo[player]) then
        createElement(MarkerIniciar)
        destroyElement(veiculo[player])
        setElementVisibleTo(BlipFinalizar , player, false)
        setElementVisibleTo(MarkerFinalizar , player, false)
        exports["[HS]Notify_System"]:notify(player, 'Você guardou a moto com sucesso e finalizou seu expediente', 'success')
    end
end
addEventHandler("onMarkerHit", MarkerFinalizar, fim)
 
   

Olá boa noite, o createElement não serve examente para o criar o marker, então aqui crei o marker novamente e coloquei a função dnv agora só encerrar o script...

local MarkerIniciar = createMarker(1198.36206, -1454.21411, 13.383 -1,"cylinder",1.2,255,255,255,100) -- Cria o marker de iniciar
local MarkerFinalizar = createMarker(1197.54395, -1437.23108, 13.383 -1,"cylinder",1.2,255,255,255,100) -- Cria o marker finalizar
setElementVisibleTo(MarkerFinalizar, root, false) -- Oculta o marker pra todo mundo

local veiculo = {} -- Variavel veiculo

function inicio (thePlayer)
    if thePlayer and isElement(thePlayer) and getElementType(thePlayer) == "player" then -- Verifica o elemento the thePlayer
        if not getPedOccupiedVehicle (thePlayer) then -- Se o player não estiver em veiculo, então

            local quantidade = exports["[HS]Inventory_system_2"]:getItem(thePlayer, 'cafe')
            if quantidade == 14 then -- Verificar a quantidade de pizzas
                MensagemDX(thePlayer, 'Você não tem pizzas suficientes', 'error') 
                return 
            end
        
            if veiculo[thePlayer] and isElement(veiculo[thePlayer]) then -- Se o player estiver com a moto, então destrui-la
                destroyElement(veiculo[thePlayer])
                veiculo[thePlayer] = nil
            end

            veiculo[thePlayer] = createVehicle(521, 1194.031, -1454.766, 13.383) -- Cria o veiculo
            warpPedIntoVehicle(thePlayer, veiculo[thePlayer]) -- Coloca o player dentro do veiculo

            if veiculo[thePlayer] and isElement(veiculo[thePlayer]) then -- Verifica se há moto
                if MarkerIniciar and isElement(MarkerIniciar) then -- Verifica se o marker existe
                    destroyElement(MarkerIniciar) -- Destroi o marker de iniciar
                end
                setElementVisibleTo(MarkerFinalizar, thePlayer, true) -- Mostra o marker para o player após pegar a moto
                MensagemDX(thePlayer, 'Vá até o local marcado em seu mapa para fazer sua primeira entrega', 'info')
            end

        else -- Se o player tiver no veiculo, então
            MensagemDX(thePlayer, 'Saia do seu veiculo para pegar outro!', 'info')
        end
    end
end
addEventHandler("onMarkerHit", MarkerIniciar, inicio) -- Adiciona o evento ao ligar o resource

function fim (player)
    if veiculo[player] and isElement(veiculo[player]) then -- Se há moto, então
        destroyElement(veiculo[player]) -- Destroy a moto
        setElementVisibleTo(MarkerFinalizar , player, false) -- Oculta o marker de finalizar para o player

        MarkerIniciar = createMarker(1198.36206, -1454.21411, 13.383 -1,"cylinder", 1.2, 255, 255, 255, 100) -- Cria o marker novamente
        addEventHandler("onMarkerHit", MarkerIniciar, inicio) -- Adiciona o evento da função ao marker

        MensagemDX(player, 'Você guardou a moto com sucesso e finalizou seu expediente', 'success')
    end
end
addEventHandler("onMarkerHit", MarkerFinalizar, fim) -- Adiciona o evento ao ligar o resource

--[[

 █▀▀▄ ▀▄▒▄▀   █▀▄▀█ █▀▀▀ █▀▀▀█ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▀ █▀▀▀█
 █░▒█ ░▒█░░   █▒█▒█ █▀▀▀ ▀▀▀▄▄ ▀▀▀▄▄ █▄▄█ █░▄▄ █▀▀▀ ▀▀▀▄▄
 █▄▄▀ ▄▀▒▀▄   █░░▒█ █▄▄▄ █▄▄▄█ █▄▄▄█ █░▒█ █▄▄█ █▄▄▄ █▄▄▄█

]]--

function MensagemDX(p, message, type)
    exports["[HS]Notify_System"]:notify(p, message, type)
end

Deixa o thanks se deu certo<3

Link to comment
1 hour ago, FelipeX said:

 

Olá boa noite, o createElement não serve examente para o criar o marker, então aqui crei o marker novamente e coloquei a função dnv agora só encerrar o script...

local MarkerIniciar = createMarker(1198.36206, -1454.21411, 13.383 -1,"cylinder",1.2,255,255,255,100) -- Cria o marker de iniciar
local MarkerFinalizar = createMarker(1197.54395, -1437.23108, 13.383 -1,"cylinder",1.2,255,255,255,100) -- Cria o marker finalizar
setElementVisibleTo(MarkerFinalizar, root, false) -- Oculta o marker pra todo mundo

local veiculo = {} -- Variavel veiculo

function inicio (thePlayer)
    if thePlayer and isElement(thePlayer) and getElementType(thePlayer) == "player" then -- Verifica o elemento the thePlayer
        if not getPedOccupiedVehicle (thePlayer) then -- Se o player não estiver em veiculo, então

            local quantidade = exports["[HS]Inventory_system_2"]:getItem(thePlayer, 'cafe')
            if quantidade == 14 then -- Verificar a quantidade de pizzas
                MensagemDX(thePlayer, 'Você não tem pizzas suficientes', 'error') 
                return 
            end
        
            if veiculo[thePlayer] and isElement(veiculo[thePlayer]) then -- Se o player estiver com a moto, então destrui-la
                destroyElement(veiculo[thePlayer])
                veiculo[thePlayer] = nil
            end

            veiculo[thePlayer] = createVehicle(521, 1194.031, -1454.766, 13.383) -- Cria o veiculo
            warpPedIntoVehicle(thePlayer, veiculo[thePlayer]) -- Coloca o player dentro do veiculo

            if veiculo[thePlayer] and isElement(veiculo[thePlayer]) then -- Verifica se há moto
                if MarkerIniciar and isElement(MarkerIniciar) then -- Verifica se o marker existe
                    destroyElement(MarkerIniciar) -- Destroi o marker de iniciar
                end
                setElementVisibleTo(MarkerFinalizar, thePlayer, true) -- Mostra o marker para o player após pegar a moto
                MensagemDX(thePlayer, 'Vá até o local marcado em seu mapa para fazer sua primeira entrega', 'info')
            end

        else -- Se o player tiver no veiculo, então
            MensagemDX(thePlayer, 'Saia do seu veiculo para pegar outro!', 'info')
        end
    end
end
addEventHandler("onMarkerHit", MarkerIniciar, inicio) -- Adiciona o evento ao ligar o resource

function fim (player)
    if veiculo[player] and isElement(veiculo[player]) then -- Se há moto, então
        destroyElement(veiculo[player]) -- Destroy a moto
        setElementVisibleTo(MarkerFinalizar , player, false) -- Oculta o marker de finalizar para o player

        MarkerIniciar = createMarker(1198.36206, -1454.21411, 13.383 -1,"cylinder", 1.2, 255, 255, 255, 100) -- Cria o marker novamente
        addEventHandler("onMarkerHit", MarkerIniciar, inicio) -- Adiciona o evento da função ao marker

        MensagemDX(player, 'Você guardou a moto com sucesso e finalizou seu expediente', 'success')
    end
end
addEventHandler("onMarkerHit", MarkerFinalizar, fim) -- Adiciona o evento ao ligar o resource

--[[

 █▀▀▄ ▀▄▒▄▀   █▀▄▀█ █▀▀▀ █▀▀▀█ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▀ █▀▀▀█
 █░▒█ ░▒█░░   █▒█▒█ █▀▀▀ ▀▀▀▄▄ ▀▀▀▄▄ █▄▄█ █░▄▄ █▀▀▀ ▀▀▀▄▄
 █▄▄▀ ▄▀▒▀▄   █░░▒█ █▄▄▄ █▄▄▄█ █▄▄▄█ █░▒█ █▄▄█ █▄▄▄ █▄▄▄█

]]--

function MensagemDX(p, message, type)
    exports["[HS]Notify_System"]:notify(p, message, type)
end

Deixa o thanks se deu certo<3

Há um problema nesse código, ao usar o destroyElement no lado server, o marker é destruido para todos os jogadores!
Por isso recomendo usar o setElementVisibleTo, ou fazer este resource em client-side ( o que eu particularmente, prefiro rs)

Link to comment
9 minutes ago, Blaack said:

Há um problema nesse código, ao usar o destroyElement no lado server, o marker é destruido para todos os jogadores!
Por isso recomendo usar o setElementVisibleTo, ou fazer este resource em client-side ( o que eu particularmente, prefiro rs)

Vdd agora que me lembrei que destroy para todos os players, tentei usar o setElementVisibleTo mas não funcionou, não sei se foi por que acabei de executar uma função nele...

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