RyanUSNS

SOEvent Update v3.0 - Client

Apr 5th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.46 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 buttonData
  12. local picking, testMarker, zDifference
  13. local markerInfo = {}
  14.  
  15. function createEventGUI()
  16.     local screenW, screenH = guiGetScreenSize()
  17.     eventsWindow = guiCreateWindow((screenW - 420) / 2, (screenH - 367) / 2, 420, 367, t("State Official Event Panel"), false)
  18.     guiWindowSetSizable(eventsWindow, false)
  19.     guiSetAlpha(eventsWindow, 1.00)
  20.     guiSetVisible(eventsWindow, false)
  21.     eventsCombo = guiCreateComboBox(164, 25, 246, 84, "", false, eventsWindow)
  22.     missionsInfo = {
  23.         ["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."),
  24.         ["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."),
  25.         ["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."),
  26.         ["From Danger to Safety"] = t("Requires a Bus Driver vehicle. You will take the people from a shooting to a safe zone. When the first player delivers them, all other players will have 90 seconds to complete. The bus that received less damage will be the winner."),
  27.         --["Sick Person"] = t("Requires an Ambulance or a Medic Car. People will spawn randomly next to a house and you will need take them to a hospital, chosen by an SO. Who delivers more people to the hospital will be the winner. Time limit: 5 minutes."),
  28.         ["Delivery Fish"] = t("Requires any boat. You will take the fish from the ocean and come back to shore with 95%%+ or you will have to catch the fish again. If you leave your boat, you must restore the mission. The first to complete the mission will be the winner."),
  29.         ["Awesome Bag"] = t("Volunteers will try find a lost bag. If you find it, you must hand it over to the police department or the civilian headquarters."),
  30.     }
  31.     for name, info in pairs(missionsInfo) do
  32.         guiComboBoxAddItem(eventsCombo, name)
  33.     end
  34.     helpLabel1 = guiCreateLabel(10, 25, 144, 23, t("Select event from box:"), false, eventsWindow)
  35.     guiLabelSetVerticalAlign(helpLabel1, "center")
  36.     infoLabelB = guiCreateLabel(10, 48, 400, 61, t("No event selected..."), false, eventsWindow)
  37.     guiLabelSetHorizontalAlign(infoLabelB, "left", true)
  38.     mainTabPanel = guiCreateTabPanel(10, 109, 400, 171, false, eventsWindow)
  39.     -- Pickup information tab
  40.     pickupTab = guiCreateTab(t("Pickup informations"), mainTabPanel)
  41.     pickCoordsLabel = guiCreateLabel(10, 45, 72, 26, t("Coordinates:"), false, pickupTab)
  42.     guiLabelSetVerticalAlign(pickCoordsLabel, "center")
  43.     pickCoordsEdit = guiCreateEdit(82, 44, 308, 26, "", false, pickupTab)
  44.     guiEditSetReadOnly(pickCoordsEdit, true)
  45.     getPickPosButton = guiCreateButton(10, 9, 380, 25, t("Get my Position"), false, pickupTab)
  46.     pickLocLabel = guiCreateLabel(10, 75, 72, 26, t("Location:"), false, pickupTab)
  47.     guiLabelSetHorizontalAlign(pickLocLabel, "center", false)
  48.     guiLabelSetVerticalAlign(pickLocLabel, "center")
  49.     pickBlipLabel = guiCreateLabel(10, 106, 72, 26, t("Blip ID:"), false, pickupTab)
  50.     guiLabelSetHorizontalAlign(pickBlipLabel, "center", false)
  51.     guiLabelSetVerticalAlign(pickBlipLabel, "center")
  52.     pickLocEdit = guiCreateEdit(82, 75, 308, 26, "", false, pickupTab)
  53.     guiEditSetReadOnly(pickLocEdit, true)
  54.     pickBlipEdit = guiCreateEdit(82, 106, 308, 26, "53", false, pickupTab)
  55.     -- Delivery information tab
  56.     deliveryTab = guiCreateTab(t("Delivery informations"), mainTabPanel)
  57.     delCoordsLabel = guiCreateLabel(10, 45, 72, 26, t("Coordinates:"), false, deliveryTab)
  58.     guiLabelSetVerticalAlign(delCoordsLabel, "center")
  59.     delCoordsEdit = guiCreateEdit(82, 44, 308, 26, "", false, deliveryTab)
  60.     guiEditSetReadOnly(delCoordsEdit, true)
  61.     getDelPosButton = guiCreateButton(10, 9, 380, 25, t("Get my Position"), false, deliveryTab)
  62.     delLocLabel = guiCreateLabel(10, 75, 72, 26, t("Location:"), false, deliveryTab)
  63.     guiLabelSetHorizontalAlign(delLocLabel, "center", false)
  64.     guiLabelSetVerticalAlign(delLocLabel, "center")
  65.     delBlipLabel = guiCreateLabel(10, 106, 72, 26, t("Blip ID:"), false, deliveryTab)
  66.     guiLabelSetHorizontalAlign(delBlipLabel, "center", false)
  67.     guiLabelSetVerticalAlign(delBlipLabel, "center")
  68.     delLocEdit = guiCreateEdit(82, 75, 308, 26, "", false, deliveryTab)
  69.     guiEditSetReadOnly(delLocEdit, true)
  70.     delBlipEdit = guiCreateEdit(82, 106, 308, 26, "53", false, deliveryTab)
  71.     -- Other controls
  72.     startEventButton = guiCreateButton(297, 290, 113, 27, t("Start Event"), false, eventsWindow)
  73.     stopEventButton = guiCreateButton(10, 332, 113, 27, t("Stop Event"), false, eventsWindow)
  74.     clearInfoButton = guiCreateButton(157, 332, 113, 27, t("Clear Informations"), false, eventsWindow)
  75.     closeButton = guiCreateButton(297, 332, 113, 27, t("Close Window"), false, eventsWindow)
  76.     timeEdit = guiCreateEdit(157, 290, 113, 27, t("Time"), false, eventsWindow)
  77.     amountEdit = guiCreateEdit(10, 290, 113, 27, t("Reward Amount"), false, eventsWindow)
  78.     guiSetProperty(timeEdit, "ValidationString", "^[0-9]*$")
  79.     guiSetProperty(amountEdit, "ValidationString", "^[0-9]*$")
  80.     guiSetProperty(delBlipEdit, "ValidationString", "^[0-9]*$")
  81.     guiSetProperty(pickBlipEdit, "ValidationString", "^[0-9]*$")
  82.     --Progress Bar
  83.     progressBar = guiCreateProgressBar((screenW/2) - 350,(screenH/2) - 25, 700, 57, false)
  84.     guiSetVisible(progressBar, false)
  85.     -- Event handlers
  86.     addEventHandler("onClientGUIClick", closeButton, toggleWindow, false)
  87.     addEventHandler("onClientGUIClick", startEventButton, startEvent, false)
  88.     addEventHandler("onClientGUIClick", stopEventButton, cancelThisEvent, false)
  89.     addEventHandler("onClientGUIClick", clearInfoButton, resetData, false)
  90.     addEventHandler("onClientGUIClick", getPickPosButton, insertCoordinates, false)
  91.     addEventHandler("onClientGUIClick", getDelPosButton, insertCoordinates, false)
  92.     addEventHandler("onClientGUIComboBoxAccepted", eventsCombo, selectMission, false)
  93.     addEventHandler("onClientGUIClick", timeEdit, clearEdit, false)
  94.     addEventHandler("onClientGUIClick", amountEdit, clearEdit, false)
  95. end
  96.  
  97.  
  98. function toggleWindow()
  99.     if (not eventsWindow) then
  100.         createEventGUI()
  101.     end
  102.     local state = not guiGetVisible(eventsWindow)
  103.     guiSetVisible(eventsWindow, state)
  104.     showCursor(state)
  105. end
  106. addEvent("CITsoEvents.toggleWindow", true)
  107. addEventHandler("CITsoEvents.toggleWindow", root, toggleWindow)
  108.  
  109. function startEvent()
  110.     local r = guiComboBoxGetSelected(eventsCombo)
  111.     if (r < 0) then
  112.         outputChatBox("Please select an event from combo box.", 255, 0, 0)
  113.         return false
  114.     end
  115.     if (getElementDimension(localPlayer) ~= 0) then
  116.         outputChatBox("You need to be in main dimension to create events.", 200, 0, 0)
  117.         return false
  118.     end
  119.     local p = split(guiGetText(pickCoordsEdit):gsub(" ", ""), ",")
  120.     if (#p < 3) then
  121.         outputChatBox("Please enter pickup coordinates.", 255, 0, 0)
  122.         return false
  123.     end
  124.     local px, py, pz, pBlip = p[1], p[2], p[3], guiGetText(pickBlipEdit)
  125.     if (not tonumber(pBlip)) then
  126.         return false
  127.     end
  128.     local timer = guiGetText(timeEdit)
  129.     local reward = guiGetText(amountEdit)
  130.     local eventName = guiComboBoxGetItemText(eventsCombo, r)
  131.     local info = guiGetText(infoLabelB)
  132.     if (tonumber(pBlip) > 63) then
  133.         outputChatBox("The blip ID can only be between 0-63.", 255, 0, 0)
  134.         return false
  135.     end
  136.     if (not tonumber(timer) or timer == "" or tonumber(timer) == 0) then
  137.         outputChatBox("Please enter time in minutes at second edit box.", 255, 0, 0)
  138.         return false
  139.     end
  140.     if (not tonumber(reward) or reward == "") then
  141.         outputChatBox("Please enter prize money in first edit box.", 255, 0, 0)
  142.         return false
  143.     end
  144.     if (tonumber(reward) > 100000) then
  145.         outputChatBox("Maximum prize is $100,000.", 255, 0, 0)
  146.         return false
  147.     end
  148.     if (tonumber(reward) < 1000) then
  149.         outputChatBox("Minimum prize is $1,000.", 255, 0, 0)
  150.         return false
  151.     end
  152.     if (eventName == "Mystery Box") then
  153.         triggerServerEvent("CITsoEvents.startMission", resourceRoot, eventName, info, reward, timer, px, py, pz)
  154.         resetData()
  155.         return true
  156.     end
  157.     local d = split(guiGetText(delCoordsEdit):gsub(" ", ""), ",")
  158.     if (#d < 3) then
  159.         outputChatBox("Please enter delivery coordinates.", 255, 0, 0)
  160.         return false
  161.     end
  162.     local dx, dy, dz, dBlip = d[1], d[2], d[3], guiGetText(delBlipEdit)
  163.     if (tonumber(dBlip) > 63) then
  164.         outputChatBox("The blip ID can only be between 0-63.", 255, 0, 0)
  165.         return false
  166.     end
  167.     if (getDistanceBetweenPoints2D(px, py, dx, dy) <= 100) then
  168.         outputChatBox("The delivery position is very close to pickup position, pick different delivery position.", 200, 0, 0)
  169.         return false
  170.     end
  171.     triggerServerEvent("CITsoEvents.startMission", resourceRoot, eventName, info, reward, timer, px, py, pz, pBlip, dx, dy, dz, dBlip)
  172.     resetData()
  173. end
  174.  
  175. function cancelThisEvent()
  176.     triggerServerEvent("CITsoEvents.stopEvent", resourceRoot)
  177. end
  178.  
  179. function resetData()
  180.     guiSetText(pickCoordsEdit, "")
  181.     guiSetText(pickLocEdit, "")
  182.     guiSetText(delCoordsEdit, "")
  183.     guiSetText(delLocEdit, "")
  184.     guiSetText(infoLabelB, t("No event selected..."))
  185.     guiSetText(pickBlipEdit, "53")
  186.     guiSetText(delBlipEdit, "53")
  187.     guiSetText(amountEdit, t("Reward Amount"))
  188.     guiSetText(timeEdit, t("Time"))
  189.     guiComboBoxSetSelected(eventsCombo, -1)
  190. end
  191.  
  192. function insertCoordinates(button)
  193.     if (button == "right") then
  194.         guiSetVisible(eventsWindow, false)
  195.         outputChatBox(t("You can get coords. Use ./uav for get the coords!"), 0, 255, 0)
  196.         bbuttonData = source
  197.         toggleGetPosByMouse()
  198.         return true
  199.     end
  200.     local x, y, z = getElementPosition(localPlayer)
  201.     local city = exports.CITmapMisc:getZoneName2(x, y, z, true)
  202.     local zone = exports.CITmapMisc:getZoneName2(x, y, z)
  203.     if (source == getPickPosButton) then
  204.         guiSetText(pickCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z) - 1.5, 3))
  205.         guiSetText(pickLocEdit, city..", "..zone)
  206.         return true
  207.     end
  208.     guiSetText(delCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z) - 1.5, 3))
  209.     guiSetText(delLocEdit, city..", "..zone)
  210. end
  211.  
  212. function selectMission()
  213.     local r = guiComboBoxGetSelected(eventsCombo)
  214.     local name = guiComboBoxGetItemText(eventsCombo, r)
  215.     missionsInfo = {
  216.         ["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."),
  217.         ["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."),
  218.         ["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."),
  219.         ["From Danger to Safety"] = t("Requires a Bus Driver vehicle. You will take the people from a shooting to a safe zone. When the first player delivers them, all other players will have 90 seconds to complete. The bus that received less damage will be the winner."),
  220.         --["Sick Person"] = t("Requires an Ambulance or a Medic Car. People will spawn randomly next to a house and you will need take them to a hospital, chosen by an SO. Who delivers more people to the hospital will be the winner. Time limit: 5 minutes."),
  221.         ["Delivery Fish"] = t("Requires any boat. You will take the fish from the ocean and come back to shore with 95%%+ or you will have to catch the fish again. If you leave your boat, you must restore the mission. The first to complete the mission will be the winner."),
  222.         ["Awesome Bag"] = t("Volunteers will try find a lost bag. If you find it, you must hand it over to the police department or the civilian headquarters."),
  223.     }
  224.     guiSetText(infoLabelB, (missionsInfo[name] or "Couldn't fetch info, select again."))
  225. end
  226.  
  227. function clearEdit()
  228.     local text = guiGetText(source)
  229.     if (text == t("Time") or text == t("Reward Amount")) then
  230.         guiSetText(source, "")
  231.     end
  232. end
  233.  
  234. function loadingCargoDG()
  235.     if (not progressBar) then
  236.         createEventGUI()
  237.     end
  238.     setElementData(localPlayer, "lc", 1)
  239.     guiSetVisible(progressBar, true)
  240.     progressTimer = setTimer(addProgress, 100, 100)
  241.     exports.CIThelp:modTextBar("loadingCargo", t("Loading cargo..."), 255, 167, 0)
  242. end
  243. addEvent("CITsoEvents.addProgressBar", true)
  244. addEventHandler("CITsoEvents.addProgressBar", root, loadingCargoDG)
  245.  
  246. function addProgress()     
  247.     guiProgressBarSetProgress(progressBar, guiProgressBarGetProgress(progressBar) + 1)                 
  248.     if (guiProgressBarGetProgress(progressBar) == 100) then
  249.         triggerServerEvent("CITsoEvents.showMarker", resourceRoot)
  250.         guiSetVisible(progressBar, false)
  251.         guiProgressBarSetProgress(progressBar, 0)
  252.         progressTimer = nil
  253.         setElementData(localPlayer, "lc", nil)
  254.         exports.CIThelp:modTextBar("loadingCargo", "")
  255.     end
  256. end
  257.  
  258. function killProgressBar()
  259.     if (not progressBar) then
  260.         return false
  261.     end
  262.     if (progressTimer) then
  263.         killTimer(progressTimer)
  264.         progressTimer = nil
  265.     end
  266.     guiSetVisible(progressBar, false)
  267.     guiProgressBarSetProgress(progressBar, 0)
  268. end
  269. addEvent("CITsoEvents.killProgressBar", true)
  270. addEventHandler("CITsoEvents.killProgressBar", root, killProgressBar)
  271.  
  272. function outputEventMessage(str)
  273.     if (tostring(getElementData(localPlayer, "CITset.eventoutput")) == "Yes") then
  274.         outputChatBox(str, 255, 167, 0)
  275.     end
  276. end
  277. addEvent("CITsoEvents.OEM", true)
  278. addEventHandler("CITsoEvents.OEM", root, outputEventMessage)
  279.  
  280. --Get co-ordinates by using a mouse.
  281. function pickPosition()
  282.     if (not picking or not isCursorShowing()) then
  283.         return false
  284.     end
  285.     local x, y, z = getCameraMatrix()
  286.     z = z + zDifference
  287.     setElementPosition(testMarker, x, y, z)
  288.     exports.CIThelp:modTextBar("outputCoords",  math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
  289.     markerInfo = {}
  290.     markerInfo = {x, y, z}
  291. end
  292.  
  293. function increaseZ()
  294.     if (not picking) then
  295.         return false
  296.     end
  297.     zDifference = zDifference + 0.1
  298. end
  299.  
  300. function decreaseZ()
  301.     if (not picking) then
  302.         return false
  303.     end
  304.     zDifference = zDifference - 0.1
  305. end
  306.  
  307. function spawnMarker()
  308.     if (not picking or not isCursorShowing()) then
  309.         return false
  310.     end
  311.     local x, y, z = markerInfo[1], markerInfo[2], markerInfo[3]
  312.     local zone, city = getZoneName(x, y, z), getZoneName(x, y, z, true)
  313.     toggleGetPosByMouse()
  314.     guiSetVisible(eventsWindow, true)
  315.     if (buttonData == getPickPosButton) then
  316.         guiSetText(pickCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
  317.         guiSetText(pickLocEdit, city..", "..zone)
  318.         return true
  319.     end
  320.     guiSetText(delCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
  321.     guiSetText(delLocEdit, city..", "..zone)
  322. end
  323.  
  324. function toggleGetPosByMouse()
  325.     picking = not picking
  326.     if (picking) then
  327.         testMarker = createMarker(0, 0, 0, "cylinder", 2, 255, 167, 0)
  328.         markerInfo = {0, 0, 0}
  329.         removeEventHandler("onClientRender", root, pickPosition)
  330.         addEventHandler("onClientRender", root, pickPosition)
  331.         zDifference = 0
  332.         bindKey("mouse1", "down", spawnMarker)
  333.         bindKey("pgup", "down", increaseZ)
  334.         bindKey("num_8", "down", increaseZ)
  335.         bindKey("pgdn", "down", decreaseZ)
  336.         bindKey("num_2", "down", decreaseZ)
  337.         return false
  338.     end
  339.     removeEventHandler("onClientRender", root, pickPosition)
  340.     unbindKey("pgup", "down", increaseZ)
  341.     unbindKey("num_8", "down", increaseZ)
  342.     unbindKey("pgdn", "down", decreaseZ)
  343.     unbindKey("num_2", "down", decreaseZ)
  344.     unbindKey("mouse1", "down", spawnMarker)
  345.     exports.CIThelp:modTextBar("outputCoords", "")
  346.     markerInfo = {}
  347.     destroyElement(testMarker)
  348.     testMarker = nil
  349. end
Advertisement
Add Comment
Please, Sign In to add comment