MilutuS

Untitled

Jul 27th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.96 KB | None | 0 0
  1. ESX = nil
  2. local pic = 'CHAR_CARSITE'
  3. PlayerData = {}
  4.  
  5. Citizen.CreateThread(function()
  6. while ESX == nil do
  7. Citizen.Wait(10)
  8.  
  9. TriggerEvent("esx:getSharedObject", function(response)
  10. ESX = response
  11. end)
  12. end
  13.  
  14. if ESX.IsPlayerLoaded() then
  15. PlayerData = ESX.GetPlayerData()
  16.  
  17. RemoveVehicles()
  18.  
  19. Citizen.Wait(500)
  20.  
  21. LoadSellPlace()
  22.  
  23. SpawnVehicles()
  24. end
  25. end)
  26.  
  27. RegisterNetEvent("esx:playerLoaded")
  28. AddEventHandler("esx:playerLoaded", function(response)
  29. PlayerData = response
  30.  
  31. LoadSellPlace()
  32.  
  33. SpawnVehicles()
  34. end)
  35.  
  36. RegisterNetEvent("esx-qalle-sellvehicles:refreshVehicles")
  37. AddEventHandler("esx-qalle-sellvehicles:refreshVehicles", function()
  38. RemoveVehicles()
  39.  
  40. Citizen.Wait(500)
  41.  
  42. SpawnVehicles()
  43. end)
  44.  
  45.  
  46.  
  47. function LoadSellPlace()
  48. Citizen.CreateThread(function()
  49.  
  50. local SellPos = Config.SellPosition
  51.  
  52. local Blip = AddBlipForCoord(SellPos["x"], SellPos["y"], SellPos["z"])
  53. SetBlipSprite (Blip, 225)
  54. SetBlipDisplay(Blip, 4)
  55. SetBlipScale (Blip, 0.8)
  56. SetBlipColour (Blip, 47)
  57. SetBlipAsShortRange(Blip, true)
  58. BeginTextCommandSetBlipName("STRING")
  59. AddTextComponentString("Komis samochodowy")
  60. EndTextCommandSetBlipName(Blip)
  61.  
  62. while true do
  63. local sleepThread = 500
  64.  
  65. local ped = PlayerPedId()
  66. local pedCoords = GetEntityCoords(ped)
  67.  
  68. local dstCheck = GetDistanceBetweenCoords(pedCoords, SellPos["x"], SellPos["y"], SellPos["z"], true)
  69. if dstCheck <= 100.0 then
  70. 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)
  71. sleepThread = 5
  72.  
  73. if dstCheck <= 4.2 then
  74.  
  75. if IsPedInAnyVehicle(ped, false) then
  76. DisplayHelpText("Nacisnij ~INPUT_CONTEXT~ aby otworzyć menu komisu")
  77. else
  78. DisplayHelpText("Nacisnij ~INPUT_CONTEXT~ aby odebrać gotówke lub przyjedz autem aby je wystawić")
  79. end
  80. if IsControlJustPressed(0, 38) then
  81. if IsPedInAnyVehicle(ped, false) then
  82.  
  83. OpenSellMenu(GetVehiclePedIsUsing(ped))
  84. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Pamietaj że koszt wystawienia pojazdu to 2% jego ceny za którą ma być sprzedany", pic, 1)
  85. else
  86. --ESX.ShowNotification("~r~Musisz siedzieć w pojeździe który chcesz sprzedać")
  87. OpenMenuToTakeMoney()
  88. end
  89. end
  90. end
  91. end
  92.  
  93. for i = 1, #Config.VehiclePositions, 1 do
  94. if Config.VehiclePositions[i]["entityId"] ~= nil then
  95. local pedCoords = GetEntityCoords(ped)
  96. local vehCoords = GetEntityCoords(Config.VehiclePositions[i]["entityId"])
  97.  
  98.  
  99. local dstCheck = GetDistanceBetweenCoords(pedCoords, vehCoords, true)
  100.  
  101. if dstCheck <= 1.8 then
  102. sleepThread = 5
  103. local InfoPoss = Config.InfoPositionn
  104. local InfoPos = Config.InfoPosition
  105.  
  106.  
  107.  
  108. local x = ESX.Game.GetVehicleProperties(Config.VehiclePositions[i]["entityId"])
  109. local vehicle = json.encode(x)
  110. string = vehicle
  111. local tekst = string
  112. local ilosc_znakow = string.len(vehicle)
  113.  
  114. local silnik = string.find(tekst, 'modEngine"')
  115. silnik = silnik + 11
  116. silnik2 = silnik +0
  117. local poziom_silnika = string.sub(string,silnik,silnik2)
  118. if poziom_silnika == "-1" or poziom_silnika == "-" then
  119. poziom_silnika = "~o~Seryjny~w~"
  120. elseif poziom_silnika == "0" then
  121. poziom_silnika = "1"
  122. elseif poziom_silnika == "1" then
  123. poziom_silnika = "2"
  124. elseif poziom_silnika == "2" then
  125. poziom_silnika = "3"
  126. elseif poziom_silnika == "3" then
  127. poziom_silnika = "4"
  128. elseif poziom_silnika == "4" then
  129. poziom_silnika = "5"
  130. elseif poziom_silnika == "6" then
  131. poziom_silnika = "7"
  132. end
  133.  
  134.  
  135. local turbo = string.find(tekst, 'modTurbo"')
  136. turbo = turbo + 10
  137. turbo2 = turbo +4
  138. local poziom_turbo = string.sub(string,turbo,turbo2)
  139.  
  140. if poziom_turbo == "false" then
  141. poziom_turbo = "~r~Brak~w~"
  142. else
  143. poziom_turbo = "~g~Zamontowana~w~"
  144. end
  145.  
  146. local humulce = string.find(tekst, 'modBrakes"')
  147. humulce = humulce + 11
  148. humulce2 = humulce +0
  149. local poziom_humulce = string.sub(string,humulce,humulce2)
  150.  
  151. if poziom_humulce == "-1" or poziom_humulce == "-" then
  152. poziom_humulce = "~o~Seryjne~w~"
  153. elseif poziom_humulce == "0" then
  154. poziom_humulce = "1"
  155. elseif poziom_humulce == "1" then
  156. poziom_humulce = "2"
  157. elseif poziom_humulce == "2" then
  158. poziom_humulce = "3"
  159. elseif poziom_humulce == "3" then
  160. poziom_humulce = "4"
  161. elseif poziom_humulce == "4" then
  162. poziom_humulce = "5"
  163. elseif poziom_humulce == "6" then
  164. poziom_humulce = "7"
  165. end
  166.  
  167. local skrzynia = string.find(tekst, 'modTransmission"')
  168. skrzynia = skrzynia + 17
  169. skrzynia2 = skrzynia +0
  170. local poziom_skrzynia = string.sub(string,skrzynia,skrzynia2)
  171. if poziom_skrzynia == "-1" or poziom_skrzynia == "-" then
  172. poziom_skrzynia = "~o~Seryjna~w~"
  173. elseif poziom_skrzynia == "0" then
  174. poziom_skrzynia = "1"
  175. elseif poziom_skrzynia == "1" then
  176. poziom_skrzynia = "2"
  177. elseif poziom_skrzynia == "2" then
  178. poziom_skrzynia = "3"
  179. elseif poziom_skrzynia == "3" then
  180. poziom_skrzynia = "4"
  181. elseif poziom_skrzynia == "4" then
  182. poziom_skrzynia = "5"
  183. elseif poziom_skrzynia == "6" then
  184. poziom_skrzynia = "7"
  185. end
  186.  
  187.  
  188. vehCoords_text = vehCoords
  189. local x = vehCoords_text["x"]
  190. local y = vehCoords_text["y"]
  191. local z = vehCoords_text["z"]+2
  192. local z2 = vehCoords_text["z"]+1.68
  193. local z3 = vehCoords_text["z"]+1.5
  194. local elements = {
  195. ["x"] = x,
  196. ["y"] = y,
  197. ["z"] = z
  198. }
  199. local elements2 = {
  200. ["x"] = x,
  201. ["y"] = y,
  202. ["z"] = z2
  203. }
  204. local elements3 = {
  205. ["x"] = x,
  206. ["y"] = y,
  207. ["z"] = z3
  208. }
  209. --
  210. if vmax == nil then
  211. vmax = 0
  212. end
  213. local playerPed = GetPlayerPed(-1)
  214. local coords = GetEntityCoords(playerPed)
  215. if IsPedInAnyVehicle(playerPed, false) then
  216. vehiclee = GetVehiclePedIsIn(playerPed,false)
  217. else
  218. vehiclee = GetClosestVehicle(coords.x, coords.y, coords.z, 2.0, 0, 71)
  219. end
  220. vmax = math.floor(GetVehicleHandlingFloat(vehiclee,"CHandlingData","fInitialDriveMaxFlatVel")) * 1.41
  221. local kolor = "~w~"
  222. if vmax < 180 then
  223. kolor = "~r~"
  224. elseif vmax > 180 and vmax < 280 then
  225. kolor = "~o~"
  226. elseif vmax > 280 and vmax < 330 then
  227. kolor = "~g~"
  228. elseif vmax > 330 then
  229. kolor = "~b~"
  230. end
  231. --print(vehiclee)
  232. ESX.Game.Utils.DrawText3D(elements
  233. ,
  234. "Poziom silnika: "..poziom_silnika..
  235. "\rTurbina: "..poziom_turbo..
  236. "\rPoziom hamulców: "..poziom_humulce
  237. , 0.8)
  238. ESX.Game.Utils.DrawText3D(elements2,
  239. "Poziom skrzyni biegów: "..poziom_skrzynia
  240. , 0.8)
  241. --print(y)
  242.  
  243.  
  244.  
  245. ESX.Game.Utils.DrawText3D(vehCoords, "[E] Aby kupić pojazd za:~g~ " .. Config.VehiclePositions[i]["price"].."$", 1.2)
  246. if IsControlJustPressed(0, 38) then
  247. if IsPedInVehicle(ped, Config.VehiclePositions[i]["entityId"], false) then
  248. OpenSellMenu(Config.VehiclePositions[i]["entityId"], Config.VehiclePositions[i]["price"], true, Config.VehiclePositions[i]["owner"])
  249. else
  250. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Musisz siedzieć w pojeździe który chcesz kupić", pic, 1)
  251. end
  252. end
  253. if IsPedInVehicle(ped, Config.VehiclePositions[i]["entityId"], false) then
  254. FreezeEntityPosition(PlayerPedId(), true)
  255. if IsPedInAnyVehicle(PlayerPedId(), true) then
  256. FreezeEntityPosition(GetVehiclePedIsIn(PlayerPedId(), false), true)
  257. end
  258. else
  259. FreezeEntityPosition(PlayerPedId(), false)
  260. if IsPedInAnyVehicle(PlayerPedId(), true) then
  261. FreezeEntityPosition(GetVehiclePedIsIn(PlayerPedId(), false), false)
  262. end
  263. end
  264. end
  265. end
  266. end
  267.  
  268. Citizen.Wait(sleepThread)
  269. end
  270. end)
  271. end
  272.  
  273. function OpenMenuToTakeMoney()
  274. ESX.TriggerServerCallback('esx_purchaseVehicles:getinfoofmoney', function(quantity)
  275. local quantity = tonumber(quantity)
  276. if quantity == nil then
  277. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~y~Nie masz żadnych pieniędzy do odebrania !", pic, 1)
  278. elseif quantity > 0 then
  279. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~y~odebrałeś "..quantity.."$ !", pic, 1)
  280.  
  281. TriggerServerEvent('esx:komissamochodowy',GetPlayerName(PlayerId()),0,quantity)
  282. TriggerServerEvent('esx_purchaseVehicles:givemoney',quantity)
  283. else
  284. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~y~Nie masz żadnych pieniędzy do odebrania !", pic, 1)
  285. end
  286.  
  287. end, '')
  288. end
  289.  
  290. function OpenSellMenu(veh, price, buyVehicle, owner)
  291. local elements = {}
  292.  
  293. if not buyVehicle then
  294. if price ~= nil then
  295. table.insert(elements, { ["label"] = "Zmień cene: " .. price.."$", ["value"] = "price" })
  296. table.insert(elements, { ["label"] = "Wystaw na sprzedarz", ["value"] = "sell" })
  297. else
  298. table.insert(elements, { ["label"] = "Ustaw cene: ", ["value"] = "price" })
  299. end
  300. else
  301. table.insert(elements, { ["label"] = "Kup za: " .. price.."$", ["value"] = "buy" })
  302.  
  303. if owner then
  304. table.insert(elements, { ["label"] = "Usun pojazd", ["value"] = "remove" })
  305. end
  306. end
  307.  
  308. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'sell_veh',
  309. {
  310. title = "Komis Samochodowy",
  311. align = 'top-left',
  312. elements = elements
  313. },
  314. function(data, menu)
  315. local action = data.current.value
  316.  
  317. if action == "price" then
  318. ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'sell_veh_price',
  319. {
  320. title = "Cena pojazdu"
  321. },
  322. function(data2, menu2)
  323.  
  324. local vehPrice = tonumber(data2.value)
  325.  
  326. menu2.close()
  327. menu.close()
  328.  
  329. OpenSellMenu(veh, vehPrice)
  330. end, function(data2, menu2)
  331. menu2.close()
  332. end)
  333. elseif action == "sell" then
  334. local vehProps = ESX.Game.GetVehicleProperties(veh)
  335. local jebac_haksow = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
  336.  
  337.  
  338. ESX.TriggerServerCallback("esx-qalle-sellvehicles:getmoneyofplayer", function(valid)
  339. local procent = math.floor(price*0.02)
  340. if valid >= procent then
  341. ESX.TriggerServerCallback("esx-qalle-sellvehicles:isVehicleValid", function(valid)
  342. if valid then
  343. if procent < 500 then
  344. procent = 500
  345. else
  346. procent = procent
  347. end
  348. TriggerServerEvent('esx_purchaseVehicles:removeemoney',procent)
  349. if DoesEntityExist(veh) then
  350. DeleteEntity(veh)
  351. else
  352. print("Brak pojazdu")
  353. end
  354. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "Wystawileś pojazd na sprzedarz za:~g~ " .. price.."$\r~w~Koszt wystawienia to:~r~"..procent.."$", pic, 1)
  355. menu.close()
  356.  
  357. else
  358. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Musisz być właścicielem pojazdu", pic, 1)
  359. end
  360.  
  361. end, vehProps, price,jebac_haksow)
  362. else
  363. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Musisz mieć "..procent.." aby wystawić pojazd za kwote "..price, pic, 1)
  364. end
  365. end, price)
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. elseif action == "buy" then
  373. local jebac_haksow = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
  374. ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
  375. if isPurchasable then
  376. DeleteVehicle(veh)
  377. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "Kupiłes ten pojazd za: ~g~".. price.."$", pic, 1)
  378. menu.close()
  379. else
  380.  
  381. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "Nie masz wystarczajaca gotowki. Brakuje: ~r~" .. price - totalMoney.."$", pic, 1)
  382. end
  383. end, ESX.Game.GetVehicleProperties(veh), price, jebac_haksow)
  384. elseif action == "remove" then
  385. local jebac_haksow = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
  386. ESX.TriggerServerCallback("esx-qalle-sellvehicles:buyVehicle", function(isPurchasable, totalMoney)
  387. if isPurchasable then
  388. DeleteVehicle(veh)
  389. ESX.ShowAdvancedNotification('Komis Samochodowy', '', "~r~Usunales ten pojazd", pic, 1)
  390. menu.close()
  391. end
  392. end, ESX.Game.GetVehicleProperties(veh), 0, jebac_haksow)
  393. end
  394.  
  395. end, function(data, menu)
  396. menu.close()
  397. end)
  398. end
  399.  
  400. function RemoveVehicles()
  401. local VehPos = Config.VehiclePositions
  402.  
  403. for i = 1, #VehPos, 1 do
  404. local veh, distance = ESX.Game.GetClosestVehicle(VehPos[i])
  405.  
  406. if DoesEntityExist(veh) and distance <= 1.0 then
  407. if DoesEntityExist(veh) then
  408. DeleteEntity(veh)
  409. else
  410. print("Brak pojazdu")
  411. end
  412. end
  413. end
  414. end
  415.  
  416. function SpawnVehicles()
  417. local VehPos = Config.VehiclePositions
  418.  
  419. ESX.TriggerServerCallback("esx-qalle-sellvehicles:retrieveVehicles", function(vehicles)
  420. for i = 1, #vehicles, 1 do
  421.  
  422. local vehicleProps = vehicles[i]["vehProps"]
  423.  
  424. LoadModel(vehicleProps["model"])
  425.  
  426. VehPos[i]["entityId"] = CreateVehicle(vehicleProps["model"], VehPos[i]["x"], VehPos[i]["y"], VehPos[i]["z"] - 0.975, VehPos[i]["h"], false)
  427. VehPos[i]["price"] = vehicles[i]["price"]
  428. VehPos[i]["owner"] = vehicles[i]["owner"]
  429.  
  430. ESX.Game.SetVehicleProperties(VehPos[i]["entityId"], vehicleProps)
  431.  
  432. FreezeEntityPosition(VehPos[i]["entityId"], true)
  433.  
  434. SetEntityAsMissionEntity(VehPos[i]["entityId"], true, true)
  435. SetModelAsNoLongerNeeded(vehicleProps["model"])
  436. end
  437. end)
  438.  
  439. end
  440.  
  441. LoadModel = function(model)
  442. while not HasModelLoaded(model) do
  443. RequestModel(model)
  444.  
  445. Citizen.Wait(1)
  446. end
  447. end
  448. function DisplayHelpText(str)
  449. SetTextComponentFormat("STRING")
  450. AddTextComponentString(str)
  451. DisplayHelpTextFromStringLabel(0, 0, 1, -1)
  452. end
Advertisement
Add Comment
Please, Sign In to add comment