Advertisement
Filexdoj

pilotClient.lua

Mar 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.90 KB | None | 0 0
  1. local screenW, screenH = guiGetScreenSize()
  2. local dimensions = {
  3.     window = {
  4.         floatX = (screenW - 474) / 2,
  5.         floatY = (screenH - 296) / 2,
  6.         width = 474,
  7.         height = 296
  8.     },
  9.     gridList = {
  10.         floatX = 13,
  11.         floatY = 28,
  12.         width = 451,
  13.         height = 212
  14.     },
  15.     closeButton = {
  16.         floatX = 14,
  17.         floatY = 250,
  18.         width = 183,
  19.         height = 32
  20.     },
  21.     startButton = {
  22.         floatX = 207,
  23.         floatY = 250,
  24.         width = 257,
  25.         height = 32
  26.     }
  27. }
  28.  
  29. function round(num, numDecimalPlaces)
  30.     local mult = 10 ^ (numDecimalPlaces or 0)
  31.     return math.floor(num * mult + 0.5) / mult
  32. end
  33.  
  34. local list = {
  35.     BoneCountry = {
  36.         {
  37.             "Bone Country",
  38.             "Andromada",
  39.             4
  40.         },
  41.         {
  42.             "Bone Country",
  43.             "AT400",
  44.             3.5
  45.         },
  46.         {
  47.             "Bone Country",
  48.             "Shamal",
  49.             2
  50.         },
  51.         {
  52.             "Bone Country",
  53.             "Dodo",
  54.             1.5
  55.         }
  56.     },
  57.     LosSantos = {
  58.         {
  59.             "Los Santos",
  60.             "Andromada",
  61.             4
  62.         },
  63.         {
  64.             "Los Santos",
  65.             "AT400",
  66.             3.5
  67.         },
  68.         {
  69.             "Los Santos",
  70.             "Shamal",
  71.             2
  72.         },
  73.         {
  74.             "Los Santos",
  75.             "Dodo",
  76.             1.5
  77.         }
  78.     },
  79.     SanFierro = {
  80.         {
  81.             "San Fierro",
  82.             "Andromada",
  83.             4
  84.         },
  85.         {
  86.             "San Fierro",
  87.             "AT400",
  88.             3.5
  89.         },
  90.         {
  91.             "San Fierro",
  92.             "Shamal",
  93.             2
  94.         },
  95.         {
  96.             "San Fierro",
  97.             "Dodo",
  98.             1.5
  99.         }
  100.     },
  101.     LasVenturas = {
  102.         {
  103.             "Las Venturas",
  104.             "Andromada",
  105.             4
  106.         },
  107.         {
  108.             "Las Venturas",
  109.             "AT400",
  110.             3.5
  111.         },
  112.         {
  113.             "Las Venturas",
  114.             "Shamal",
  115.             2
  116.         },
  117.         {
  118.             "Las Venturas",
  119.             "Dodo",
  120.             1.5
  121.         }
  122.     }
  123. }
  124. local arriveMarkerPositions = {
  125.     BoneCountry = {
  126.         {x = 46.9, y = 2504, z = 15.5},
  127.         {x = 106.2, y = 2504, z = 15.5},
  128.         {x = 159.2, y = 2504, z = 15.5},
  129.         {x = 214.2, y = 2504, z = 15.5},
  130.         {x = 261.7, y = 2504, z = 15.5},
  131.         {x = 310.7, y = 2504, z = 15.5},
  132.         {x = 358.89, y = 2504, z = 15.5},
  133.         {x = 406, y = 2504, z = 15.5}
  134.     },
  135.     LosSantos = {
  136.         {x = 1468.6, y = -2592.6, z = 12.5},
  137.         {x = 1509.0, y = -2592.6, z = 12.5},
  138.         {x = 1568.8, y = -2592.6, z = 12.5},
  139.         {x = 1628.9, y = -2592.6, z = 12.5},
  140.         {x = 1717.5, y = -2592.6, z = 12.5},
  141.         {x = 1798.6, y = -2592.6, z = 12.5},
  142.         {x = 1890.5, y = -2592.6, z = 12.5},
  143.         {x = 1953.2, y = -2592.6, z = 12.5},
  144.         {x = 1953.2, y = -2592.6, z = 12.5}
  145.     },
  146.     SanFierro = {
  147.         {x = -1086.5, y = 406.2, z = 14.1},
  148.         {x = -1132.2, y = 360.399, z = 14.1},
  149.         {x = -1177.5, y = 315.799, z = 14.1},
  150.         {x = -1223.8, y = 269, z = 14.1},
  151.         {x = -1282.4, y = 209.5, z = 14.1},
  152.         {x = -1338.4, y = 154.2, z = 14.1},
  153.         {x = -1403.9, y = 88.8, z = 14.1},
  154.         {x = -1448.5, y = 44.2, z = 14.1},
  155.         {x = -1494.8, y = -2.2, z = 14.1},
  156.         {x = -1543.3, y = -50.6, z = 14.1},
  157.         {x = -1588.2, y = -96.2, z = 14.1},
  158.         {x = -1623.2, y = -130.2, z = 14.1},
  159.         {x = -1653.8, y = -161.7, z = 14.1}
  160.     },
  161.     LasVenturas = {
  162.         {x = 1477.4, y = 1755.1, z = 10.8},
  163.         {x = 1477.4, y = 1691.2, z = 10.8},
  164.         {x = 1477.4, y = 1617.2, z = 10.8},
  165.         {x = 1477.4, y = 1553, z = 10.8},
  166.         {x = 1477.4, y = 1468, z = 10.8},
  167.         {x = 1477.4, y = 1392, z = 10.8},
  168.         {x = 1477.4, y = 1303.6, z = 10.8},
  169.         {x = 1443.2, y = 1260.6, z = 10.8}
  170.     }
  171. }
  172. function pilotTab(location, distances)
  173.     showCursor(true)
  174.     local window =
  175.         GuiWindow(
  176.         dimensions.window["floatX"],
  177.         dimensions.window["floatY"],
  178.         dimensions.window["width"],
  179.         dimensions.window["height"],
  180.         "Los Santos Airport - Pilot Tab",
  181.         false
  182.     )
  183.     window:setSizable(false)
  184.     window:setMovable(false)
  185.  
  186.     local gridList =
  187.         GuiGridList(
  188.         dimensions.gridList["floatX"],
  189.         dimensions.gridList["floatY"],
  190.         dimensions.gridList["width"],
  191.         dimensions.gridList["height"],
  192.         false,
  193.         window
  194.     )
  195.     gridList:addColumn("Arrive Location", 0.3)
  196.     gridList:addColumn("Plane Model", 0.3)
  197.     gridList:addColumn("Income", 0.3)
  198.     local closeButton =
  199.         GuiButton(
  200.         dimensions.closeButton["floatX"],
  201.         dimensions.closeButton["floatY"],
  202.         dimensions.closeButton["width"],
  203.         dimensions.closeButton["height"],
  204.         "Close",
  205.         false,
  206.         window
  207.     )
  208.     local startButton =
  209.         GuiButton(
  210.         dimensions.startButton["floatX"],
  211.         dimensions.startButton["floatY"],
  212.         dimensions.startButton["width"],
  213.         dimensions.startButton["height"],
  214.         "Start",
  215.         false,
  216.         window
  217.     )
  218.     for k, v in pairs(list) do
  219.         if k ~= location then
  220.             for k2, v2 in ipairs(v) do
  221.                 if location == "BoneCountry" then
  222.                     if v2[2] ~= "AT400" then
  223.                         gridList:addRow(v2[1], v2[2], round(v2[3] * distances[k]))
  224.                     end
  225.                 else
  226.                     gridList:addRow(v2[1], v2[2], round(v2[3] * distances[k]))
  227.                 end
  228.             end
  229.         end
  230.     end
  231.     function onCloseButtonClick()
  232.         window:destroy()
  233.         showCursor(false)
  234.     end
  235.     addEventHandler("onClientGUIClick", closeButton, onCloseButtonClick, false)
  236.  
  237.     function onStartButtonClick()
  238.         local selectedRow, selectedColumn = gridList:getSelectedItem()
  239.         if selectedRow ~= -1 and selectedColumn ~= -1 then
  240.             showCursor(false)
  241.             local arrivalLocation = gridList:getItemText(selectedRow, selectedColumn)
  242.             arrivalLocation = arrivalLocation:gsub(" ", "")
  243.             local planeModel = gridList:getItemText(selectedRow, selectedColumn + 1)
  244.             local income = gridList:getItemText(selectedRow, selectedColumn + 2)
  245.             triggerServerEvent(
  246.                 "makePlane",
  247.                 getRootElement(),
  248.                 getLocalPlayer(),
  249.                 planeModel,
  250.                 location,
  251.                 arrivalLocation,
  252.                 income
  253.             )
  254.             window:destroy()
  255.         else
  256.             return outputChatBox("Please Select a mission.", 255, 20, 20)
  257.         end
  258.     end
  259.     addEventHandler("onClientGUIClick", startButton, onStartButtonClick, false)
  260. end
  261. addEvent("openPilotTab", true)
  262. addEventHandler("openPilotTab", getRootElement(), pilotTab)
  263.  
  264. function startJob(arrivalLocation, income)
  265.     local newPosition
  266.     local i = 1
  267.     local position =
  268.         Vector3(
  269.         arriveMarkerPositions[arrivalLocation][i]["x"],
  270.         arriveMarkerPositions[arrivalLocation][i]["y"],
  271.         arriveMarkerPositions[arrivalLocation][i]["z"]
  272.     )
  273.     local arriveMarker = Marker(position, "checkpoint", 10, 255, 255, 0, 200)
  274.     local blip = Blip.createAttachedTo(arriveMarker)
  275.  
  276.     function stopMission()
  277.         outputChatBox("You have abondand the mission", 255, 0, 0)
  278.         arriveMarker:destroy()
  279.         blip:destroy()
  280.         i = nil
  281.     end
  282.     addEvent("stop:mission", true)
  283.     addEventHandler("stop:mission", getRootElement(), stopMission)
  284.  
  285.     function onArriveMarkerHit()
  286.         if i == #arriveMarkerPositions[arrivalLocation] then
  287.             i = nil
  288.             arriveMarker:destroy()
  289.             blip:destroy()
  290.             triggerServerEvent("getSalary", getRootElement(), income)
  291.         else
  292.             i = i + 1
  293.             newPosition =
  294.                 Vector3(
  295.                 arriveMarkerPositions[arrivalLocation][i]["x"],
  296.                 arriveMarkerPositions[arrivalLocation][i]["y"],
  297.                 arriveMarkerPositions[arrivalLocation][i]["z"]
  298.             )
  299.             arriveMarker:setPosition(newPosition)
  300.         end
  301.     end
  302.     addEventHandler("onClientMarkerHit", arriveMarker, onArriveMarkerHit)
  303.    
  304. end
  305. addEvent("start:job", true)
  306. addEventHandler("start:job", getRootElement(), startJob)
  307.  
  308. addCommandHandler(
  309.     "vehposition",
  310.     function()
  311.         local veh = getLocalPlayer():getOccupiedVehicle()
  312.         local x, y, z = getElementPosition(veh)
  313.         iprint(x, y, z)
  314.         local xr, yr, zr = getElementRotation(veh)
  315.         iprint(x, y, z)
  316.         outputChatBox("x =" .. x .. ", y =" .. y .. ", z =" .. z, 0, 200, 0)
  317.         outputChatBox(", rx =" .. xr .. ", ry =" .. yr .. ", rz =" .. zr, 0, 200, 0)
  318.     end
  319. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement