Guest User

Untitled

a guest
Jan 28th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.10 KB | None | 0 0
  1. local m_dostep="mechanik-sf"
  2.  
  3. local doFixed={
  4.     {"Silnik", 1, fn=function(veh) if getElementHealth(veh)>=2040 then return true end; return false end},
  5.     {"Maska", 2, fn=function(veh) if getVehicleDoorState(veh, 0)==0 then return true end; return false end},
  6.     {"Bagażnik", 3, fn=function(veh) if getVehicleDoorState(veh, 1)==0 then return true end; return false end},
  7.     {"Drzwi lewy przód", 4, fn=function(veh) if getVehicleDoorState(veh, 2)==0 then return true end; return false end},
  8.     {"Drzwi prawy przód", 5, fn=function(veh) if getVehicleDoorState(veh, 3)==0 then return true end; return false end},
  9.     {"Drzwi lewy tył", 6, fn=function(veh) if getVehicleDoorState(veh, 4)==0 then return true end; return false end},
  10.     {"Drzwi prawy tył", 7, fn=function(veh) if getVehicleDoorState(veh, 5)==0 then return true end; return false end},
  11.     {"Szyba przednia", 8, fn=function(veh) if getVehiclePanelState(veh, 4)==0 then return true end; return false end},
  12.     {"Zderzak przedni", 9, fn=function(veh) if getVehiclePanelState(veh, 5)==0 then return true end; return false end},
  13.     {"Zderzak tylni", 10, fn=function(veh) if getVehiclePanelState(veh, 6)==0 then return true end; return false end},
  14.     {"Światło lewe przednie", 11, fn=function(veh) if getVehicleLightState(veh, 0)==0 then return true end; return false end},
  15.     {"Światła prawe przednie", 12, fn=function(veh) if getVehicleLightState(veh, 1)==0 then return true end; return false end},
  16.     {"Światła lewe tylnie", 13, fn=function(veh) if getVehicleLightState(veh, 2)==0 then return true end; return false end},
  17.     {"Światła prawe tylnie", 14, fn=function(veh) if getVehicleLightState(veh, 3)==0 then return true end; return false end},
  18.    
  19. }
  20.  
  21.  
  22. local doCosts ={ [507] = {50, 20, 20, 15, 15, 15, 15, 40, 10, 10, 20, 20, 20, 20},
  23.                  [597] = {40, 30, 15, 25, 30, 45, 32, 61, 20, 10, 64, 44, 52, 39}}
  24.  
  25. local wm={}
  26. local isVehicles=nil
  27. wm.window = guiCreateWindow(0.18, 0.21, 0.64, 0.52, "", true)
  28. guiWindowSetSizable(wm.window, false)
  29. guiSetVisible(wm.window, false)
  30. guiSetAlpha(wm.window, 1.00)
  31. wm.gridlist = guiCreateGridList(0.01, 0.07, 0.97, 0.75, true, wm.window)
  32. guiGridListAddColumn(wm.gridlist, "Nazwa", 0.5)
  33. guiGridListAddColumn(wm.gridlist, "Koszt", 0.5)
  34. guiGridListAddRow(wm.gridlist)
  35. wm.fixall = guiCreateButton(0.75, 0.85, 0.24, 0.11, "Napraw wszystko (200 PLN)", true, wm.window)
  36. wm.fixparts = guiCreateButton(0.02, 0.85, 0.24, 0.11, "Napraw wybraną część", true, wm.window)
  37.  
  38.  
  39. function wybrane()
  40.     local pojazd = getPedOccupiedVehicle(getLocalPlayer())
  41.     local model = getElementModel(pojazd)
  42.     if doCosts[model] then
  43.         local koszt = doCosts[model] [doFixed]  
  44.     end
  45. end
  46.  
  47.  
  48.  
  49. local function refreshGUI()
  50.     if not isVehicles then return end
  51.  
  52.     guiGridListClear(wm.gridlist)
  53.     for i,v in pairs(doFixed) do
  54.         if v.fn(isVehicles)==false then
  55.             local row = guiGridListAddRow(wm.gridlist)
  56.             guiGridListSetItemText(wm.gridlist, row, 1, v[1], false, false)
  57.             guiGridListSetItemData(wm.gridlist, row, 1, i)
  58.             guiGridListSetItemText(wm.gridlist, row, 2, doCosts[i].." PLN", false, false)
  59.             guiGridListSetItemData(wm.gridlist, row, 2, doCosts[i])
  60.         end
  61.     end
  62. end
  63.  
  64. addEventHandler("onClientMarkerHit", resourceRoot, function(el,md)
  65.     if not md or el~=localPlayer then return end
  66.     local cs=getElementData(source, "snn_cs")
  67.     if not cs then return end
  68.     local vehicles=getElementsWithinColShape(cs,"vehicle")
  69.     if #vehicles < 1 then
  70.         outputChatBox("* Na stanowisku naprawczym nie znajduje się pojazd.", 255, 0, 0)
  71.         return
  72.     end
  73.     if #vehicles > 1 then
  74.         outputChatBox("* Na stanowisku naprawczym znajduje się zbyt duża ilość pojazdów.", 255, 0, 0)
  75.         return
  76.     end
  77.     --[[if getElementHealth(vehicles[1]) > 990 then
  78.         outputChatBox("* Pojazd na stanowisku naprawczym jest sprawny.")
  79.         return
  80.     end]]
  81.     showCursor(true, false)
  82.     guiSetVisible(wm.window, true)
  83.     isVehicles = vehicles[1]
  84.     guiGridListClear(wm.gridlist)
  85.     for i,v in pairs(doFixed) do
  86.         if v.fn(isVehicles)==false then
  87.             local row = guiGridListAddRow(wm.gridlist)
  88.             guiGridListSetItemText(wm.gridlist, row, 1, v[1], false, false)
  89.             guiGridListSetItemData(wm.gridlist, row, 1, i)
  90.             guiGridListSetItemText(wm.gridlist, row, 2, doCosts[i].." PLN", false, false)
  91.             guiGridListSetItemData(wm.gridlist, row, 2, doCosts[i])
  92.         end
  93.     end
  94. end)
  95.  
  96. addEventHandler("onClientMarkerLeave", resourceRoot, function(el,md)
  97.     if el~=localPlayer then return end
  98.     guiSetVisible(wm.window, false)
  99.     isVehicles=nil
  100.     showCursor(false)
  101. end)
  102.  
  103. addEventHandler("onClientGUIClick", wm.fixparts, function()
  104.     if not isVehicles or not isElement(isVehicles) then return end
  105.     selectedRow = guiGridListGetSelectedItem(wm.gridlist) or -1
  106.     if selectedRow < 0 then return end
  107.     local cost = guiGridListGetItemData(wm.gridlist, selectedRow, 2)
  108.     if cost > getPlayerMoney(localPlayer) then
  109.         outputChatBox("* Nie posiadasz tyle gotówki!")
  110.         return
  111.     end
  112.  
  113.     local part = guiGridListGetItemData(wm.gridlist, selectedRow, 1)
  114.     outputChatBox('* Naprawiles ' .. tostring(getPartName(doFixed, part)))
  115.     triggerServerEvent("takePlayerMoney", localPlayer, cost)
  116.     triggerServerEvent("montazElementu", root, isVehicles, "naprawa", part, cost)
  117.     setTimer(function()
  118.         refreshGUI()
  119.     end, 200, 2)
  120. end)
  121.  
  122. addEventHandler("onClientGUIClick", wm.fixall, function()
  123.     if not isVehicles or not isElement(isVehicles) then return end
  124.     if 200 > getPlayerMoney(localPlayer) then
  125.         outputChatBox("* Nie posiadasz tyle gotówki!")
  126.         return
  127.     end
  128.  
  129.     local elementyDoNaprawy=0
  130.     for i,v in pairs(doFixed) do
  131.         if v.fn(isVehicles)==false then
  132.             elementyDoNaprawy=elementyDoNaprawy+1
  133.         end
  134.     end
  135.     if elementyDoNaprawy==0 then
  136.         outputChatBox('* Pojazd jest już naprawiony.')
  137.         return
  138.     end
  139.  
  140.     triggerServerEvent("takePlayerMoney", localPlayer, 200)
  141.     outputChatBox('* Naprawiłeś(aś) wszystkie elementy w pojeździe.')
  142.     triggerServerEvent("montazElementu", root, isVehicles, "naprawa", "all", 200)
  143.     setTimer(function()
  144.         refreshGUI()
  145.     end, 200, 2)
  146. end)
  147.  
  148. -- utils
  149. function getPartName(t, key)
  150.     for i,v in pairs(t) do
  151.         if v[2]==key then
  152.             return v[1]
  153.         end
  154.     end
  155. end
  156. fileDelete('c_naprawa.lua')
Advertisement
Add Comment
Please, Sign In to add comment