TanguyOrtegat / esx_jb_stopvehicledespawn

8 stars 15 forks source link

example of installation #1

Open shyricaus opened 5 years ago

shyricaus commented 5 years ago

function StockVehicleMenu(KindOfVehicle)
    local playerPed  = GetPlayerPed(-1)
    if IsPedInAnyVehicle(playerPed,  false) then
        local vehicle = GetVehiclePedIsIn(playerPed,false)
        local vehicleProps  = ESX.Game.GetVehicleProperties(vehicle)
        local networkid = NetworkGetNetworkIdFromEntity(vehicle)
        local GotTrailer, TrailerHandle = GetVehicleTrailerVehicle(vehicle)
        local trailerProps  = ESX.Game.GetVehicleProperties(TrailerHandle)
        if GotTrailer then
            ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
                if(valid) then
                    local trailerplate = GetVehicleNumberPlateText(TrailerHandle)
                    for k,v in pairs (carInstance) do
                        if v.plate == trailerplate then
                            table.remove(carInstance, k)
                        end
                    end
                    DeleteVehicle(TrailerHandle)
                    TriggerServerEvent('esx_jb_stopvehicledespawn:vehicleenteredingarage', networkid)
                    TriggerServerEvent('eden_garage:modifystate', trailerProps, true, KindOfVehicle)
                    TriggerEvent('esx:showNotification', '~g~Veículo guardado na garagem')
                else
                    TriggerEvent('esx:showNotification', '~r~Você não pode guardar este veículo')
                end
            end,trailerProps, KindOfVehicle)
            hasAlreadyEnteredMarker = false
        else
            ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
                if(valid) then
                    local vehicleplate = GetVehicleNumberPlateText(vehicle)
                    for k,v in pairs (carInstance) do
                        if v.plate == vehicleplate then
                            table.remove(carInstance, k)
                        end
                    end
                    DeleteVehicle(vehicle)
                    TriggerServerEvent('esx_jb_stopvehicledespawn:vehicleenteredingarage', networkid)
                    TriggerServerEvent('eden_garage:modifystate', vehicleProps, true, KindOfVehicle)
                    TriggerEvent('esx:showNotification', '~g~Veículo guardado na garagem')
                else
                    TriggerEvent('esx:showNotification', '~r~Você não pode guardar este veículo')
                end
            end,vehicleProps, KindOfVehicle)
        end
    else
        TriggerEvent('esx:showNotification', 'Você tem que estar no veículo para guardarlo')
    end
    CurrentAction = 'garage_delete'
end
TanguyOrtegat commented 5 years ago

i did update your comment you forgot to put one line :)

shyricaus commented 5 years ago

for who wants to use with esx_vehicleshop


AddEventHandler('esx_vehicleshop:hasEnteredMarker', function (zone)
  if zone == 'ShopEntering' then
    if Config.EnablePlayerManagement then
      if ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'cardealer' then
        CurrentAction     = 'reseller_menu'
        CurrentActionMsg  = _U('shop_menu')
        CurrentActionData = {}
      end
    else
      CurrentAction     = 'shop_menu'
      CurrentActionMsg  = _U('shop_menu')
      CurrentActionData = {}
    end
  end

  if zone == 'GiveBackVehicle' and Config.EnablePlayerManagement then
    local playerPed = PlayerPedId()

    if IsPedInAnyVehicle(playerPed, false) then
      local vehicle = GetVehiclePedIsIn(playerPed, false)

      CurrentAction     = 'give_back_vehicle'
      CurrentActionMsg  = _U('vehicle_menu')

      CurrentActionData = {
        vehicle = vehicle
      }
    end
  end

  if zone == 'ResellVehicle' then
    local playerPed = PlayerPedId()

    if IsPedInAnyVehicle(playerPed, false) then
      local vehicle     = GetVehiclePedIsIn(playerPed, false)
      local networkid = NetworkGetNetworkIdFromEntity(vehicle)
      local vehicleData = nil

      for i=1, #Vehicles, 1 do
        if GetHashKey(Vehicles[i].model) == GetEntityModel(vehicle) then
          vehicleData = Vehicles[i]
          break
        end
      end

      local resellPrice = math.floor(vehicleData.price / 100 * Config.ResellPercentage)

      CurrentAction     = 'resell_vehicle'
      TriggerServerEvent('esx_jb_stopvehicledespawn:vehicleenteredingarage', networkid)
      CurrentActionMsg  = _U('sell_menu', vehicleData.name, resellPrice)

      CurrentActionData = {
        vehicle = vehicle,
        price   = resellPrice
      }
    end
  end

  if zone == 'BossActions' and Config.EnablePlayerManagement and ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'cardealer' and ESX.PlayerData.job.grade_name == 'boss' then
    CurrentAction     = 'boss_actions_menu'
    CurrentActionMsg  = _U('shop_menu')
    CurrentActionData = {}
  end
end)
shyricaus commented 5 years ago

for those who want to use with esx-qalle-sellvehicles


function OpenSellMenu(veh, price, buyVehicle, owner)
    local elements = {}
    local networkid = NetworkGetNetworkIdFromEntity(veh)

    if not buyVehicle then
        if price ~= nil then
            table.insert(elements, { ["label"] = "Alterar preço - " .. price .. " :-", ["value"] = "price" })
            table.insert(elements, { ["label"] = "Colocar à venda", ["value"] = "sell" })
        else
            table.insert(elements, { ["label"] = "Preço definido - :-", ["value"] = "price" })
        end
    else
        table.insert(elements, { ["label"] = "Comprar " .. price .. " - :-", ["value"] = "buy" })

        if owner then
            table.insert(elements, { ["label"] = "Remover Veículo", ["value"] = "remove" })
        end
    end

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'sell_veh',
        {
            title    = "Menu Veículo",
            align    = 'top-right',
            elements = elements
        },
    function(data, menu)
        local action = data.current.value

        if action == "price" then
            ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'sell_veh_price',
                {
                    title = "Preço do Veículo"
                },
            function(data2, menu2)

                local vehPrice = tonumber(data2.value)

                menu2.close()
                menu.close()

                OpenSellMenu(veh, vehPrice)
            end, function(data2, menu2)
                menu2.close()
            end)
        elseif action == "sell" then
            local vehProps = ESX.Game.GetVehicleProperties(veh)

            ESX.TriggerServerCallback("esx-qalle-sellvehicles:isVehicleValid", function(valid)

                if valid then
                    DeleteVehicle(veh)
                    TriggerServerEvent('esx_jb_stopvehicledespawn:vehicleenteredingarage', networkid)
                    ESX.ShowNotification("Você colocou o ~g~veículo~s~ à venda por - " .. price .. " :-")
                    menu.close()
                else
                    ESX.ShowNotification("O seu ~g~veículo!~s~ já está a ~r~venda~s~ " .. #Config.VehiclePositions .. " veículos à venda!")
                end

            end, vehProps, price)
        elseif action == "buy" then
            ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
                if isPurchasable then
                    DeleteVehicle(veh)
                    ESX.ShowNotification("Você ~g~comprou~s~ um veículo por " .. price .. " :-")
                    menu.close()
                else
                    ESX.ShowNotification("Você ~r~não~s~ tem dinheiro suficiente, está faltando " .. price - totalMoney .. " :-")
                end
            end, ESX.Game.GetVehicleProperties(veh), price)
        elseif action == "remove" then
            ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
                if isPurchasable then
                    DeleteVehicle(veh)
                    ESX.ShowNotification("Você ~g~removeu~s~ seu veículo")
                    menu.close()
                end
            end, ESX.Game.GetVehicleProperties(veh), 0)
        end

    end, function(data, menu)
        menu.close()
    end)
end
shyricaus commented 5 years ago

for anyone who wants to use with esx_ownedcarthief


function SellStolenCar()
local playerPed   = PlayerPedId()
local veh         = GetVehiclePedIsIn(playerPed, false)
local vehicleData = ESX.Game.GetVehicleProperties(veh)
local networkid = NetworkGetNetworkIdFromEntity(veh)

    if GetPedInVehicleSeat(veh, -1) == playerPed and not SellWait then
        SellWait = true
        ESX.TriggerServerCallback('esx_ownedcarthief:GetVehPrice', function (ownedcar, vehicles)
            ESX.ShowNotification(_U('checkvehicle'))
            Citizen.CreateThread(function()
                if ownedcar then
                    for i=1, #vehicles, 1 do
                        Citizen.Wait(1)
                        local vehicle = vehicles[i]

                        if vehicleData.model == GetHashKey(vehicle.model) then
                            price = math.floor(vehicle.price / 100 * Config.ResellPercentage) 
                            ESX.Game.DeleteVehicle(veh)
                            TriggerServerEvent('esx_ownedcarthief:VehSold', true, price, vehicleData.plate)
                            TriggerServerEvent('esx_jb_stopvehicledespawn:vehicleenteredingarage', networkid)
                            SellWait = false
                            break
                        end
                    end
                elseif not Config.OnlyPlayerCar and not ownedcar then
                    price = Config.NpcCarPrice
                    ESX.Game.DeleteVehicle(veh)
                    TriggerServerEvent('esx_ownedcarthief:VehSold', false, price, vehicleData.plate)
                    SellWait = false
                elseif Config.OnlyPlayerCar and not ownedcar then
                    ESX.ShowNotification(_U('not_work_with_npc'))
                    SellWait = false
                end

            end)
        end, vehicleData.plate)
    end
end
c4gsavages commented 5 years ago

networkid = NetworkGetNetworkIdFromEntity(vehicle) TriggerServerEvent('vehicleenteredingarage', networkid)

Idk where to put this in correctly, I am using esx_jb_eden_garage2, do i put it in the client lua or server lua? Also where would I place it? I tried using the ones above as reference but don't see where you triggerserverevent

GFA-SkyRanger commented 3 years ago

I dont know, either.

i am using esx_garage