Advertisement
Filexdoj

client.lua

Mar 27th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.45 KB | None | 0 0
  1. local list = {
  2.     BoneCountry = {
  3.         {
  4.             arrivalLocation = "Bone Country",
  5.             model = "Andromada",
  6.             incomeLevel = 4
  7.         },
  8.         {
  9.             arrivalLocation = "Bone Country",
  10.             model = "Shamal",
  11.             incomeLevel = 2
  12.         },
  13.         {
  14.             arrivalLocation = "Bone Country",
  15.             model = "Dodo",
  16.             incomeLevel = 1.5
  17.         }
  18.     },
  19.     LosSantos = {
  20.         {
  21.             arrivalLocation = "Los Santos",
  22.             model = "Andromada",
  23.             incomeLevel = 4
  24.         },
  25.         {
  26.             arrivalLocation = "Los Santos",
  27.             model = "AT-400",
  28.             incomeLevel = 3.5
  29.         },
  30.         {
  31.             arrivalLocation = "Los Santos",
  32.             model = "Shamal",
  33.             incomeLevel = 2
  34.         },
  35.         {
  36.             arrivalLocation = "Los Santos",
  37.             model = "Dodo",
  38.             incomeLevel = 1.5
  39.         }
  40.     },
  41.     SanFierro = {
  42.         {
  43.             arrivalLocation = "San Fierro",
  44.             model = "Andromada",
  45.             incomeLevel = 4
  46.         },
  47.         {
  48.             arrivalLocation = "San Fierro",
  49.             model = "AT-400",
  50.             incomeLevel = 3.5
  51.         },
  52.         {
  53.             arrivalLocation = "San Fierro",
  54.             model = "Shamal",
  55.             incomeLevel = 2
  56.         },
  57.         {
  58.             arrivalLocation = "San Fierro",
  59.             model = "Dodo",
  60.             incomeLevel = 1.5
  61.         }
  62.     },
  63.     LasVenturas = {
  64.         {
  65.             arrivalLocation = "Las Venturas",
  66.             model = "Andromada",
  67.             incomeLevel = 4
  68.         },
  69.         {
  70.             arrivalLocation = "Las Venturas",
  71.             model = "AT-400",
  72.             incomeLevel = 3.5
  73.         },
  74.         {
  75.             arrivalLocation = "Las Venturas",
  76.             model = "Shamal",
  77.             incomeLevel = 2
  78.         },
  79.         {
  80.             arrivalLocation = "Las Venturas",
  81.             model = "Dodo",
  82.             incomeLevel = 1.5
  83.         }
  84.     }
  85. }
  86. local arriveMarkerPositions = {
  87.     BoneCountry = {
  88.         Vector3(46.9, 2504, 15.5),
  89.         Vector3(106.2, 2504, 15.5),
  90.         Vector3(159.2, 2504, 15.5),
  91.         Vector3(214.2, 2504, 15.5),
  92.         Vector3(261.7, 2504, 15.5),
  93.         Vector3(310.7, 2504, 15.5),
  94.         Vector3(358.89, 2504, 15.5),
  95.         Vector3(406, 2504, 15.5)
  96.     },
  97.     LosSantos = {
  98.         Vector3(1468.6, -2592.6, 12.5),
  99.         Vector3(1509.0, -2592.6, 12.5),
  100.         Vector3(1568.8, -2592.6, 12.5),
  101.         Vector3(1628.9, -2592.6, 12.5),
  102.         Vector3(1717.5, -2592.6, 12.5),
  103.         Vector3(1798.6, -2592.6, 12.5),
  104.         Vector3(1890.5, -2592.6, 12.5),
  105.         Vector3(1953.2, -2592.6, 12.5),
  106.         Vector3(1953.2, -2592.6, 12.5)
  107.     },
  108.     SanFierro = {
  109.         Vector3(-1086.5, 406.2, 14.1),
  110.         Vector3(-1132.2, 360.399, 14.1),
  111.         Vector3(-1177.5, 315.799, 14.1),
  112.         Vector3(-1223.8, 269, 14.1),
  113.         Vector3(-1282.4, 209.5, 14.1),
  114.         Vector3(-1338.4, 154.2, 14.1),
  115.         Vector3(-1403.9, 88.8, 14.1),
  116.         Vector3(-1448.5, 44.2, 14.1),
  117.         Vector3(-1494.8, -2.2, 14.1),
  118.         Vector3(-1543.3, -50.6, 14.1),
  119.         Vector3(-1588.2, -96.2, 14.1),
  120.         Vector3(-1623.2, -130.2, 14.1),
  121.         Vector3(-1653.8, -161.7, 14.1)
  122.     },
  123.     LasVenturas = {
  124.         Vector3(1477.4, 1755.1, 10.8),
  125.         Vector3(1477.4, 1691.2, 10.8),
  126.         Vector3(1477.4, 1617.2, 10.8),
  127.         Vector3(1477.4, 1553, 10.8),
  128.         Vector3(1477.4, 1468, 10.8),
  129.         Vector3(1477.4, 1392, 10.8),
  130.         Vector3(1477.4, 1303.6, 10.8),
  131.         Vector3(1443.2, 1260.6, 10.8)
  132.     }
  133. }
  134. local positionNumber = 1
  135. local pilotTabElements = {}
  136. local startLocation
  137. local arriveLocation
  138. local model
  139. local income
  140. local arriveMarker
  141. local arriveBlip
  142.  
  143. function createTabElements()
  144.     local screenW, screenH = guiGetScreenSize()
  145.     pilotTabElements.window =
  146.         GuiWindow((screenW - 474) / 2, (screenH - 296) / 2, 474, 296, "Airport - Pilot Tab", false)
  147.     pilotTabElements.window:setSizable(false)
  148.     pilotTabElements.window:setMovable(false)
  149.     pilotTabElements.gridList = GuiGridList(13, 28, 451, 212, false, pilotTabElements.window)
  150.     pilotTabElements.gridList:addColumn("Arrive Location", 0.3)
  151.     pilotTabElements.gridList:addColumn("Plane Model", 0.3)
  152.     pilotTabElements.gridList:addColumn("Income", 0.3)
  153.     pilotTabElements.closeButton = GuiButton(14, 250, 183, 32, "Close", false, pilotTabElements.window)
  154.     pilotTabElements.startButton = GuiButton(207, 250, 257, 32, "Start", false, pilotTabElements.window)
  155. end
  156.  
  157. function getIncome(location, incomeLevel)
  158.     -- this gets an income based on the distance between the player and the arrive marker
  159.     local playerPosition = getLocalPlayer():getPosition()
  160.     local distance = getDistanceBetweenPoints3D(playerPosition, arriveMarkerPositions[location][1])
  161.     distance = math.floor(distance)
  162.     income = distance * incomeLevel
  163.     income = math.random(income, income + 2000)
  164.     return income
  165. end
  166.  
  167. function createPilotTab(startMarkerLocation)
  168.     startLocation = startMarkerLocation
  169.     createTabElements()
  170.     showCursor(true)
  171.     for location, valueTables in pairs(list) do
  172.         if location ~= startLocation then
  173.             for _index, informations in pairs(valueTables) do
  174.                 if  startLocation == "BoneCountry" then
  175.                     if informations["model"] ~= "AT-400" then
  176.                         pilotTabElements.gridList:addRow(
  177.                             informations["arrivalLocation"],
  178.                             informations["model"],
  179.                             getIncome(location, informations["incomeLevel"])
  180.                         )
  181.                     end
  182.                 else
  183.                     pilotTabElements.gridList:addRow(
  184.                         informations["arrivalLocation"],
  185.                         informations["model"],
  186.                         getIncome(location, informations["incomeLevel"])
  187.                     )
  188.                 end
  189.             end
  190.         end
  191.     end
  192.     addEventHandler("onClientGUIClick", pilotTabElements.closeButton, onCloseButtonClick, false)
  193.     addEventHandler("onClientGUIClick", pilotTabElements.startButton, onStartButtonClick, false)
  194. end
  195. addEvent("create:pilotTab", true)
  196. addEventHandler("create:pilotTab", getRootElement(), createPilotTab)
  197.  
  198. function onCloseButtonClick()
  199.     pilotTabElements.window:destroy()
  200.     pilotTabElements = {}
  201.     showCursor(false)
  202. end
  203.  
  204. function onStartButtonClick()
  205.     local selectedRow, selectedColumn = pilotTabElements.gridList:getSelectedItem()
  206.     if selectedRow ~= -1 and selectedColumn ~= -1 then
  207.         arriveLocation = pilotTabElements.gridList:getItemText(selectedRow, selectedColumn)
  208.         arriveLocation = arriveLocation:gsub(" ", "")
  209.         model = pilotTabElements.gridList:getItemText(selectedRow, selectedColumn + 1)
  210.         income = pilotTabElements.gridList:getItemText(selectedRow, selectedColumn + 2)
  211.         pilotTabElements.window:destroy()
  212.         pilotTabElements = {}
  213.         triggerServerEvent("make:plane", getLocalPlayer(), startLocation, model)
  214.         triggerEvent("start:flight", getLocalPlayer())
  215.         showCursor(false)
  216.     else
  217.         return outputChatBox("Please specify a flight.", 255, 0, 0)
  218.     end
  219. end
  220.  
  221. function startFlight()
  222.     arriveMarker = Marker(arriveMarkerPositions[arriveLocation][1])
  223.     arriveBlip = Blip.createAttachedTo(arriveMarker)
  224.     addEventHandler("stop:flight", getLocalPlayer(), stopFlight)
  225.     addEventHandler("onClientMarkerHit", arriveMarker, onArriveMarkerHit)
  226. end
  227. addEvent("start:flight")
  228. addEventHandler("start:flight", getLocalPlayer(), startFlight)
  229.  
  230. function stopFlight()
  231.     arriveBlip:destroy()
  232.     arriveMarker:destroy()
  233.     local handler = getEventHandlers("stop:flight", getLocalPlayer())
  234.     removeEventHandler("stop:flight", getLocalPlayer(), handler[1])
  235. end
  236. addEvent("stop:flight", true)
  237.  
  238. function onArriveMarkerHit()
  239.     if positionNumber == #arriveMarkerPositions[arriveLocation] then
  240.         local handler = getEventHandlers("stop:flight", getLocalPlayer())
  241.         removeEventHandler("stop:flight", getLocalPlayer(), handler[1])
  242.         triggerServerEvent("give:salary", getLocalPlayer(), income)
  243.         arriveBlip:destroy()
  244.         arriveMarker:destroy()
  245.         positionNumber = 1
  246.     else
  247.         positionNumber = positionNumber + 1
  248.         arriveMarker:setPosition(arriveMarkerPositions[arriveLocation][positionNumber])
  249.     end
  250. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement