Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.94 KB | None | 0 0
  1. tow =
  2. {
  3.     towary = { },
  4.     last =
  5.         {
  6.             select = false,
  7.             text = "",
  8.             grupa = "",
  9.         },
  10.     grupa = {},
  11.     labelRed = { },
  12.     przesylki = {}
  13. }
  14.  
  15. rozladunki_window, tab1 = guiCreateWindow(screenX / 2 - 175, screenY / 2 - 75, 350, 150, "Rozladunek", false)
  16. rozladunki_text = guiCreateLabel(10, 15, 320, 80, "Witaj, tutaj możesz załadowac / rozładować towar.\n\nWystarczy, ze klikniesz na odpowiedni przycisk.", false, tab1)
  17. guiLabelSetHorizontalAlign(rozladunki_text, "left", true)
  18. rozladunki_button = guiCreateButton(20, 100, 150, 20, "Załaduj", false, tab1)
  19. rozladunki_zamknij = guiCreateButton(180, 100, 150, 20, "Zamknij", false, tab1)
  20. guiSetVisible(rozladunki_window, false)
  21.  
  22. towary_lista_window, tab2 = guiCreateWindow(screenX / 2 - 550 / 2, screenY / 2 - 400 / 2, 550, 400, "Towary", false)
  23. rozladunek_scroll = guiCreateScrollPane(10, 30, 550 - 20, 400 - 90, false, tab2)
  24. guiScrollPaneSetScrollBars(rozladunek_scroll, false, false)
  25. guiSetProperty(rozladunek_scroll, "VertStepSize", "0.05")
  26. guiSetProperty(rozladunek_scroll, "HorzStepSize", "0.05")
  27. guiCreateLabel(60, 10, 50, 20, "Nazwa", false, tab2)
  28. guiCreateLabel(170, 10, 50, 20, "Score", false, tab2)
  29. guiCreateLabel(280, 10, 50, 20, "Ilość", false, tab2)
  30. guiCreateLabel(450, 10, 50, 20, "Załaduj", false, tab2)
  31. rozladunek_zamknij = guiCreateButton(550 / 2 - 50, 400 - 50, 100, 20, "Zamknij", false, tab2)
  32. guiSetVisible(towary_lista_window,false)
  33.  
  34. waga_okno,tab3 = guiCreateWindow(screenX / 2 - 145, screenY / 2 - 50, 290, 160, "Ilość towaru", false)
  35. waga_ladowanie = guiCreateScrollBar(5, 10, 280, 18, true, false, tab3)
  36. guiSetProperty(waga_ladowanie, "StepSize", "0.01")
  37. guiScrollBarSetScrollPosition(waga_ladowanie, 50)
  38. guiCreateStaticImage(232, 0, 2, 30, "files/dot.png", false, waga_ladowanie)
  39. guiCreateLabel(20, 0, 30, 40, "10%", false, waga_ladowanie)
  40. guiCreateLabel(235, 0, 30, 40, "110%", false, waga_ladowanie)
  41. waga_stan_bg = guiCreateStaticImage(5, 34, 280, 20, "files/capture_bg.png", false, tab3)
  42. waga_stan_stan = guiCreateStaticImage(0, 0, 140, 20, "files/capture.png", false, waga_stan_bg)
  43. waga_tekst = guiCreateLabel(5, 60, 280, 50, "Przeładowując pojazd narażasz się na mandat od\nfunkcjonariuszy policji. Jeżeli nie chcesz dostać kary\nprzesuń suwak do czerwonek kreski", false, tab3)
  44. guiLabelSetHorizontalAlign(waga_tekst, "left", true)
  45. waga_stan_tekst = guiCreateLabel(0, 0, 280, 20, "60%", false, waga_stan_bg)
  46. guiLabelSetHorizontalAlign(waga_stan_tekst, "center", true)
  47. waga_button = guiCreateButton(95, 110, 100, 20, "Ładuj", false, tab3)
  48. waga_wstecz = guiCreateButton(10, 112, 60, 18, "Wróć", false, tab3)
  49. guiSetVisible(waga_okno, false)
  50.  
  51. zapytanie_window,tab4 = guiCreateWindow(screenX / 2 - 150, screenY / 2 - 62, 300, 124, "Kolejny rozładunek", false)
  52. zapytanie_text = guiCreateLabel(10, 6.5, 280, 46, "Czy chcesz, aby system wylosował docelowy\nrozładunek? Czy wolisz sam wybrać gdzie chcesz\ndowieźć towar? Wciśnij odpowiedni przycisk.", false, tab4)
  53. guiLabelSetHorizontalAlign(zapytanie_text, "left", true)
  54. zapytanie_1 = guiCreateButton(60, 62, 100, 28, "Skrypt", false, tab4)
  55. zapytanie_2 = guiCreateButton(170, 62, 100, 28, "Sam wybiorę", false, tab4)
  56. zapytanie_wstecz = guiCreateButton(10, 70, 40, 20, "Wróć", false, tab4)
  57. guiSetVisible(zapytanie_window, false)
  58.  
  59. TruckWorld_ZmianaScrolla = function()
  60.   local stan = guiScrollBarGetScrollPosition(waga_ladowanie)
  61.   guiSetSize(waga_stan_stan, stan * 2.8, 18, false)
  62.   guiSetText(waga_stan_tekst, tostring(stan + 10) .. "%")
  63. end
  64. addEventHandler("onClientGUIScroll", waga_ladowanie, TruckWorld_ZmianaScrolla)
  65.  
  66. addEvent("show",true)
  67. addEventHandler("show",root,function(id,towary)
  68. local x,y,z = getElementPosition(getMarkerByID(id))
  69. -- guiText:visible(true)
  70. -- guiText:text("Zatrąb, aby otworzyć menu\n\nStrefa załadunku "..id.."\n\n"..getZoneName(x,y,z).."")
  71. exports["es-komunikaty"]:komunikat("Zatrąb, aby otworzyć menu\n\nStrefa załadunku "..id.."\n\n"..getZoneName(x,y,z).."", plr)
  72. marid = id
  73. towtable = split(towary,',')
  74. bindKey("H","down",open_window)
  75.     if getVehicleTowedByVehicle(getPedOccupiedVehicle(localPlayer)) then
  76.         veh = getVehicleTowedByVehicle(getPedOccupiedVehicle(localPlayer))
  77.     else
  78.         veh = getPedOccupiedVehicle(localPlayer)
  79.     end
  80. end)
  81.  
  82. addEvent("close",true)
  83. addEventHandler("close",root,function(id)
  84. marid = false
  85. unbindKey("H","down",open_window)
  86. -- guiText:visible(false)
  87. -- guiText:text("")
  88. end)
  89.  
  90. function open_window()
  91. guiSetVisible(rozladunki_window,true)
  92. showCursor(true)
  93. unbindKey("H","down",open_window)
  94.     triggerServerEvent("blokujJazde",localPlayer,localPlayer,"Tak")
  95.     if getElementData(veh,"zaladowany") == true then
  96.         guiSetText(rozladunki_button,"Rozładuj")
  97.     else
  98.         guiSetText(rozladunki_button,"Załaduj")
  99.     end
  100. end
  101.  
  102. addEventHandler("onClientGUIClick",root,function()
  103.     if source == rozladunki_zamknij then
  104.         guiSetVisible(rozladunki_window,false)
  105.         showCursor(false)
  106.         bindKey("H","down",open_window)
  107.         close_praca()
  108.         triggerServerEvent("blokujJazde",localPlayer,localPlayer,"Nie")
  109.     elseif source == rozladunki_button then
  110.         if guiGetText(rozladunki_button) == "Załaduj" then
  111.             close_praca()
  112.             unbindKey("H","down",open_window)
  113.             guiSetVisible(rozladunki_window,false)
  114.             guiSetVisible(towary_lista_window,true)
  115.             createTowary() 
  116.         else
  117.             if getElementData(veh,"zaladowany") == true then
  118.                 if getElementData(veh,"rozladowac_moze") == true then
  119.                     if getElementData(veh,"rozladunek_typ") == "Skrypt" then
  120.                         if getElementData(veh,"rozladunek_id") == marid then
  121.                             rozladuj()
  122.                         else
  123.                             outputMessage("To nie jest twoje miejsce rozładunku","warning","",false)
  124.                         end
  125.                     else
  126.                         rozladuj()
  127.                     end
  128.                 else
  129.                     outputMessage("Nie możesz jeszcze rozładować towaru","warning","",false)
  130.                 end
  131.             end
  132.         end
  133.     elseif source == rozladunek_zamknij then
  134.         guiSetVisible(towary_lista_window,false)
  135.         showCursor(false)
  136.         close_praca()
  137.         bindKey("H","down",open_window)
  138.         triggerServerEvent("blokujJazde",localPlayer,localPlayer,"Nie")
  139.     elseif source == tak then
  140.         closeMessageBox()
  141.         guiSetVisible(towary_lista_window,false)
  142.         guiSetVisible(waga_okno,true)
  143.         close_praca()
  144.     elseif source == nie then
  145.         closeMessageBox()
  146.     elseif source == waga_wstecz then
  147.         guiSetVisible(towary_lista_window,true)
  148.         guiSetVisible(waga_okno,false)
  149.         createTowary()
  150.     elseif source == waga_button then
  151.         local stan = guiScrollBarGetScrollPosition(waga_ladowanie)
  152.         waga = tonumber(stan+10)
  153.         guiSetVisible(zapytanie_window,true)
  154.         guiSetVisible(waga_okno,false)
  155.     elseif source == zapytanie_1 then
  156.         zaladuj(towar,kategoria,czas,waga,"Skrypt")
  157.         guiSetVisible(zapytanie_window,false)
  158.         showCursor(false)
  159.     elseif source == zapytanie_2 then
  160.         zaladuj(towar,kategoria,czas,waga,"Sam wybiore")
  161.         guiSetVisible(zapytanie_window,false)
  162.         showCursor(false)
  163.     end
  164. end)
  165.  
  166. function close_praca()
  167.     for k,v in ipairs(getElementChildren(rozladunek_scroll)) do
  168.         destroyElement(v)
  169.     end
  170.     tow.last.text = ""
  171.     tow.labelRed = {}
  172.     tow.towary = { }
  173.     tow.last.select = false
  174. end
  175.  
  176. addEvent("uzupclient",true)
  177. addEventHandler("uzupclient",getRootElement(),
  178.     function(tows,ka)
  179.         tow = tows
  180.         kate = ka
  181.     end
  182. )
  183.  
  184. function iniciateZapisData()
  185.     local mar = getMarkerByID(marid)
  186.     for num,data in ipairs(towtable) do
  187.         setElementData(mar,"towar_"..tostring(data['towarName']),tonumber(data['wartosc']))
  188.     end
  189. end
  190.  
  191. function createTowary()
  192.     iniciateZapisData()
  193.     local id = 0
  194.     for l,a in ipairs(split(getDane("zal"),',')) do
  195.         guiCreateLabel(0, id * 25 + 1, 500, 20, a, false, rozladunek_scroll)
  196.         guiCreateStaticImage(0, id * 25 + 20, 500, 1, "files/capture.png", false, rozladunek_scroll)
  197.         id = id+1
  198.         for i,v in ipairs(tow.grupa[a]) do
  199.             local labelname = guiCreateLabel(20, (id) * 25, 135, 20,  v[1], false, rozladunek_scroll)
  200.             local labelscore = guiCreateLabel(170, (id) * 25, 30, 20,  v[2], false, rozladunek_scroll)
  201.             local podkladimage = guiCreateStaticImage(210, (id) * 25 + 1, 200, 18, "files/capture_bg.png", false, rozladunek_scroll)
  202.             local minlabel = guiCreateButton(420, (id) * 25, 65, 20,  "Załaduj", false, rozladunek_scroll)
  203.             setElementData(minlabel, "towar_id", v[1], false)
  204.             setElementData(minlabel, "towar_czas", v[5], false)
  205.             setElementData(minlabel, "towar_kategoria", v[7], false)
  206.             addEventHandler("onClientGUIClick", minlabel, pytanie)
  207.             tow.towary[v[1]] =
  208.             {
  209.                 labelname,
  210.                 labelscore,
  211.                 podkladimage,
  212.                 minlabel,
  213.                 v[5],
  214.                 a
  215.             }
  216.             setElementSource(labelname,labelname)
  217.             setElementSource(labelscore,labelname)
  218.             setElementSource(minlabel,labelname)
  219.             local postepbar = guiCreateStaticImage(0, 0, 0, 18, "files/capture.png", false, podkladimage)
  220.             local mar = getMarkerByID(marid)
  221.             if mar then
  222.                 local data = getElementData(mar,"towar_"..tostring(v[1]))
  223.                 if tonumber(data) then
  224.                     setProggesPasek(postepbar,data)
  225.                 else
  226.                     setProggesPasek(postepbar,100)
  227.                     setElementData(mar,"towar_"..tostring(v[1]),100)
  228.                 end
  229.             end
  230.             if tonumber(v[2]) > tonumber(getElementData(localPlayer,"Score")) then
  231.             guiSetAlpha(labelname,0.5)
  232.             guiSetAlpha(labelscore,0.5)
  233.             guiSetAlpha(labelscore,0.5)
  234.             guiSetAlpha(postepbar,0.5)
  235.             guiSetAlpha(podkladimage,0.5)
  236.             guiSetEnabled(minlabel,false)
  237.             end
  238.             id = id+1
  239.         end
  240.     end
  241. end
  242.  
  243. function setElementSource(element,elementtosource)
  244.     return setElementData(element,"source_Element",elementtosource)
  245. end
  246.  
  247. function getElementSource(element)
  248.     return getElementData(element,"source_Element")
  249. end
  250.  
  251. function setProggesPasek(ele,postep)
  252.     guiSetSize(ele, tonumber(postep)*2, 26, false)
  253. end
  254.  
  255. function getDane(typ)
  256.     for a,marker in ipairs(getElementsByType("colshape",getResourceRootElement(getThisResource()))) do
  257.         if getElementData(marker,"id") == marid then
  258.             return getElementData(marker,typ)
  259.         end
  260.     end
  261.     return false
  262. end
  263.  
  264. function getMarkerByID(id)
  265.     for a,marker in ipairs(getElementsByType("colshape",getResourceRootElement(getThisResource()))) do
  266.         if getElementData(marker,"id") == id then
  267.             return marker
  268.         end
  269.     end
  270.     return false
  271. end
  272.  
  273. function pytanie()
  274. towar = getElementData(source,"towar_id")
  275. kategoria = getElementData(source,"towar_kategoria")
  276. czas = getElementData(source,"towar_czas")
  277. tak, nie = outputMessage("Czy chcesz załadować towar "..towar.."?","info","",true)
  278. end
  279.  
  280. function getWynagrodzenie(app)
  281.     return tonumber(tow.przesylki[app].min) or tonumber(0), tonumber(tow.przesylki[app].max) or tonumber(5000)
  282. end
  283.  
  284. function zaladuj(towar,kategoria,czas,waga,typ)
  285. outputMessage("Trwa ładowanie towaru..","info","",false)
  286. loadingTimer = exports.missiontimer:createMissionTimer((czas*60000),true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255)
  287. addEventHandler("onClientMissionTimerElapsed", loadingTimer, loadingEnd)
  288. setElementData(localPlayer,"laduje",true)
  289.     ladTimer = setTimer(function()
  290.         triggerServerEvent("TruckWorld_ZaladunekPrzetworz",localPlayer,localPlayer,marid,towar,kategoria,waga,typ,czas)
  291.         outputMessage("Pomyślie załadowano","info","",false)
  292.         odczekajTimer = exports.missiontimer:createMissionTimer((5*60000),true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255)
  293.         addEventHandler("onClientMissionTimerElapsed", odczekajTimer, odczekajEnd)
  294.         setElementData(localPlayer,"laduje",false)
  295.         setElementData(veh,"rozladowac_moze",false)
  296.         triggerServerEvent("blokujJazde",localPlayer,localPlayer,"Nie")
  297.     end,(czas*60000),1)
  298. end
  299.  
  300. addEvent("towar_pasek",true)
  301. addEventHandler("towar_pasek",root,
  302.     function(pojazd,towar,kategoria,waga,typ)
  303.         if typ == "Skrypt" then
  304.             local x,y,z = getElementPosition(getMarkerByID(getElementData(pojazd,"rozladunek_id")))
  305.             renderTowar_new("Towar: "..towar..", kategoria: "..kategoria..", waga: "..waga.." kg, cel: "..getZoneName(x,y,z).."("..getElementData(pojazd,"rozladunek_id")..")")
  306.         else
  307.             renderTowar_new("Towar: "..towar..", kategoria: "..kategoria..", waga: "..waga.." kg")
  308.         end
  309.     end
  310. )
  311.  
  312. function rozladuj()
  313. triggerServerEvent("blokujJazde",localPlayer,localPlayer,"Tak")
  314. guiSetVisible(rozladunki_window,false)
  315. showCursor(false)
  316. outputMessage("Trwa rozładowywanie towaru..","info","",false)
  317. loadingTimer = exports.missiontimer:createMissionTimer((getElementData(veh,"czas")*60000),true,"%m:%s",0.5,20,true,"default-bold",1,255,255,255)
  318. addEventHandler("onClientMissionTimerElapsed", loadingTimer, loadingEnd)
  319. setElementData(localPlayer,"rozladowywuje",true)
  320.     ladTimer = setTimer(function()
  321.         local min,max = getWynagrodzenie(getElementData(veh,"towar"))
  322.         local gwarantowane = math.random(min,max)
  323.         triggerServerEvent("TruckWorld_RozladunekPrzetworz",localPlayer,localPlayer,veh,gwarantowane)
  324.         setElementData(localPlayer,"rozladowywuje",false)
  325.         setElementData(veh,"rozladowac_moze",false)
  326.         triggerServerEvent("blokujJazde",localPlayer,localPlayer,"Nie")
  327.         renderTowar_new(false)
  328.     end,(getElementData(veh,"czas")*60000),1)
  329. end
  330.  
  331. function loadingEnd()
  332. destroyElement(source)
  333. end
  334.  
  335. function odczekajEnd()
  336. destroyElement(source)
  337. setElementData(veh,"rozladowac_moze",true)
  338. outputMessage("Już możesz rozładować swój towar","info","",false)
  339. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement