RyanUSNS

SOEvents - Client

Dec 10th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.91 KB | None | 0 0
  1. ------------------------------------------------------------------------------------
  2. --  PROJECT:     Community, Integrity, Transparency
  3. --  RIGHTS:      All rights reserved by developers
  4. --  FILE:        CITsoEvents/soevents.lua
  5. --  PURPOSE:     State official events - Client side
  6. --  DEVELOPERS:  Ryan#USNS (IRC: Ryan1)
  7. ------------------------------------------------------------------------------------
  8.  
  9. local t = function(...) return exports.CITt:t(...) or arg[1] or "error" end
  10. local progressTimer = nil
  11. local missionsInfo = {}
  12.  
  13. function createEventGUI()
  14.     local screenW, screenH = guiGetScreenSize()
  15.     eventsWindow = guiCreateWindow((screenW - 420) / 2, (screenH - 367) / 2, 420, 367, t("State Official Event Panel"), false)
  16.     guiWindowSetSizable(eventsWindow, false)
  17.     guiSetAlpha(eventsWindow, 1.00)
  18.     guiSetVisible(eventsWindow, false)
  19.     eventsCombo = guiCreateComboBox(164, 25, 246, 84, "", false, eventsWindow)
  20.     missionsInfo = {
  21.         ["Delivery Clothes"] = t("Requires a Trucker vehicle. You will take the clothes from a place and deliver it to the clothes shop with 95%%+ or you will have to re-take the clothes, if you leave your vehicle, you must re-take the mission. First one to finish the mission wins."),
  22.         ["Delivery Glasses"] = t("Requires a Delivery Man vehicle, you will take the glass from a place and deliver it to the shop with 95%%+ or you will have to re-take the glass, if you leave your vehicle, you must re-take the mission. First one to deliver it wins."),
  23.         ["Mystery Box"] = t("An SO will place the Mystery Box in a hidden place on the map and  then civilians will try to find it. First one to find it, wins the prize provided by State Official."),
  24.     }
  25.     for name, info in pairs(missionsInfo) do
  26.         guiComboBoxAddItem(eventsCombo, name)
  27.     end
  28.     helpLabel1 = guiCreateLabel(10, 25, 144, 23, t("Select event from box:"), false, eventsWindow)
  29.     guiLabelSetVerticalAlign(helpLabel1, "center")
  30.     infoLabelB = guiCreateLabel(10, 48, 400, 61, t("No event selected..."), false, eventsWindow)
  31.     guiLabelSetHorizontalAlign(infoLabelB, "left", true)
  32.     mainTabPanel = guiCreateTabPanel(10, 109, 400, 171, false, eventsWindow)
  33.     -- Pickup information tab
  34.     pickupTab = guiCreateTab(t("Pickup informations"), mainTabPanel)
  35.     pickCoordsLabel = guiCreateLabel(10, 45, 72, 26, t("Coordinates:"), false, pickupTab)
  36.     guiLabelSetVerticalAlign(pickCoordsLabel, "center")
  37.     pickCoordsEdit = guiCreateEdit(82, 44, 308, 26, "", false, pickupTab)
  38.     guiEditSetReadOnly(pickCoordsEdit, true)
  39.     getPickPosButton = guiCreateButton(10, 9, 380, 25, t("Get my Position"), false, pickupTab)
  40.     pickLocLabel = guiCreateLabel(10, 75, 72, 26, t("Location:"), false, pickupTab)
  41.     guiLabelSetHorizontalAlign(pickLocLabel, "center", false)
  42.     guiLabelSetVerticalAlign(pickLocLabel, "center")
  43.     pickBlipLabel = guiCreateLabel(10, 106, 72, 26, t("Blip ID:"), false, pickupTab)
  44.     guiLabelSetHorizontalAlign(pickBlipLabel, "center", false)
  45.     guiLabelSetVerticalAlign(pickBlipLabel, "center")
  46.     pickLocEdit = guiCreateEdit(82, 75, 308, 26, "", false, pickupTab)
  47.     guiEditSetReadOnly(pickLocEdit, true)
  48.     pickBlipEdit = guiCreateEdit(82, 106, 308, 26, "53", false, pickupTab)
  49.     -- Delivery information tab
  50.     deliveryTab = guiCreateTab(t("Delivery informations"), mainTabPanel)
  51.     delCoordsLabel = guiCreateLabel(10, 45, 72, 26, t("Coordinates:"), false, deliveryTab)
  52.     guiLabelSetVerticalAlign(delCoordsLabel, "center")
  53.     delCoordsEdit = guiCreateEdit(82, 44, 308, 26, "", false, deliveryTab)
  54.     guiEditSetReadOnly(delCoordsEdit, true)
  55.     getDelPosButton = guiCreateButton(10, 9, 380, 25, t("Get my Position"), false, deliveryTab)
  56.     delLocLabel = guiCreateLabel(10, 75, 72, 26, t("Location:"), false, deliveryTab)
  57.     guiLabelSetHorizontalAlign(delLocLabel, "center", false)
  58.     guiLabelSetVerticalAlign(delLocLabel, "center")
  59.     delBlipLabel = guiCreateLabel(10, 106, 72, 26, t("Blip ID:"), false, deliveryTab)
  60.     guiLabelSetHorizontalAlign(delBlipLabel, "center", false)
  61.     guiLabelSetVerticalAlign(delBlipLabel, "center")
  62.     delLocEdit = guiCreateEdit(82, 75, 308, 26, "", false, deliveryTab)
  63.     guiEditSetReadOnly(delLocEdit, true)
  64.     delBlipEdit = guiCreateEdit(82, 106, 308, 26, "53", false, deliveryTab)
  65.     -- Other controls
  66.     startEventButton = guiCreateButton(297, 290, 113, 27, t("Start Event"), false, eventsWindow)
  67.     stopEventButton = guiCreateButton(10, 332, 113, 27, t("Stop Event"), false, eventsWindow)
  68.     clearInfoButton = guiCreateButton(157, 332, 113, 27, t("Clear Informations"), false, eventsWindow)
  69.     closeButton = guiCreateButton(297, 332, 113, 27, t("Close Window"), false, eventsWindow)
  70.     timeEdit = guiCreateEdit(157, 290, 113, 27, t("Time"), false, eventsWindow)
  71.     amountEdit = guiCreateEdit(10, 290, 113, 27, t("Reward Amount"), false, eventsWindow)
  72.     guiSetProperty(timeEdit, "ValidationString", "^[0-9]*$")
  73.     guiSetProperty(amountEdit, "ValidationString", "^[0-9]*$")
  74.     guiSetProperty(delBlipEdit, "ValidationString", "^[0-9]*$")
  75.     guiSetProperty(pickBlipEdit, "ValidationString", "^[0-9]*$")
  76.     --Progress Bar
  77.     progressBar = guiCreateProgressBar((screenW/2) - 350,(screenH/2) - 25, 700, 57, false)
  78.     guiSetVisible(progressBar, false)
  79.     -- Event handlers
  80.     addEventHandler("onClientGUIClick", closeButton, toggleWindow, false)
  81.     addEventHandler("onClientGUIClick", startEventButton, startEvent, false)
  82.     addEventHandler("onClientGUIClick", stopEventButton, cancelThisEvent, false)
  83.     addEventHandler("onClientGUIClick", clearInfoButton, resetData, false)
  84.     addEventHandler("onClientGUIClick", getPickPosButton, insertCoordinates, false)
  85.     addEventHandler("onClientGUIClick", getDelPosButton, insertCoordinates, false)
  86.     addEventHandler("onClientGUIComboBoxAccepted", eventsCombo, selectMission, false)
  87.     addEventHandler("onClientGUIClick", timeEdit, clearEdit, false)
  88.     addEventHandler("onClientGUIClick", amountEdit, clearEdit, false)
  89. end
  90.  
  91.  
  92. function toggleWindow()
  93.     if (not eventsWindow) then
  94.         createEventGUI()
  95.     end
  96.     local state = not guiGetVisible(eventsWindow)
  97.     guiSetVisible(eventsWindow, state)
  98.     showCursor(state)
  99. end
  100. addEvent("CITsoEvents.toggleWindow", true)
  101. addEventHandler("CITsoEvents.toggleWindow", root, toggleWindow)
  102.  
  103. function startEvent()
  104.     local r = guiComboBoxGetSelected(eventsCombo)
  105.     if (r < 0) then
  106.         outputChatBox("Please select an event from combo box.", 255, 0, 0)
  107.         return false
  108.     end
  109.     if (getElementDimension(localPlayer) ~= 0) then
  110.         outputChatBox("You need to be in main dimension to create events.", 200, 0, 0)
  111.         return false
  112.     end
  113.     local p = split(guiGetText(pickCoordsEdit):gsub(" ", ""), ",")
  114.     if (#p < 3) then
  115.         outputChatBox("Please enter pickup coordinates.", 255, 0, 0)
  116.         return false
  117.     end
  118.     local px, py, pz, pBlip = p[1], p[2], p[3], guiGetText(pickBlipEdit)
  119.     if (not tonumber(pBlip)) then
  120.         return false
  121.     end
  122.     local timer = guiGetText(timeEdit)
  123.     local reward = guiGetText(amountEdit)
  124.     local eventName = guiComboBoxGetItemText(eventsCombo, r)
  125.     local info = guiGetText(infoLabelB)
  126.     if (tonumber(pBlip) > 63) then
  127.         outputChatBox("The blip ID can only be between 0-63.", 255, 0, 0)
  128.         return false
  129.     end
  130.     if (not tonumber(timer) or timer == "" or tonumber(timer) == 0) then
  131.         outputChatBox("Please enter time in minutes at second edit box.", 255, 0, 0)
  132.         return false
  133.     end
  134.     if (not tonumber(reward) or reward == "") then
  135.         outputChatBox("Please enter prize money in first edit box.", 255, 0, 0)
  136.         return false
  137.     end
  138.     if (tonumber(reward) > 100000) then
  139.         outputChatBox("Maximum prize is $100,000.", 255, 0, 0)
  140.         return false
  141.     end
  142.     if (tonumber(reward) < 1000) then
  143.         outputChatBox("Minimum prize is $1,000.", 255, 0, 0)
  144.         return false
  145.     end
  146.     if (eventName == "Mystery Box") then
  147.         triggerServerEvent("CITsoEvents.startMission", resourceRoot, eventName, info, reward, timer, px, py, pz)
  148.         resetData()
  149.         return true
  150.     end
  151.     local d = split(guiGetText(delCoordsEdit):gsub(" ", ""), ",")
  152.     if (#d < 3) then
  153.         outputChatBox("Please enter delivery coordinates.", 255, 0, 0)
  154.         return false
  155.     end
  156.     local dx, dy, dz, dBlip = d[1], d[2], d[3], guiGetText(delBlipEdit)
  157.     if (tonumber(dBlip) > 63) then
  158.         outputChatBox("The blip ID can only be between 0-63.", 255, 0, 0)
  159.         return false
  160.     end
  161.     if (getDistanceBetweenPoints2D(px, py, dx, dy) <= 100) then
  162.         outputChatBox("The delivery position is very close to pickup position, pick different delivery position.", 200, 0, 0)
  163.         return false
  164.     end
  165.     triggerServerEvent("CITsoEvents.startMission", resourceRoot, eventName, info, reward, timer, px, py, pz, pBlip, dx, dy, dz, dBlip)
  166.     resetData()
  167. end
  168.  
  169. function cancelThisEvent()
  170.     triggerServerEvent("CITsoEvents.stopEvent", resourceRoot)
  171. end
  172.  
  173. function resetData()
  174.     guiSetText(pickCoordsEdit, "")
  175.     guiSetText(pickLocEdit, "")
  176.     guiSetText(delCoordsEdit, "")
  177.     guiSetText(delLocEdit, "")
  178.     guiSetText(infoLabelB, t("No event selected..."))
  179.     guiSetText(pickBlipEdit, "53")
  180.     guiSetText(delBlipEdit, "53")
  181.     guiSetText(amountEdit, t("Reward Amount"))
  182.     guiSetText(timeEdit, t("Time"))
  183.     guiComboBoxSetSelected(eventsCombo, -1)
  184. end
  185.  
  186. function insertCoordinates()
  187.     local x, y, z = getElementPosition(localPlayer)
  188.     local city = getZoneName(x, y, z, true)
  189.     local zone = getZoneName(x, y, z)
  190.     if (source == getPickPosButton) then
  191.         guiSetText(pickCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
  192.         guiSetText(pickLocEdit, city..", "..zone)
  193.         return true
  194.     end
  195.     guiSetText(delCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
  196.     guiSetText(delLocEdit, city..", "..zone)
  197. end
  198.  
  199. function selectMission()
  200.     local r = guiComboBoxGetSelected(eventsCombo)
  201.     local name = guiComboBoxGetItemText(eventsCombo, r)
  202.     missionsInfo = {
  203.         ["Delivery Clothes"] = "Requires a Trucker vehicle. You will take the clothes from a place and deliver it to the clothes shop with 95%%+ or you will have to re-take the clothes, if you leave your vehicle, you must re-take the mission. First one to finish the mission wins.",
  204.         ["Delivery Glasses"] = "Requires a Delivery Man vehicle, you will take the glass from a place and deliver it to the shop with 95%%+ or you will have to re-take the glass, if you leave your vehicle, you must re-take the mission. First one to deliver it wins.",
  205.         ["Mystery Box"] = "An SO will place the Mystery Box in a hidden place on the map and  then civilians will try to find it. First one to find it, wins the prize provided by State Official.",
  206.     }
  207.     guiSetText(infoLabelB, (missionsInfo[name] or "Couldn't fetch info, select again."))
  208. end
  209.  
  210. function clearEdit()
  211.     local text = guiGetText(source)
  212.     if (text == t("Time") or text == t("Reward Amount")) then
  213.         guiSetText(source, "")
  214.     end
  215. end
  216.  
  217. function loadingCargoDG()
  218.     if (not progressBar) then
  219.         createEventGUI()
  220.     end
  221.     setElementData(localPlayer, "lc", 1)
  222.     guiSetVisible(progressBar, true)
  223.     progressTimer = setTimer(addProgress, 100, 100)
  224.     exports.CIThelp:modTextBar("loadingCargo", t("Loading cargo..."), 255, 167, 0)
  225. end
  226. addEvent("CITsoEvents.addProgressBar", true)
  227. addEventHandler("CITsoEvents.addProgressBar", root, loadingCargoDG)
  228.  
  229. function addProgress()     
  230.     guiProgressBarSetProgress(progressBar, guiProgressBarGetProgress(progressBar) + 1)                 
  231.     if (guiProgressBarGetProgress(progressBar) == 100) then
  232.         triggerServerEvent("CITsoEvents.showMarker", resourceRoot)
  233.         guiSetVisible(progressBar, false)
  234.         guiProgressBarSetProgress(progressBar, 0)
  235.         progressTimer = nil
  236.         setElementData(localPlayer, "lc", nil)
  237.         exports.CIThelp:modTextBar("loadingCargo", "")
  238.     end
  239. end
  240.  
  241. function killProgressBar()
  242.     if (not progressBar) then
  243.         return false
  244.     end
  245.     if (progressTimer) then
  246.         killTimer(progressTimer)
  247.         progressTimer = nil
  248.     end
  249.     guiSetVisible(progressBar, false)
  250.     guiProgressBarSetProgress(progressBar, 0)
  251. end
  252. addEvent("CITsoEvents.killProgressBar", true)
  253. addEventHandler("CITsoEvents.killProgressBar", root, killProgressBar)
  254.  
  255. function outputEventMessage(str)
  256.     if (tostring(getElementData(localPlayer, "CITset.eventoutput")) == "Yes") then
  257.         outputChatBox(str, 255, 167, 0)
  258.     end
  259. end
  260. addEvent("CITsoEvents.OEM", true)
  261. addEventHandler("CITsoEvents.OEM", root, outputEventMessage)
Advertisement
Add Comment
Please, Sign In to add comment