Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------------
- -- PROJECT: Community, Integrity, Transparency
- -- RIGHTS: All rights reserved by developers
- -- FILE: CITsoEvents/soevents.lua
- -- PURPOSE: State official events - Client side
- -- DEVELOPERS: Ryan#USNS (IRC: Ryan1) (Discord: Ryan#9516)
- ------------------------------------------------------------------------------------
- local t = function(...) return exports.CITt:t(...) or arg[1] or "error" end
- local progressTimer = nil
- local missionsInfo = {}
- local validResourcesAndLimit = {
- ["Iron"] = 3400,
- ["Oil"] = 970,
- ["Fish"] = 2500,
- ["Wheat"] = 1700,
- ["Herbs"] = 750,
- ["Hemp"] = 750,
- ["Meat"] = 1875,
- ["Explosive"] = 150,
- ["Gold"] = 60,
- ["Chemicals"] = 60,
- ["Nitrous"] = 3500,
- ["Electronics"] = 75,
- }
- function createEventGUI()
- local screenW, screenH = guiGetScreenSize()
- eventsWindow = guiCreateWindow((screenW - 420) / 2, (screenH - 367) / 2, 420, 367, t("State Official Event Panel"), false)
- guiWindowSetSizable(eventsWindow, false)
- guiSetAlpha(eventsWindow, 1.00)
- guiSetVisible(eventsWindow, false)
- eventsCombo = guiCreateComboBox(164, 25, 246, 84, "", false, eventsWindow)
- missionsInfo = {
- ["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."),
- ["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."),
- ["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."),
- ["From Danger to Safety"] = t("Requires a Bus Driver Vehicle's. You will take the people from a shooting to a safe zone. When the first player delivery them ( all other players will have 90 seconds to complete. The bus that received less damage will be the winner."),
- ["Awesome Bag"] = t("Voluotedrs will, try fild a lost bag. If you find it, you must hand it over to the police Department or the civilian headquarters."),
- ["Delivery Fish"] = t("Requires any boat. You will take the fish from the ocean and come back to shore with 95%%+ or you will back to sea for catch the fish. If you leave your boat, you will fail the mission. The first to complete the mission will be the winner."),
- }
- for name, info in pairs(missionsInfo) do
- guiComboBoxAddItem(eventsCombo, name)
- end
- helpLabel1 = guiCreateLabel(10, 25, 144, 23, t("Select event from box:"), false, eventsWindow)
- guiLabelSetVerticalAlign(helpLabel1, "center")
- infoLabelB = guiCreateLabel(10, 48, 400, 61, t("No event selected..."), false, eventsWindow)
- guiLabelSetHorizontalAlign(infoLabelB, "left", true)
- mainTabPanel = guiCreateTabPanel(10, 109, 400, 171, false, eventsWindow)
- -- Pickup information tab
- pickupTab = guiCreateTab(t("Pickup informations"), mainTabPanel)
- pickCoordsLabel = guiCreateLabel(10, 45, 72, 26, t("Coordinates:"), false, pickupTab)
- guiLabelSetVerticalAlign(pickCoordsLabel, "center")
- pickCoordsEdit = guiCreateEdit(82, 44, 308, 26, "", false, pickupTab)
- guiEditSetReadOnly(pickCoordsEdit, true)
- getPickPosButton = guiCreateButton(10, 9, 380, 25, t("Get my Position"), false, pickupTab)
- pickLocLabel = guiCreateLabel(10, 75, 72, 26, t("Location:"), false, pickupTab)
- guiLabelSetHorizontalAlign(pickLocLabel, "center", false)
- guiLabelSetVerticalAlign(pickLocLabel, "center")
- pickBlipLabel = guiCreateLabel(10, 106, 72, 26, t("Blip ID:"), false, pickupTab)
- guiLabelSetHorizontalAlign(pickBlipLabel, "center", false)
- guiLabelSetVerticalAlign(pickBlipLabel, "center")
- pickLocEdit = guiCreateEdit(82, 75, 308, 26, "", false, pickupTab)
- guiEditSetReadOnly(pickLocEdit, true)
- pickBlipEdit = guiCreateEdit(82, 106, 308, 26, "53", false, pickupTab)
- -- Delivery information tab
- deliveryTab = guiCreateTab(t("Delivery informations"), mainTabPanel)
- delCoordsLabel = guiCreateLabel(10, 45, 72, 26, t("Coordinates:"), false, deliveryTab)
- guiLabelSetVerticalAlign(delCoordsLabel, "center")
- delCoordsEdit = guiCreateEdit(82, 44, 308, 26, "", false, deliveryTab)
- guiEditSetReadOnly(delCoordsEdit, true)
- getDelPosButton = guiCreateButton(10, 9, 380, 25, t("Get my Position"), false, deliveryTab)
- delLocLabel = guiCreateLabel(10, 75, 72, 26, t("Location:"), false, deliveryTab)
- guiLabelSetHorizontalAlign(delLocLabel, "center", false)
- guiLabelSetVerticalAlign(delLocLabel, "center")
- delBlipLabel = guiCreateLabel(10, 106, 72, 26, t("Blip ID:"), false, deliveryTab)
- guiLabelSetHorizontalAlign(delBlipLabel, "center", false)
- guiLabelSetVerticalAlign(delBlipLabel, "center")
- delLocEdit = guiCreateEdit(82, 75, 308, 26, "", false, deliveryTab)
- guiEditSetReadOnly(delLocEdit, true)
- delBlipEdit = guiCreateEdit(82, 106, 308, 26, "53", false, deliveryTab)
- -- Quiz tab
- quizTab = guiCreateTab(t"Quiz", mainTabPanel)
- startQuizBtn = guiCreateButton(269, 112, 121, 25, t"Ask", false, quizTab)
- quizField = guiCreateEdit(50, 17, 340, 20, "", false, quizTab)
- quizLabel = guiCreateLabel(10, 18, 40, 14, t"Quiz:", false, quizTab)
- answerLabel = guiCreateLabel(10, 48, 50, 15, t"Answer:", false, quizTab)
- answerField = guiCreateEdit(60, 47, 330, 20, "", false, quizTab)
- cancelBtn = guiCreateButton(15, 112, 121, 25, t"Cancel Quiz", false, quizTab)
- rewardLabel = guiCreateLabel(10, 78, 50, 15, "Reward:", false, quizTab)
- rewardField = guiCreateEdit(60, 78, 330, 20, "", false, quizTab)
- -- Other controls
- startEventButton = guiCreateButton(297, 290, 113, 27, t("Start Event"), false, eventsWindow)
- stopEventButton = guiCreateButton(10, 332, 113, 27, t("Stop Event"), false, eventsWindow)
- clearInfoButton = guiCreateButton(157, 332, 113, 27, t("Clear Informations"), false, eventsWindow)
- closeButton = guiCreateButton(297, 332, 113, 27, t("Close Window"), false, eventsWindow)
- timeEdit = guiCreateEdit(157, 290, 113, 27, t("Time"), false, eventsWindow)
- amountEdit = guiCreateEdit(10, 290, 113, 27, t("Reward Amount"), false, eventsWindow)
- guiSetProperty(timeEdit, "ValidationString", "^[0-9]*$")
- --guiSetProperty(amountEdit, "ValidationString", "^[0-9]*$")
- guiSetProperty(delBlipEdit, "ValidationString", "^[0-9]*$")
- guiSetProperty(pickBlipEdit, "ValidationString", "^[0-9]*$")
- guiSetProperty(rewardField, "ValidationString", "^[0-9]*$")
- --Progress Bar
- progressBar = guiCreateProgressBar((screenW/2) - 350,(screenH/2) - 25, 700, 57, false)
- guiSetVisible(progressBar, false)
- -- Event handlers
- addEventHandler("onClientGUIClick", closeButton, toggleWindow, false)
- addEventHandler("onClientGUIClick", startEventButton, startEvent, false)
- addEventHandler("onClientGUIClick", stopEventButton, cancelThisEvent, false)
- addEventHandler("onClientGUIClick", clearInfoButton, resetData, false)
- addEventHandler("onClientGUIClick", getPickPosButton, insertCoordinates, false)
- addEventHandler("onClientGUIClick", getDelPosButton, insertCoordinates, false)
- addEventHandler("onClientGUIComboBoxAccepted", eventsCombo, selectMission, false)
- addEventHandler("onClientGUIClick", timeEdit, clearEdit, false)
- addEventHandler("onClientGUIClick", amountEdit, clearEdit, false)
- addEventHandler("onClientGUIClick", startQuizBtn, startQuiz, false)
- addEventHandler("onClientGUIClick", cancelBtn, stopQuiz, false)
- end
- function toggleWindow()
- if (not eventsWindow) then
- createEventGUI()
- end
- local state = not guiGetVisible(eventsWindow)
- guiSetVisible(eventsWindow, state)
- showCursor(state)
- end
- addEvent("CITsoEvents.toggleWindow", true)
- addEventHandler("CITsoEvents.toggleWindow", root, toggleWindow)
- function startEvent()
- local r = guiComboBoxGetSelected(eventsCombo)
- if (r < 0) then
- outputChatBox("Please select an event from combo box.", 255, 0, 0)
- return false
- end
- if (getElementDimension(localPlayer) ~= 0) then
- outputChatBox("You need to be in main dimension to create events.", 200, 0, 0)
- return false
- end
- local p = split(guiGetText(pickCoordsEdit):gsub(" ", ""), ",")
- if (#p < 3) then
- outputChatBox("Please enter pickup coordinates.", 255, 0, 0)
- return false
- end
- local px, py, pz, pBlip = p[1], p[2], p[3], guiGetText(pickBlipEdit)
- if (not tonumber(pBlip)) then
- return false
- end
- local timer = guiGetText(timeEdit)
- local reward = guiGetText(amountEdit)
- local eventName = guiComboBoxGetItemText(eventsCombo, r)
- local info = guiGetText(infoLabelB)
- if (tonumber(pBlip) > 63) then
- outputChatBox("The blip ID can only be between 0-63.", 255, 0, 0)
- return false
- end
- if (not tonumber(timer) or timer == "" or tonumber(timer) == 0) then
- outputChatBox("Please enter time in minutes at second edit box.", 255, 0, 0)
- return false
- end
- if (not tonumber(reward) or reward == "") then
- if (not reward:find(":")) then
- outputChatBox("Please enter prize money (or resourceName:amountOfResource) in first edit box.", 255, 0, 0)
- return false
- end
- local spl = split(reward, ":")
- if (not validResourcesAndLimit[spl[1]]) then
- outputChatBox("Invalid resource name entered", 255, 0, 0)
- return false
- end
- if (not spl[2] or not tonumber(spl[2]) or (tonumber(spl[2]) and tonumber(spl[2]) < 1)) then
- outputChatBox("Invalid resource amount entered", 255, 0, 0)
- return false
- end
- if (validResourcesAndLimit[spl[1]] < tonumber(spl[2])) then
- outputChatBox("You are exceeding the maximum limit of "..spl[1]..". Max Limit: "..validResourcesAndLimit[spl[1]], 255, 0, 0)
- return false
- end
- end
- if (tonumber(reward) and tonumber(reward) > 100000) then
- outputChatBox("Maximum prize is $100,000.", 255, 0, 0)
- return false
- end
- if (tonumber(reward) and tonumber(reward) < 1000) then
- outputChatBox("Minimum prize is $1,000.", 255, 0, 0)
- return false
- end
- if (eventName == "Mystery Box") then
- triggerServerEvent("CITsoEvents.startMission", resourceRoot, eventName, info, reward, timer, px, py, pz)
- resetData()
- return true
- end
- local d = split(guiGetText(delCoordsEdit):gsub(" ", ""), ",")
- if (#d < 3) then
- outputChatBox("Please enter delivery coordinates.", 255, 0, 0)
- return false
- end
- local dx, dy, dz, dBlip = d[1], d[2], d[3], guiGetText(delBlipEdit)
- if (tonumber(dBlip) > 63) then
- outputChatBox("The blip ID can only be between 0-63.", 255, 0, 0)
- return false
- end
- if (getDistanceBetweenPoints2D(px, py, dx, dy) <= 100) then
- outputChatBox("The delivery position is very close to pickup position, pick different delivery position.", 200, 0, 0)
- return false
- end
- triggerServerEvent("CITsoEvents.startMission", resourceRoot, eventName, info, reward, timer, px, py, pz, pBlip, dx, dy, dz, dBlip)
- resetData()
- end
- function cancelThisEvent()
- triggerServerEvent("CITsoEvents.stopEvent", resourceRoot)
- end
- function resetData()
- guiSetText(pickCoordsEdit, "")
- guiSetText(pickLocEdit, "")
- guiSetText(delCoordsEdit, "")
- guiSetText(delLocEdit, "")
- guiSetText(infoLabelB, t("No event selected..."))
- guiSetText(pickBlipEdit, "53")
- guiSetText(delBlipEdit, "53")
- guiSetText(amountEdit, t("Reward Amount"))
- guiSetText(timeEdit, t("Time"))
- guiComboBoxSetSelected(eventsCombo, -1)
- end
- function insertCoordinates()
- local x, y, z = getCameraMatrix()
- local z = getGroundPosition(x, y, z) + 0.5
- local city = exports.CITmapMisc:getZoneName2(x, y, z, true)
- local zone = exports.CITmapMisc:getZoneName2(x, y, z)
- if (source == getPickPosButton) then
- guiSetText(pickCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
- guiSetText(pickLocEdit, city..", "..zone)
- return true
- end
- guiSetText(delCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
- guiSetText(delLocEdit, city..", "..zone)
- end
- function selectMission()
- local r = guiComboBoxGetSelected(eventsCombo)
- local name = guiComboBoxGetItemText(eventsCombo, r)
- missionsInfo = {
- ["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.",
- ["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.",
- ["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.",
- ["From Danger to Safety"] = "Requires a Bus Driver Vehicle's. You will take the people from a shooting to a safe zone. When the first player delivery them ( all other players will have 90 seconds to complete. The bus that received less damage will be the winner.",
- ["Awesome Bag"] = "Voluotedrs will, try fild a lost bag. If you find it, you must hand it over to the police Department or the civilian headquarters.",
- ["Delivery Fish"] = "Requires any boat. You will take the fish from the ocean and come back to shore with 95%%+ or you will back to sea for catch the fish. If you leave your boat, you will fail the mission. The first to complete the mission will be the winner.",
- }
- guiSetText(infoLabelB, (missionsInfo[name] or "Couldn't fetch info, select again."))
- end
- function clearEdit()
- local text = guiGetText(source)
- if (text == t("Time") or text == t("Reward Amount")) then
- guiSetText(source, "")
- end
- end
- function loadingCargoDG()
- if (not progressBar) then
- createEventGUI()
- end
- setElementData(localPlayer, "lc", 1)
- guiSetVisible(progressBar, true)
- progressTimer = setTimer(addProgress, 100, 100)
- exports.CIThelp:modTextBar("loadingCargo", t("Loading cargo..."), 255, 167, 0)
- end
- addEvent("CITsoEvents.addProgressBar", true)
- addEventHandler("CITsoEvents.addProgressBar", root, loadingCargoDG)
- function addProgress()
- guiProgressBarSetProgress(progressBar, guiProgressBarGetProgress(progressBar) + 1)
- if (guiProgressBarGetProgress(progressBar) == 100) then
- triggerServerEvent("CITsoEvents.showMarker", resourceRoot)
- guiSetVisible(progressBar, false)
- guiProgressBarSetProgress(progressBar, 0)
- progressTimer = nil
- setElementData(localPlayer, "lc", nil)
- exports.CIThelp:modTextBar("loadingCargo", "")
- end
- end
- function killProgressBar()
- if (not progressBar) then
- return false
- end
- if (progressTimer) then
- killTimer(progressTimer)
- progressTimer = nil
- end
- guiSetVisible(progressBar, false)
- guiProgressBarSetProgress(progressBar, 0)
- end
- addEvent("CITsoEvents.killProgressBar", true)
- addEventHandler("CITsoEvents.killProgressBar", root, killProgressBar)
- function outputEventMessage(str)
- if (tostring(getElementData(localPlayer, "CITset.eventoutput")) == "Yes") then
- outputChatBox(str, 255, 167, 0)
- end
- end
- addEvent("CITsoEvents.OEM", true)
- addEventHandler("CITsoEvents.OEM", root, outputEventMessage)
- function startQuiz(button)
- if (button ~= "left") then
- return false
- end
- local reward = guiGetText(rewardField)
- local quiz = guiGetText(quizField)
- local answer = guiGetText(answerField)
- local timeToStop = guiGetText(timeEdit)
- if (#answer == 0 or #quiz == 0) then
- exports.CIThelp:dm(t("Missing parts need to be filled."), 190, 0, 0)
- return false
- end
- reward = ((reward and reward ~= "" and tonumber(reward)) or 0)
- if (reward > 7000) then
- exports.CIThelp:dm(t("The reward should not be less than 0 or more than $%s.", "7000"), 190, 0, 0)
- return false
- end
- timeToStop = ((timeToStop and timeToStop ~= "" and tonumber(timeToStop)) or 0)
- if (timeToStop > 10) then
- exports.CIThelp:dm(t("The time should not be less than 0 or more than %s minutes.", "10"), 190, 0, 0)
- return false
- end
- triggerServerEvent("CITsoEvents.startQuiz", resourceRoot, quiz, answer, (reward ~= 0 and reward), ((timeToStop ~= 0 and (timeToStop * 60000)) or (60000 * 5)))
- end
- function stopQuiz(button)
- if (button ~= "left") then
- return false
- end
- triggerServerEvent("CITsoEvents.stopQuiz", resourceRoot)
- end
- function receiveQuiz(msg, r, g, b)
- if ((getElementData(localPlayer, "CITset.soquiz") or "") ~= "Yes") then
- return false
- end
- outputChatBox(msg, r, g, b, true)
- end
- addEvent("CITsoEvents.receiveQuiz", true)
- addEventHandler("CITsoEvents.receiveQuiz", resourceRoot, receiveQuiz)
- local mysteryBagObj = nil
- local mysteryBagTimer = nil
- function checkUAVMysteryBag()
- if (not mysteryBagObj) then
- if (mysteryBagTimer) then
- killTimer(mysteryBagTimer)
- mysteryBagTimer = nil
- end
- mysteryBagObj = nil
- return false
- end
- if (getElementData(localPlayer, "freecam") or getElementData(localPlayer, "camerafar")) then
- if (getElementAlpha(mysteryBagObj) == 255) then
- setElementAlpha(mysteryBagObj, 0)
- end
- elseif (getElementAlpha(mysteryBagObj) == 0) then
- setElementAlpha(mysteryBagObj, 255)
- end
- end
- function mysteryBagAddTimer(obj)
- mysteryBagObj = obj
- mysteryBagTimer = setTimer(checkUAVMysteryBag, 750, 0)
- end
- addEvent("CITsoEvents.mysteryBagStarted", true)
- addEventHandler("CITsoEvents.mysteryBagStarted", root, mysteryBagAddTimer)
- function mysteryBagStop()
- if (mysteryBagTimer) then
- killTimer(mysteryBagTimer)
- end
- mysteryBagTimer = nil
- mysteryBagObj = nil
- end
- addEvent("CITsoEvents.mysteryBagStopped", true)
- addEventHandler("CITsoEvents.mysteryBagStopped", root, mysteryBagAddTimer)
Advertisement
Add Comment
Please, Sign In to add comment