Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ESX = nil
- local pic = 'CHAR_CARSITE'
- PlayerData = {}
- Citizen.CreateThread(function()
- while ESX == nil do
- Citizen.Wait(10)
- TriggerEvent("esx:getSharedObject", function(response)
- ESX = response
- end)
- end
- if ESX.IsPlayerLoaded() then
- PlayerData = ESX.GetPlayerData()
- RemoveVehicles()
- Citizen.Wait(500)
- LoadSellPlace()
- SpawnVehicles()
- end
- end)
- RegisterNetEvent("esx:playerLoaded")
- AddEventHandler("esx:playerLoaded", function(response)
- PlayerData = response
- LoadSellPlace()
- SpawnVehicles()
- end)
- RegisterNetEvent("esx-qalle-sellvehicles:refreshVehicles")
- AddEventHandler("esx-qalle-sellvehicles:refreshVehicles", function()
- RemoveVehicles()
- Citizen.Wait(500)
- SpawnVehicles()
- end)
- function LoadSellPlace()
- Citizen.CreateThread(function()
- local SellPos = Config.SellPosition
- local Blip = AddBlipForCoord(SellPos["x"], SellPos["y"], SellPos["z"])
- SetBlipSprite (Blip, 225)
- SetBlipDisplay(Blip, 4)
- SetBlipScale (Blip, 0.8)
- SetBlipColour (Blip, 47)
- SetBlipAsShortRange(Blip, true)
- BeginTextCommandSetBlipName("STRING")
- AddTextComponentString("Komis samochodowy")
- EndTextCommandSetBlipName(Blip)
- while true do
- local sleepThread = 500
- local ped = PlayerPedId()
- local pedCoords = GetEntityCoords(ped)
- local dstCheck = GetDistanceBetweenCoords(pedCoords, SellPos["x"], SellPos["y"], SellPos["z"], true)
- if dstCheck <= 100.0 then
- DrawMarker(29, SellPos["x"], SellPos["y"], SellPos["z"], 0.0, 0.0, 0.0, 0, 0.0, 0.0, 3.0, 3.0, 2.0, 100, 100, 204, 100, false, true, 2, false, false, false, false)
- sleepThread = 5
- if dstCheck <= 4.2 then
- if IsPedInAnyVehicle(ped, false) then
- DisplayHelpText("Nacisnij ~INPUT_CONTEXT~ aby otworzyć menu komisu")
- else
- DisplayHelpText("Nacisnij ~INPUT_CONTEXT~ aby odebrać gotówke lub przyjedz autem aby je wystawić")
- end
- if IsControlJustPressed(0, 38) then
- if IsPedInAnyVehicle(ped, false) then
- OpenSellMenu(GetVehiclePedIsUsing(ped))
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Pamietaj że koszt wystawienia pojazdu to 2% jego ceny za którą ma być sprzedany", pic, 1)
- else
- --ESX.ShowNotification("~r~Musisz siedzieć w pojeździe który chcesz sprzedać")
- OpenMenuToTakeMoney()
- end
- end
- end
- end
- for i = 1, #Config.VehiclePositions, 1 do
- if Config.VehiclePositions[i]["entityId"] ~= nil then
- local pedCoords = GetEntityCoords(ped)
- local vehCoords = GetEntityCoords(Config.VehiclePositions[i]["entityId"])
- local dstCheck = GetDistanceBetweenCoords(pedCoords, vehCoords, true)
- if dstCheck <= 1.8 then
- sleepThread = 5
- local InfoPoss = Config.InfoPositionn
- local InfoPos = Config.InfoPosition
- local x = ESX.Game.GetVehicleProperties(Config.VehiclePositions[i]["entityId"])
- local vehicle = json.encode(x)
- string = vehicle
- local tekst = string
- local ilosc_znakow = string.len(vehicle)
- local silnik = string.find(tekst, 'modEngine"')
- silnik = silnik + 11
- silnik2 = silnik +0
- local poziom_silnika = string.sub(string,silnik,silnik2)
- if poziom_silnika == "-1" or poziom_silnika == "-" then
- poziom_silnika = "~o~Seryjny~w~"
- elseif poziom_silnika == "0" then
- poziom_silnika = "1"
- elseif poziom_silnika == "1" then
- poziom_silnika = "2"
- elseif poziom_silnika == "2" then
- poziom_silnika = "3"
- elseif poziom_silnika == "3" then
- poziom_silnika = "4"
- elseif poziom_silnika == "4" then
- poziom_silnika = "5"
- elseif poziom_silnika == "6" then
- poziom_silnika = "7"
- end
- local turbo = string.find(tekst, 'modTurbo"')
- turbo = turbo + 10
- turbo2 = turbo +4
- local poziom_turbo = string.sub(string,turbo,turbo2)
- if poziom_turbo == "false" then
- poziom_turbo = "~r~Brak~w~"
- else
- poziom_turbo = "~g~Zamontowana~w~"
- end
- local humulce = string.find(tekst, 'modBrakes"')
- humulce = humulce + 11
- humulce2 = humulce +0
- local poziom_humulce = string.sub(string,humulce,humulce2)
- if poziom_humulce == "-1" or poziom_humulce == "-" then
- poziom_humulce = "~o~Seryjne~w~"
- elseif poziom_humulce == "0" then
- poziom_humulce = "1"
- elseif poziom_humulce == "1" then
- poziom_humulce = "2"
- elseif poziom_humulce == "2" then
- poziom_humulce = "3"
- elseif poziom_humulce == "3" then
- poziom_humulce = "4"
- elseif poziom_humulce == "4" then
- poziom_humulce = "5"
- elseif poziom_humulce == "6" then
- poziom_humulce = "7"
- end
- local skrzynia = string.find(tekst, 'modTransmission"')
- skrzynia = skrzynia + 17
- skrzynia2 = skrzynia +0
- local poziom_skrzynia = string.sub(string,skrzynia,skrzynia2)
- if poziom_skrzynia == "-1" or poziom_skrzynia == "-" then
- poziom_skrzynia = "~o~Seryjna~w~"
- elseif poziom_skrzynia == "0" then
- poziom_skrzynia = "1"
- elseif poziom_skrzynia == "1" then
- poziom_skrzynia = "2"
- elseif poziom_skrzynia == "2" then
- poziom_skrzynia = "3"
- elseif poziom_skrzynia == "3" then
- poziom_skrzynia = "4"
- elseif poziom_skrzynia == "4" then
- poziom_skrzynia = "5"
- elseif poziom_skrzynia == "6" then
- poziom_skrzynia = "7"
- end
- vehCoords_text = vehCoords
- local x = vehCoords_text["x"]
- local y = vehCoords_text["y"]
- local z = vehCoords_text["z"]+2
- local z2 = vehCoords_text["z"]+1.68
- local z3 = vehCoords_text["z"]+1.5
- local elements = {
- ["x"] = x,
- ["y"] = y,
- ["z"] = z
- }
- local elements2 = {
- ["x"] = x,
- ["y"] = y,
- ["z"] = z2
- }
- local elements3 = {
- ["x"] = x,
- ["y"] = y,
- ["z"] = z3
- }
- --
- if vmax == nil then
- vmax = 0
- end
- local playerPed = GetPlayerPed(-1)
- local coords = GetEntityCoords(playerPed)
- if IsPedInAnyVehicle(playerPed, false) then
- vehiclee = GetVehiclePedIsIn(playerPed,false)
- else
- vehiclee = GetClosestVehicle(coords.x, coords.y, coords.z, 2.0, 0, 71)
- end
- vmax = math.floor(GetVehicleHandlingFloat(vehiclee,"CHandlingData","fInitialDriveMaxFlatVel")) * 1.41
- local kolor = "~w~"
- if vmax < 180 then
- kolor = "~r~"
- elseif vmax > 180 and vmax < 280 then
- kolor = "~o~"
- elseif vmax > 280 and vmax < 330 then
- kolor = "~g~"
- elseif vmax > 330 then
- kolor = "~b~"
- end
- --print(vehiclee)
- ESX.Game.Utils.DrawText3D(elements
- ,
- "Poziom silnika: "..poziom_silnika..
- "\rTurbina: "..poziom_turbo..
- "\rPoziom hamulców: "..poziom_humulce
- , 0.8)
- ESX.Game.Utils.DrawText3D(elements2,
- "Poziom skrzyni biegów: "..poziom_skrzynia
- , 0.8)
- --print(y)
- ESX.Game.Utils.DrawText3D(vehCoords, "[E] Aby kupić pojazd za:~g~ " .. Config.VehiclePositions[i]["price"].."$", 1.2)
- if IsControlJustPressed(0, 38) then
- if IsPedInVehicle(ped, Config.VehiclePositions[i]["entityId"], false) then
- OpenSellMenu(Config.VehiclePositions[i]["entityId"], Config.VehiclePositions[i]["price"], true, Config.VehiclePositions[i]["owner"])
- else
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Musisz siedzieć w pojeździe który chcesz kupić", pic, 1)
- end
- end
- if IsPedInVehicle(ped, Config.VehiclePositions[i]["entityId"], false) then
- FreezeEntityPosition(PlayerPedId(), true)
- if IsPedInAnyVehicle(PlayerPedId(), true) then
- FreezeEntityPosition(GetVehiclePedIsIn(PlayerPedId(), false), true)
- end
- else
- FreezeEntityPosition(PlayerPedId(), false)
- if IsPedInAnyVehicle(PlayerPedId(), true) then
- FreezeEntityPosition(GetVehiclePedIsIn(PlayerPedId(), false), false)
- end
- end
- end
- end
- end
- Citizen.Wait(sleepThread)
- end
- end)
- end
- function OpenMenuToTakeMoney()
- ESX.TriggerServerCallback('esx_purchaseVehicles:getinfoofmoney', function(quantity)
- local quantity = tonumber(quantity)
- if quantity == nil then
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~y~Nie masz żadnych pieniędzy do odebrania !", pic, 1)
- elseif quantity > 0 then
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~y~odebrałeś "..quantity.."$ !", pic, 1)
- TriggerServerEvent('esx:komissamochodowy',GetPlayerName(PlayerId()),0,quantity)
- TriggerServerEvent('esx_purchaseVehicles:givemoney',quantity)
- else
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~y~Nie masz żadnych pieniędzy do odebrania !", pic, 1)
- end
- end, '')
- end
- function OpenSellMenu(veh, price, buyVehicle, owner)
- local elements = {}
- if not buyVehicle then
- if price ~= nil then
- table.insert(elements, { ["label"] = "Zmień cene: " .. price.."$", ["value"] = "price" })
- table.insert(elements, { ["label"] = "Wystaw na sprzedarz", ["value"] = "sell" })
- else
- table.insert(elements, { ["label"] = "Ustaw cene: ", ["value"] = "price" })
- end
- else
- table.insert(elements, { ["label"] = "Kup za: " .. price.."$", ["value"] = "buy" })
- if owner then
- table.insert(elements, { ["label"] = "Usun pojazd", ["value"] = "remove" })
- end
- end
- ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'sell_veh',
- {
- title = "Komis Samochodowy",
- align = 'top-left',
- elements = elements
- },
- function(data, menu)
- local action = data.current.value
- if action == "price" then
- ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'sell_veh_price',
- {
- title = "Cena pojazdu"
- },
- 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)
- local jebac_haksow = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
- ESX.TriggerServerCallback("esx-qalle-sellvehicles:getmoneyofplayer", function(valid)
- local procent = math.floor(price*0.02)
- if valid >= procent then
- ESX.TriggerServerCallback("esx-qalle-sellvehicles:isVehicleValid", function(valid)
- if valid then
- if procent < 500 then
- procent = 500
- else
- procent = procent
- end
- TriggerServerEvent('esx_purchaseVehicles:removeemoney',procent)
- if DoesEntityExist(veh) then
- DeleteEntity(veh)
- else
- print("Brak pojazdu")
- end
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "Wystawileś pojazd na sprzedarz za:~g~ " .. price.."$\r~w~Koszt wystawienia to:~r~"..procent.."$", pic, 1)
- menu.close()
- else
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Musisz być właścicielem pojazdu", pic, 1)
- end
- end, vehProps, price,jebac_haksow)
- else
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Musisz mieć "..procent.." aby wystawić pojazd za kwote "..price, pic, 1)
- end
- end, price)
- elseif action == "buy" then
- local jebac_haksow = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
- ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
- if isPurchasable then
- DeleteVehicle(veh)
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "Kupiłes ten pojazd za: ~g~".. price.."$", pic, 1)
- menu.close()
- else
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "Nie masz wystarczajaca gotowki. Brakuje: ~r~" .. price - totalMoney.."$", pic, 1)
- end
- end, ESX.Game.GetVehicleProperties(veh), price, jebac_haksow)
- elseif action == "remove" then
- local jebac_haksow = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
- ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
- if isPurchasable then
- DeleteVehicle(veh)
- ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Usunales ten pojazd", pic, 1)
- menu.close()
- end
- end, ESX.Game.GetVehicleProperties(veh), 0, jebac_haksow)
- end
- end, function(data, menu)
- menu.close()
- end)
- end
- function RemoveVehicles()
- local VehPos = Config.VehiclePositions
- for i = 1, #VehPos, 1 do
- local veh, distance = ESX.Game.GetClosestVehicle(VehPos[i])
- if DoesEntityExist(veh) and distance <= 1.0 then
- if DoesEntityExist(veh) then
- DeleteEntity(veh)
- else
- print("Brak pojazdu")
- end
- end
- end
- end
- function SpawnVehicles()
- local VehPos = Config.VehiclePositions
- ESX.TriggerServerCallback("esx-qalle-sellvehicles:retrieveVehicles", function(vehicles)
- for i = 1, #vehicles, 1 do
- local vehicleProps = vehicles[i]["vehProps"]
- LoadModel(vehicleProps["model"])
- VehPos[i]["entityId"] = CreateVehicle(vehicleProps["model"], VehPos[i]["x"], VehPos[i]["y"], VehPos[i]["z"] - 0.975, VehPos[i]["h"], false)
- VehPos[i]["price"] = vehicles[i]["price"]
- VehPos[i]["owner"] = vehicles[i]["owner"]
- ESX.Game.SetVehicleProperties(VehPos[i]["entityId"], vehicleProps)
- FreezeEntityPosition(VehPos[i]["entityId"], true)
- SetEntityAsMissionEntity(VehPos[i]["entityId"], true, true)
- SetModelAsNoLongerNeeded(vehicleProps["model"])
- end
- end)
- end
- LoadModel = function(model)
- while not HasModelLoaded(model) do
- RequestModel(model)
- Citizen.Wait(1)
- end
- end
- function DisplayHelpText(str)
- SetTextComponentFormat("STRING")
- AddTextComponentString(str)
- DisplayHelpTextFromStringLabel(0, 0, 1, -1)
- end
Advertisement
Add Comment
Please, Sign In to add comment