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 buttonData
- local picking, testMarker, zDifference
- local markerInfo = {}
- 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. 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."),
- --["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."),
- ["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."),
- ["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."),
- }
- 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(button)
- if (button == "right") then
- guiSetVisible(eventsWindow, false)
- outputChatBox(t("You can get coords. Use ./uav for get the coords!"), 0, 255, 0)
- bbuttonData = source
- toggleGetPosByMouse()
- return true
- end
- local x, y, z = getElementPosition(localPlayer)
- 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) - 1.5, 3))
- guiSetText(pickLocEdit, city..", "..zone)
- return true
- end
- guiSetText(delCoordsEdit, math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z) - 1.5, 3))
- guiSetText(delLocEdit, city..", "..zone)
- end
- function selectMission()
- local r = guiComboBoxGetSelected(eventsCombo)
- local name = guiComboBoxGetItemText(eventsCombo, r)
- 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. 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."),
- --["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."),
- ["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."),
- ["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."),
- }
- 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)
- --Get co-ordinates by using a mouse.
- function pickPosition()
- if (not picking or not isCursorShowing()) then
- return false
- end
- local x, y, z = getCameraMatrix()
- z = z + zDifference
- setElementPosition(testMarker, x, y, z)
- exports.CIThelp:modTextBar("outputCoords", math.ceil(tonumber(x), 3)..", "..math.ceil(tonumber(y), 3)..", "..math.ceil(tonumber(z), 3))
- markerInfo = {}
- markerInfo = {x, y, z}
- end
- function increaseZ()
- if (not picking) then
- return false
- end
- zDifference = zDifference + 0.1
- end
- function decreaseZ()
- if (not picking) then
- return false
- end
- zDifference = zDifference - 0.1
- end
- function spawnMarker()
- if (not picking or not isCursorShowing()) then
- return false
- end
- local x, y, z = markerInfo[1], markerInfo[2], markerInfo[3]
- local zone, city = getZoneName(x, y, z), getZoneName(x, y, z, true)
- toggleGetPosByMouse()
- guiSetVisible(eventsWindow, true)
- if (buttonData == 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 toggleGetPosByMouse()
- picking = not picking
- if (picking) then
- testMarker = createMarker(0, 0, 0, "cylinder", 2, 255, 167, 0)
- markerInfo = {0, 0, 0}
- removeEventHandler("onClientRender", root, pickPosition)
- addEventHandler("onClientRender", root, pickPosition)
- zDifference = 0
- bindKey("mouse1", "down", spawnMarker)
- bindKey("pgup", "down", increaseZ)
- bindKey("num_8", "down", increaseZ)
- bindKey("pgdn", "down", decreaseZ)
- bindKey("num_2", "down", decreaseZ)
- return false
- end
- removeEventHandler("onClientRender", root, pickPosition)
- unbindKey("pgup", "down", increaseZ)
- unbindKey("num_8", "down", increaseZ)
- unbindKey("pgdn", "down", decreaseZ)
- unbindKey("num_2", "down", decreaseZ)
- unbindKey("mouse1", "down", spawnMarker)
- exports.CIThelp:modTextBar("outputCoords", "")
- markerInfo = {}
- destroyElement(testMarker)
- testMarker = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment