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)
- ------------------------------------------------------------------------------------
- local t = function(...) return exports.CITt:t(...) or arg[1] or "error" end
- local progressTimer = nil
- local missionsInfo = {}
- 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."),
- }
- 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)
- -- 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]*$")
- --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)
- 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
- outputChatBox("Please enter prize money in first edit box.", 255, 0, 0)
- return false
- end
- if (tonumber(reward) > 100000) then
- outputChatBox("Maximum prize is $100,000.", 255, 0, 0)
- return false
- end
- if (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 = getElementPosition(localPlayer)
- local city = getZoneName(x, y, z, true)
- local zone = getZoneName(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.",
- }
- 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)
Advertisement
Add Comment
Please, Sign In to add comment