Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------------
- -- PROJECT: Community of Integrity and Transparency 2.0
- -- RIGHTS: All rights reserved by developers
- -- FILE: CITsoEvents/soevents.slua
- -- PURPOSE: State official events - Server side
- -- DEVELOPERS: Ryan#USNS (IRC: Ryan1) (Discord: Ryan#9516)
- ------------------------------------------------------------------------------------
- local t = function(...) return exports.CITt:t(...) or arg[2] end
- local eventStatus, object, dMarker, pMarker, dBlip, pBlip, timer, updateTimer
- local hit, trailer, events, delivering, limitPlr, limitSO, quizzes, limitQuiz, badPlrTimer = {}, {}, {}, {}, {}, {}, {}, {}
- local allowVeh = {
- ["Delivery Clothes"] = {[403]=true, [515]=true, [514]=true},
- ["Delivery Glasses"] = {[482]=true, [413]=true, [440]=true, [414]=true, [499]=true, [456]=true},
- ["Delivery Fish"] = "Boat"
- ["From Danger to Safety"] = {[431]=true, [437]=true},
- ["Sick Person"] = {[416]=true, [458]=true},
- }
- local port = getServerPort()
- local resourcesWorth = {
- ["Iron"] = 9,
- ["Oil"] = 31,
- ["Fish"] = 11,
- ["Wheat"] = 17,
- ["Herbs"] = 40,
- ["Hemp"] = 40,
- ["Meat"] = 16,
- ["Explosive"] = 200,
- ["Gold"] = 500,
- ["Chemicals"] = 550,
- ["Nitrous"] = 7,
- ["Electronics"] = 650,
- }
- function showPanel(plr, cmd, info)
- if (info == "info") then
- local civs = getTeamFromName("Civilian Workers")
- if (getPlayerTeam(plr) ~= civs) then
- outputChatBox(t(plr, "You need be a civilian to see State Official event information."), plr, 255, 0, 0)
- return false
- end
- if (not eventStatus) then
- outputChatBox(t(plr, "Nobody is hosting civilian event right now."), plr, 255, 0, 0)
- return false
- end
- outputChatBox(t(plr, "Hosted by: %s", events[1]), plr, 255, 167, 0)
- outputChatBox(t(plr, "Event type: %s", events[2]), plr, 255, 167, 0)
- outputChatBox(t(plr, "Detail: %s", events[5]), plr, 255, 167, 0)
- outputChatBox(t(plr, "Location: %s", events[4]..", "..events[3]), plr, 255, 167, 0)
- if (events[2] ~= "Mystery Box") then
- triggerClientEvent(plr, "gpswp", root, events[8], events[9])
- end
- return true
- end
- local acc = getAccountName(getPlayerAccount(plr))
- if (not exports.CITstateOfficial:checkSOPermission(acc) and port ~= 22013) then
- return false
- end
- if (getElementData(plr, "o") ~= "State Official" and port ~= 22013) then
- outputChatBox(t(plr, "You need to be on duty state official to open events GUI."), plr, 0, 255, 0)
- return false
- end
- if (info == "bank") then
- if (not tonumber(limitSO[1])) then
- outputChatBox("ERROR: limitSO[1] was "..tostring(limitSO[1]), plr)
- return false
- end
- outputChatBox(t(plr, "SO bank: %s", (400000 - tonumber(limitSO[1]))), plr, 255, 167, 0)
- if (not tonumber(limitSO[acc])) then
- limitSO[acc] = 0
- end
- outputChatBox(t(plr, "Your bank: %s", (100000 - tonumber(limitSO[acc]))), plr, 255, 167, 0)
- return true
- end
- triggerClientEvent(plr, "CITsoEvents.toggleWindow", plr)
- end
- addCommandHandler("soevent", showPanel)
- function cancelOutput()
- local civs = getTeamFromName("Civilian Workers")
- local civilians = getPlayersInTeam(civs)
- for k, plr2 in pairs(civilians) do
- outputChatBox(t(plr2, "State official event timed out, nobody won the event!"), plr2, 255, 167, 0)
- end
- removeMarkers(events[2])
- end
- function startMission(mission, detail, reward, t2, px, py, pz, pb, dx, dy, dz, db)
- local t2 = tonumber(t2) or 1
- local acc = getAccountName(getPlayerAccount(client))
- if (eventStatus) then
- outputChatBox(t(client, "An event is already in progress."), client, 255, 0, 0)
- return false
- end
- if (not tonumber(limitSO[1])) then
- limitSO[1] = 0
- end
- if (not tonumber(limitSO[acc])) then
- limitSO[acc] = 0
- end
- if (not reward:find(":")) then
- if (tonumber(limitSO[1]) + reward > 400000 or tonumber(limitSO[acc]) + reward > 100000) then
- outputChatBox(t(client, "You cannot host an event anymore. Use '/soevent bank' for check how much you have at SO bank."), client, 255, 0, 0)
- return false
- end
- else
- local spl = split(reward, ":")
- if (not exports.CITaccounts:invGet(getPlayerAccount(client), spl[1]:lower())) then
- outputChatBox("You don't have the required resources to host the event.", client, 255, 0, 0)
- return false
- end
- local worth = resourcesWorth[spl[1]] * tonumber(spl[2])
- if (tonumber(limitSO[1]) + worth > 400000 or tonumber(limitSO[acc]) + worth > 100000) then
- outputChatBox(t(client, "You cannot host an event anymore. Use '/soevent bank' for check how much you have at SO bank."), client, 255, 0, 0)
- return false
- end
- end
- if (mission == "Mystery Box") then
- pMarker = createMarker(px, py, pz-1, 'cylinder', 2, 255, 167, 0, 0)
- object = createObject(2912, px, py, pz-1, 0,0,0)
- setElementFrozen(object, true)
- events = {getPlayerName(client), mission, exports.CITmapMisc:getZoneName2(px, py, pz, true), exports.CITmapMisc:getZoneName2(px, py, pz), detail, reward, acc, px, py}
- removeEventHandler("onMarkerHit", pMarker, hitBag)
- removeEventHandler("onPlayerQuit", root, quitHandler)
- addEventHandler("onMarkerHit", pMarker, hitBag)
- addEventHandler("onPlayerQuit", root, quitHandler)
- outputChatBox(t(client, "You created an Event: %s", mission), client, 0, 255, 0)
- local civs = getTeamFromName("Civilian Workers")
- local civilians = getPlayersInTeam(civs)
- for k, plr2 in pairs(civilians) do
- outputChatBox(t(plr2, "State Official %s is hosting an event. Type '/soevent info' for more information!", getPlayerName(client)), plr2, 255, 167, 0)
- end
- exports.CITstateOfficial:addToSOAccLogs(acc, "Hosted Civilian event; "..mission)
- exports.CITlogs:logSomething("Hosted Civilian event; "..mission, "soevents", acc)
- eventStatus = true
- timer = setTimer(cancelOutput, t2 * 60 * 1000, 0)
- triggerClientEvent("CITsoEvents.mysteryBagStarted", resourceRoot, object)
- removeEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
- addEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
- return true
- end
- if (mission == "Awesome Bag") then
- pMarker = createMarker(px, py, pz, "cylinder", 2, 255, 167, 0, 255, resourceRoot)
- dMarker = createMarker(dx, dy, dz, "cylinder", 2, 255, 167, 0, 255, resourceRoot)
- dBlip = createBlipAttachedTo(dMarker, db, 2, 255, 255, 255, 255, 0, 3000, resourceRoot)
- events = {getPlayerName(client), mission, getZoneName(px, py, pz, true), getZoneName(px, py, pz), detail, reward, getAccountName(getPlayerAccount(client))}
- removeEventHandler("onMarkerHit", pMarker, hitSB)
- removeEventHandler("onMarkerHit", dMarker, deliverySB)
- removeEventHandler("onPlayerQuit", root, quitHandler)
- removeEventHandler("onPlayerWasted", root, onPlrDies)
- removeEventHandler("CITsoEvents.showMarker", root, showMarker)
- addEventHandler("onMarkerHit", pMarker, hitSB)
- addEventHandler("onMarkerHit", dMarker, deliverySB)
- addEventHandler("onPlayerQuit", root, quitHandler)
- addEventHandler("onPlayerWasted", root, onPlrDies)
- addEventHandler("CITsoEvents.showMarker", root, showMarker)
- outputChatBox("You created an event: "..mission, client, 0, 255, 0)
- local players = getPlayersInTeam(getTeamFromName("Civilian Workers"))
- for i, plr in ipairs(players) do
- setElementVisibleTo(pMarker, plr, true)
- end
- for k, plr2 in pairs(players) do
- outputChatBox(t(plr2, "State Official %s is hosting an event. Type '/soevent info' for more information!", getPlayerName(client)), plr2, 255, 167, 0)
- end
- exports.CITstateOfficial:addToSOAccLogs(acc, "Hosted Civilian event; "..mission)
- exports.CITlogs:logSomething("Hosted Civilian event; "..mission, "soevents", acc)
- eventStatus = true
- timer = setTimer(cancelOutput, t2 * 60 * 1000, 0)
- return true
- end
- pMarker = createMarker(px, py, pz - 1.5, "cylinder", 4, 255, 167, 0, 255, resourceRoot)
- pBlip = createBlipAttachedTo(pMarker, pb, 2, 255, 255, 255, 255, 0, 3000, resourceRoot)
- dMarker = createMarker(dx, dy, dz - 1.5, "cylinder", 4, 255, 167, 0, 255, resourceRoot)
- dBlip = createBlipAttachedTo(dMarker, db, 2, 255, 255, 255, 255, 0, 3000, resourceRoot)
- events = {getPlayerName(client), mission, exports.CITmapMisc:getZoneName2(px, py, pz, true), exports.CITmapMisc:getZoneName2(px, py, pz), detail, reward, acc, px, py}
- removeEventHandler("onMarkerHit", pMarker, pickupStuff)
- removeEventHandler("onMarkerHit", dMarker, deliveryStuff)
- removeEventHandler("onPlayerQuit", root, quitHandler)
- removeEventHandler("onVehicleExit", root, exitVehicle)
- removeEventHandler("onElementDestroy", root, destroyVehicle)
- removeEventHandler("onVehicleExplode", root, destroyVehicle)
- removeEventHandler("onPlayerWasted", root, onPlrDies)
- removeEventHandler("CITsoEvents.showMarker", root, showMarker)
- addEventHandler("onMarkerHit", pMarker, pickupStuff)
- addEventHandler("onMarkerHit", dMarker, deliveryStuff)
- addEventHandler("onPlayerQuit", root, quitHandler)
- addEventHandler("onVehicleExit", root, exitVehicle)
- addEventHandler("onElementDestroy", root, destroyVehicle)
- addEventHandler("onVehicleExplode", root, destroyVehicle)
- addEventHandler("onPlayerWasted", root, onPlrDies)
- addEventHandler("CITsoEvents.showMarker", root, showMarker)
- if (mission == "Delivery Clothes") then
- removeEventHandler("onTrailerDetach", root, reattachTrailerDC)
- addEventHandler("onTrailerDetach", root, reattachTrailerDC)
- end
- outputChatBox(t(client, "You created an event: %s", mission), client, 0, 255, 0)
- local players = getPlayersInTeam(getTeamFromName("Civilian Workers"))
- for i, plr in ipairs(players) do
- setElementVisibleTo(pMarker, plr, true)
- setElementVisibleTo(pBlip, plr, true)
- end
- local name = getPlayerName(client)
- for k, plr2 in pairs(players) do
- outputChatBox(t(plr2, "State Official %s is hosting an event. Type '/soevent info' for more information!", name), plr2, 255, 167, 0)
- end
- exports.CITstateOfficial:addToSOAccLogs(acc, "Hosted Civilian event; "..mission)
- exports.CITlogs:logSomething("Hosted Civilian event; "..mission, "soevents", acc)
- eventStatus = true
- timer = setTimer(cancelOutput, t2 * 60 * 1000, 0)
- end
- addEvent("CITsoEvents.startMission", true)
- addEventHandler("CITsoEvents.startMission", resourceRoot, startMission)
- function hitBag(plr)
- if (getElementType(plr) ~= "player") then
- return false
- end
- local civs = getTeamFromName("Civilian Workers")
- local soPlr = getAccountPlayer(getAccount(events[7]))
- if (getPlayerTeam(plr) ~= civs or isPedInVehicle(plr) or plr == soPlr)then
- return false
- end
- local serial = getPlayerSerial(plr)
- local acc = getAccountName(getPlayerAccount(plr))
- local reward = nil
- if (limitPlr[acc] or limitPlr[serial]) then
- outputChatBox(t(plr, "You cannot participate in this event. Try within 30 minutes"), plr, 255, 0, 0)
- return false
- end
- if (tonumber(events[6])) then
- worth = tonumber(events[6])
- exports.CITmoney:GPM(plr, tonumber(events[6]), "Won at SO Event "..events[2].." (money)", false, 1)
- events[6] = "$"..events[6]
- else
- local spl = split(events[6], ":")
- events[6] = spl[2].." "..spl[1]
- worth = resourcesWorth[spl[1]] * tonumber(spl[2])
- if (not exports.CITmoney:checkMoneyIncome(plr, worth)) then
- return false
- end
- exports.CITcrafting:modifyPlayerItem(plr, spl[1], spl[2], "Won SO Event Mystery Box")
- end
- outputChatBox(t(plr, "You found %s from mystery box.", tostring(events[6])), plr, 0, 255, 0)
- triggerEvent("onPlayerFoundMysteryBox", plr, "SO", events[6])
- local civs = getTeamFromName("Civilian Workers")
- local civilians = getPlayersInTeam(civs)
- for k, plr2 in pairs(civilians) do
- outputChatBox(getPlayerName(plr).." "..t(plr2, "found the mystery box placed by %s and got %s", events[1], events[6]), plr2, 255, 167, 0)
- end
- exports.CITstateOfficial:addToSOAccLogs(events[7], getPlayerName(plr).." has picked up mystery box and got "..events[6])
- exports.CITlogs:logSomething(getPlayerName(plr).." has picked up mystery box and got "..events[6], "soevents", events[7], plr)
- removeMarkers(events[2], events[6], acc, serial)
- limitPlr[acc] = true
- limitPlr[serial] = true
- end
- -- Awesome Bag (Briefcase)
- function hitSB(plr)
- if (not plr or getElementType(plr) ~= "player" or isPedInVehicle(plr)) then
- return false
- end
- local civs = getTeamFromName("Civilian Workers")
- if (getPlayerTeam(plr) ~= civs or (not hit[plr] and not isElementVisibleTo(dMarker, plr) and isElementWithinMarker(plr, dMarker)) or (hit[plr] and isElementWithinMarker(plr, pMarker))) then
- return false
- end
- local serial = getPlayerSerial(plr)
- local acc = getAccountName(getPlayerAccount(plr))
- if (limitPlr[acc] or limitPlr[serial]) then
- outputChatBox(t(plr, "You cannot participate this event. Try within 30 minutes"), plr, 255, 0, 0)
- return false
- end
- triggerClientEvent(plr, "CITsoEvents.addProgressBar", plr)
- hit[plr] = true
- setElementVisibleTo(pMarker, plr, false)
- setElementVisibleTo(dMarker, plr, true)
- setElementFrozen(plr, true)
- setTimer(setElementFrozenDelay, 10000, 1, plr, false)
- outputChatBox(t(plr, "Now deliver the stuff to next location marked in your map."), plr, 255, 167, 0)
- removeEventHandler("onPlayerVehicleEnter", plr, enterVehicle)
- addEventHandler("onPlayerVehicleEnter", plr, enterVehicle)
- end
- function deliverySB(plr)
- if (not plr or getElementType(plr) ~= "player" or isPedInVehicle(plr)) then
- return false
- end
- local civs = getTeamFromName("Civilian Workers")
- if (getPlayerTeam(plr) ~= civs or not isElementVisibleTo(dMarker, plr))then
- return false
- end
- if (not events[6]) then
- outputChatBox("deliveryStuff: money is nil", plr)
- return false
- end
- local soPlr = getAccountPlayer(getAccount(events[7]))
- local worth = nil
- if (tonumber(events[6])) then
- worth = tonumber(events[6])
- exports.CITmoney:GPM(plr, worth, "Won at SO Event "..events[2], false, 1)
- events[6] = "$"..events[6]
- else
- local spl = split(events[6], ":")
- events[6] = spl[2].." "..spl[1]
- worth = resourcesWorth[spl[1]] * tonumber(spl[2])
- if (not exports.CITmoney:checkMoneyIncome(plr, worth)) then
- return false
- end
- exports.CITcrafting:modifyPlayerItem(plr, spl[1], spl[2], "Won SO Event DeliveryStuff")
- end
- exports.CITstateOfficial:addToSOAccLogs(events[7], getPlayerName(plr).." has delivered cargo at SO event and got "..events[6])
- exports.CITlogs:logSomething(getPlayerName(plr).." has delivered cargo at SO event and got "..events[6], "soevents", events[7], plr)
- outputChatBox(t(plr, "You deliveried a lost bag and you got $%s.", money), plr, 0, 255, 0)
- local civilians = getPlayersInTeam(civs)
- for k, plr2 in pairs(civilians) do
- outputChatBox(getPlayerName(plr).." "..t("found the lost bag and deliveried to %s and got $s", events[1], events[6]), plr2, 255, 167, 0)
- end
- removeMarkers(events[2], money, plr, serial)
- end
- function enterVehicle()
- removePedFromVehicle(source)
- outputChatBox("You are not allowed to enter on vehicle while you are in event!", source, 255, 0, 0)
- end
- function checkBadPlrs(plr)
- local x, y, z = getElementPosition(plr)
- if (doesPedHaveJetPack(plr) or (savePosPlr[plr] and getDistanceBetweenPoints2D(x, y, savePosPlr[plr][1], savePosPlr[plr][2]) > 20)) then
- outputChatBox(t(plr, "You are trying to cheat. The bag will be destroyed."), plr, 255, 0, 0)
- killTimer(badPlrTimer[plr])
- badPlrTimer[plr] = nil
- hit[plr] = nil
- setElementVisibleTo(pMarker, plr, true)
- setElementVisibleTo(dMarker, plr, false)
- setElementVisibleTo(dBlip, plr, false)
- removeEventHandler("onPlayerVehicleEnter", plr, enterVehicle)
- return true
- end
- savePosPlr[plr] = {x, y, z}
- end
- -- Delivery Clothes and Delivery Glassers.
- function pickupStuff(hitElement)
- if (not hitElement or getElementType(hitElement) ~= "vehicle" or not dMarker) then
- return false
- end
- local driver = getVehicleController(hitElement)
- if (not driver) then
- return false
- end
- local civs = getTeamFromName("Civilian Workers")
- if (getPlayerTeam(driver) ~= civs or (not hit[driver] and not isElementVisibleTo(dMarker, driver) and isElementWithinMarker(driver, dMarker)) or (hit[driver] and isElementWithinMarker(driver, pMarker)))then
- return false
- end
- if (getElementSpeed(hitElement, 2) > 40) then
- outputChatBox(t(driver, "You are driving too fast. Slow down to under 64 kph (40 mph)."), driver, 255, 0, 0)
- return false
- end
- local serial = getPlayerSerial(driver)
- local acc = getAccountName(getPlayerAccount(driver))
- --if (limitPlr[acc] or limitPlr[serial]) then
- -- outputChatBox(t(driver, "You cannot participate in this event. Try within 30 minutes"), driver, 255, 0, 0)
- -- return false
- --end
- if (events[2] == "Delivery Clothes") then
- if (getElementModel(hitElement) == 435) then
- return false
- end
- if (not truckerVehicles[getElementModel(hitElement)]) then
- outputChatBox(t(driver, "You need a Trucker job vehicle!"), driver, 255, 0, 0)
- return false
- end
- if (getVehicleTowedByVehicle(hitElement)) then
- outputChatBox(t(driver, "You already have the trailer. If it is bugged, respawn the vehicle."), driver, 255, 0, 0)
- return false
- end
- delivering[driver] = true
- triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
- local x, y, z = getElementPosition(pMarker)
- local rx, ry, rz = getElementRotation(hitElement)
- trailer[hitElement] = createVehicle(435, x, y, z, rx, ry, rz)
- attachTrailerToVehicle(hitElement, trailer[hitElement])
- fixVehicle(hitElement)
- hit[driver] = true
- setElementVisibleTo(pMarker, driver, false)
- setElementVisibleTo(pBlip, driver, false)
- setElementVisibleTo(dMarker, driver, true)
- setElementFrozen(hitElement, true)
- setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
- outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
- return true
- end
- if (events[2] == "Delivery Fish") then
- if (getVehicleType(hitElement) ~= allowVeh[events[2]]) then
- outputChatBox(t(driver, "You need a boat!"), driver, 255, 0, 0)
- return false
- end
- triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
- hit[driver] = true
- fixVehicle(hitElement)
- setElementVisibleTo(pMarker, driver, false)
- setElementVisibleTo(pBlip, driver, false)
- setElementVisibleTo(dMarker, driver, true)
- setElementFrozen(hitElement, true)
- setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
- outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
- return true
- end
- if (events[2] == "From Danger to Safety") then
- if (not allowVeh[events[2]][getElementModel(hitElement)]) then
- outputChatBox(t(driver, "You need a Bus Driver job vehicle!"), driver, 255, 0, 0)
- return false
- end
- if (winnerTable[driver]) then
- outputChatBox(t(driver, "You already finished the event. Wait for few seconds for get the winner!"), driver, 255, 0, 0)
- return false
- end
- triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
- hit[driver] = true
- fixVehicle(hitElement)
- setElementVisibleTo(pMarker, driver, false)
- setElementVisibleTo(pBlip, driver, false)
- setElementVisibleTo(dMarker, driver, true)
- setElementFrozen(hitElement, true)
- setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
- outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
- return true
- end
- if (not deliveryVehicles[getElementModel(hitElement)])then
- outputChatBox(t(driver, "You need a Delivery Man vehicle!"), driver, 255, 0, 0)
- return false
- end
- delivering[driver] = true
- triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
- hit[driver] = true
- fixVehicle(hitElement)
- setElementVisibleTo(pMarker, driver, false)
- setElementVisibleTo(pBlip, driver, false)
- setElementVisibleTo(dMarker, driver, true)
- setElementVisibleTo(dBlip, driver, true)
- setElementFrozen(hitElement, true)
- setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
- outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
- end
- function setElementFrozenDelay(element, bool)
- if (isElement(element)) then
- setElementFrozen(element, bool)
- end
- end
- function deliveryStuff(hitElement)
- if (not hitElement or getElementType(hitElement) ~= "vehicle") then
- return false
- end
- local driver = getVehicleController(hitElement)
- if (not driver) then
- return false
- end
- local civs = getTeamFromName("Civilian Workers")
- if (getPlayerTeam(driver) ~= civs or not isElementVisibleTo(dMarker, driver))then
- return false
- end
- if (getElementSpeed(hitElement, 2) > 40) then
- outputChatBox(t(driver, "You are driving too fast. Slow down to under 64 kph (40 mph)."), driver, 255, 0, 0)
- return false
- end
- local serial = getPlayerSerial(driver)
- local acc = getAccountName(getPlayerAccount(driver))
- if (limitPlr[acc] or limitPlr[serial]) then
- outputChatBox(t(driver, "You cannot participate in this event. Try within 30 minutes"), driver, 255, 0, 0)
- return false
- end
- if (getElementHealth(hitElement) / 10 < 95) then
- outputChatBox(t(driver, "You need to fix your vehicle. It is below 95%%"), driver, 255, 0, 0)
- outputChatBox(t(driver, "Go to first marker!"), driver, 255, 0, 0)
- setElementVisibleTo(dMarker, driver, false)
- setElementVisibleTo(dBlip, driver, false)
- setElementVisibleTo(pMarker, driver, true)
- setElementVisibleTo(pBlip, driver, true)
- hit[driver] = false
- if (trailer[hitElement]) then
- destroyElement(trailer[hitElement])
- end
- trailer[hitElement] = nil
- delivering[driver] = nil
- return true
- end
- if (events[2] == "From Danger to Safety") then
- if (not timerBusDriver) then
- timerBusDriver = setTimer(getWinners, 10000, 1)
- end
- local accPlr = getAccountName(getPlayerAccount(driver))
- if (not winnerTable[accPlr]) then
- winnerTable[accPlr] = {0, getPlayerSerial(driver)}
- end
- winnerTable[accPlr][1] = getElementHealth(hitElement) / 10
- setElementVisibleTo(dMarker, driver, false)
- setElementVisibleTo(dBlip, driver, false)
- outputChatBox(t(driver, "Wait few seconds. You are in winner Table."), driver, 0, 255, 0)
- return true
- end
- if (not events[6]) then
- outputChatBox("deliveryStuff: money is nil", driver)
- return false
- end
- local soPlr = getAccountPlayer(getAccount(events[7]))
- local worth = nil
- if (tonumber(events[6])) then
- worth = tonumber(events[6])
- exports.CITmoney:GPM(driver, worth, "Won at SO Event "..events[2], false, 1)
- events[6] = "$"..events[6]
- else
- local spl = split(events[6], ":")
- events[6] = spl[2].." "..spl[1]
- worth = resourcesWorth[spl[1]] * tonumber(spl[2])
- if (not exports.CITmoney:checkMoneyIncome(driver, worth)) then
- return false
- end
- exports.CITcrafting:modifyPlayerItem(driver, spl[1], spl[2], "Won SO Event DeliveryStuff")
- end
- exports.CITstateOfficial:addToSOAccLogs(events[7], getPlayerName(driver).." has delivered cargo at SO event and got "..events[6])
- exports.CITlogs:logSomething(getPlayerName(driver).." has delivered cargo at SO event and got "..events[6], "soevents", events[7], driver)
- local civilians = getPlayersInTeam(civs)
- delivering[driver] = nil
- if (events[2] == "Delivery Clothes") then
- outputChatBox(t(driver, "You delivered clothes successfully and won $%s", events[6]), driver, 0, 255, 0)
- for k, plr2 in pairs(civilians) do
- outputChatBox(getPlayerName(driver).." "..t(plr2, "delivered the clothes to Pull & Bear shop in State Official event and won %s", events[6]), plr2, 255, 167, 0)
- end
- removeMarkers(events[2], events[6], acc, serial)
- return true
- end
- if (events[2] == "Delivery Fish") then
- outputChatBox(t(driver, "You delivered fish successfully and won $%s", events[6]), driver, 0, 255, 0)
- for k, plr2 in ipairs(civilians) do
- outputChatBox(getPlayerName(driver).." "..t(plr2, "delivered the fish to fish market in State Official event and won %s", events[6]), plr2, 255, 167, 0)
- end
- removeMarkers(events[2], money, driver, serial)
- return true
- end
- outputChatBox(t(driver, "You delivered glasses successfully and won $%s", events[6]), driver, 0, 255, 0)
- for k, plr2 in pairs(civilians) do
- outputChatBox(getPlayerName(driver).." "..t(plr2, "delivered the glasses to IKEA shop in State Official event and won %s", events[6]), plr2, 255, 167, 0)
- end
- removeMarkers(events[2], events[6], acc, serial)
- end
- function getWinners()
- local sortTable = {}
- for acc, val in pairs(winnerTable) do
- sortTable[#sortTable + 1] = {acc, val[1], val[2]}
- end
- table.sort(sortTable, sortMyTable)
- local winnerAcc = sortTable[1][1]
- local winnerSerial = sortTable[1][3]
- local winnerPlr = getAccountPlayer(getAccount(winnerAcc))
- local soPlr = getAccountPlayer(getAccount(events[7]))
- if (not events[6]) then
- outputChatBox("deliveryStuff: money is nil", winnerPlr)
- return false
- end
- local soPlr = getAccountPlayer(getAccount(events[7]))
- local worth = nil
- if (tonumber(events[6])) then
- worth = tonumber(events[6])
- exports.CITmoney:GPM(winnerPlr, worth, "Won at SO Event "..events[2], false, 1)
- events[6] = "$"..events[6]
- else
- local spl = split(events[6], ":")
- events[6] = spl[2].." "..spl[1]
- worth = resourcesWorth[spl[1]] * tonumber(spl[2])
- if (not exports.CITmoney:checkMoneyIncome(winnerPlr, worth)) then
- return false
- end
- exports.CITcrafting:modifyPlayerItem(winnerPlr, spl[1], spl[2], "Won SO Event DeliveryStuff")
- end
- exports.CITstateOfficial:addToSOAccLogs(events[7], winnerPlr.." has delivered cargo at SO event and got "..events[6])
- exports.CITlogs:logSomething(winnerPlr.." has delivered cargo at SO event and got "..events[6], "soevents", events[7], winnerPlr)
- outputChatBox(t(winnerPlr, "You delivered people from dangerous to safe zone and won $%s", events[6]), winnerPlr, 0, 255, 0)
- local civilians = getPlayersInTeam(getTeamFromName("Civilian Workers"))
- for k, plr2 in pairs(civilians) do
- outputChatBox(getPlayerName(driver).." "..t(plr2, "delivered people from dangerous to safe zone in State Official event and won %s", events[6]), plr2, 255, 167, 0)
- end
- winnerTable = {}
- removeMarkers(events[2], worth, winnerAcc, winnerSerial)
- end
- function sortMyTable(a, b)
- return a[2] > b[2]
- end
- -- For every mission
- function mysteryBagPreventUAV()
- if (not object) then
- removeEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
- return false
- end
- triggerClientEvent("CITsoEvents.mysteryBagStarted", source, object)
- end
- function removeMarkers(typeEvent, cash, acc, serial)
- if (not pMarker) then
- return false
- end
- if (timer) then
- killTimer(timer)
- timer = nil
- end
- if (cash) then
- cash = cash:gsub("%$", "")
- if (not tonumber(cash)) then
- local spl = split(cash, " ")
- cash = resourcesWorth[spl[2]] * tonumber(spl[1])
- end
- end
- eventStatus = false
- if (cash and acc and serial and events[7]) then
- limitSO[1] = limitSO[1] + cash
- limitSO[events[7]] = (limitSO[events[7]] or 0) + cash
- limitPlr[acc] = true
- limitPlr[serial] = true
- end
- if (typeEvent == "Mystery Box") then
- triggerClientEvent("CITsoEvents.mysteryBagStopped", resourceRoot)
- removeEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
- removeEventHandler("onMarkerHit", pMarker, hitBag)
- destroyElement(pMarker)
- destroyElement(object)
- events = {}
- object = nil
- pMarker = nil
- return true
- end
- if (not dMarker) then
- return false
- end
- if (typeEvent == "Awesome Bag") then
- removeEventHandler("onPickupHit", pMarker, hitSB)
- removeEventHandler("onMarkerHit", dMarker, deliverySB)
- removeEventHandler("onPlayerQuit", root, quitHandler)
- removeEventHandler("onPlayerWasted", root, onPlrDies)
- destroyElement(pMarker)
- destroyElement(dMarker)
- destroyElement(dBlip)
- for civ, bool in pairs(hit) do
- if (civ) then
- if (badPlrTimer[civ]) then
- killTimer(badPlrTimer[civ])
- end
- removeEventHandler("onPlayerVehicleEnter", civ, enterVehicle)
- end
- end
- badPlrTimer = {}
- savePosPlr = {}
- hit = {}
- events = {}
- pMarker = nil
- dMarker = nil
- dBlip = nil
- return true
- end
- if (typeEvent == "Delivery Clothes") then
- removeEventHandler("onTrailerDetach", root, reattachTrailerDC)
- for i, trail in pairs(trailer) do
- if (isElement(trail)) then
- destroyElement(trail)
- end
- trailer[i] = nil
- end
- end
- removeEventHandler("onMarkerHit", pMarker, pickupStuff)
- removeEventHandler("onMarkerHit", dMarker, deliveryStuff)
- removeEventHandler("onPlayerQuit", root, quitHandler)
- removeEventHandler("onVehicleExit", root, exitVehicle)
- removeEventHandler("onElementDestroy", root, destroyVehicle)
- removeEventHandler("onVehicleExplode", root, destroyVehicle)
- removeEventHandler("CITsoEvents.showMarker", root, showMarker)
- -- triggerClientEvent(root, "CITsoEvents.killProgressBar", root)
- removeEventHandler("onPlayerWasted", root, onPlrDies)
- destroyElement(pMarker)
- destroyElement(pBlip)
- destroyElement(dMarker)
- destroyElement(dBlip)
- pMarker = nil
- pBlip = nil
- dMarker = nil
- dBlip = nil
- hit = {}
- events = {}
- trailer = {}
- delivering = {}
- end
- function showMarker()
- if (#events == 0) then
- return false
- end
- if (not pMarker or events[2] == "Mystery Box") then
- return false
- end
- local text = "Deliver the glasses to IKEA!"
- if (events[2] == "Delivery Clothes") then
- text = "Deliver the clothes to Pull & Bear shop!"
- end
- if (events[2] == "Delivery Fish") then
- text = "Deliver the fish to fish market!"
- end
- if (events[2] == "From Danger to Safety") then
- text = "Deliver people to safe zone!"
- end
- if (events[2] == "Awesome Bag") then
- text = "Deliver bag to Civilian HQ"
- badPlrTimer[client] = setTimer(checkBadPlrs, 1000, 0, client)
- end
- setElementVisibleTo(dBlip, client, true)
- outputChatBox(t(client, text), client, 0, 255, 0)
- end
- addEvent("CITsoEvents.showMarker", true)
- function reattachTrailerDC(theTruck)
- if (trailer[theTruck]) then
- attachTrailerToVehicle(theTruck, trailer[theTruck])
- end
- end
- function quitHandler()
- if (not events[1]) then
- return false
- end
- local veh = getPedOccupiedVehicle(source)
- if (trailer[veh]) then
- destroyElement(trailer[veh])
- trailer[veh] = nil
- end
- local soPlr = getAccountPlayer(getAccount(events[7]))
- if (getElementType(source) ~= "player" or not pMarker or not soPlr) then
- return false
- end
- local acc = getAccountName(getPlayerAccount(source))
- if (events[2] == "From Danger to Safety" and winnerTable[acc]) then
- winnerTable[acc] = nil
- end
- if (source == soPlr) then
- local text = "Event auto cancelled, "..getPlayerName(soPlr).." disconnected."
- local civs = getTeamFromName("Civilian Workers")
- local civilians = getPlayersInTeam(civs)
- for k, plr2 in pairs(civilians) do
- outputChatBox(t(plr2, "Event auto cancelled, %s disconnected.", getPlayerName(soPlr)), plr2, 255, 167, 0)
- end
- exports.CITstateOfficial:addToSOAccLogs(getAccount(events[7]), text)
- exports.CITlogs:logSomething(text, "soevents", events[7])
- removeMarkers(events[2])
- return true
- end
- hit[source] = false
- end
- function exitVehicle(plr)
- local civs = getTeamFromName("Civilian Workers")
- if (events[2] == "Mystery Box" or events[2] == "Awesome Bag" or getPlayerTeam(plr) ~= civs or not delivering[plr]) then
- return false
- end
- setElementVisibleTo(dMarker, plr, false)
- setElementVisibleTo(dBlip, plr, false)
- setElementVisibleTo(pMarker, plr, true)
- setElementVisibleTo(pBlip, plr, true)
- hit[plr] = false
- delivering[plr] = nil
- outputChatBox(t(plr, "You lost the cargo. Go to first marker again."), plr, 255, 0, 0)
- if (trailer[source]) then
- destroyElement(trailer[source])
- trailer[source] = nil
- end
- end
- function destroyVehicle()
- if (getElementType(source) ~= "vehicle") then
- return false
- end
- local driver = getVehicleController(source)
- local civs = getTeamFromName("Civilian Workers")
- if (not driver or not events[2] or events[2] == "Mystery Box" or events[2] == "Awesome Bag" or not delivering[driver] or getPlayerTeam(driver) ~= civs) then
- return false
- end
- hit[driver] = false
- delivering[driver] = nil
- setElementVisibleTo(dMarker, driver, false)
- setElementVisibleTo(dBlip, driver, false)
- setElementVisibleTo(pMarker, driver, true)
- setElementVisibleTo(pBlip, driver, true)
- if (trailer[source]) then
- destroyElement(trailer[source])
- trailer[source] = nil
- end
- outputChatBox(t(driver, "You lost the cargo. Go to first marker again."), driver, 255, 0, 0)
- if (dMarker and isElementWithinMarker(driver, pMarker)) then
- triggerClientEvent(driver, "CITsoEvents.killProgressBar", driver)
- end
- end
- function onPlrDies()
- local civs = getTeamFromName("Civilian Workers")
- if (events[2] == "Mystery Box" or getPlayerTeam(source) ~= civs or not delivering[source]) then
- return false
- end
- local acc = getAccountName(getPlayerAccount(source))
- if (events[2] == "From Danger to Safety" and winnerTable[acc]) then
- winnerTable[acc] = nil
- end
- local veh = getPedOccupiedVehicle(source)
- hit[source] = false
- delivering[source] = nil
- setElementVisibleTo(dMarker, source, false)
- setElementVisibleTo(dBlip, source, false)
- setElementVisibleTo(pMarker, source, true)
- setElementVisibleTo(pBlip, source, true)
- if (trailer[veh]) then
- destroyElement(trailer[veh])
- trailer[source] = nil
- end
- outputChatBox(t(source, "You lost the cargo. Go to first marker again."), source, 255, 0, 0)
- end
- function plrTeamChanged(newTeam)
- if (not pMarker) then
- return false
- end
- if (getTeamName(newTeam) == "Civilian Workers") then
- outputChatBox(t(source, "State Official %s is hosting an event. Type '/soevent info' for more information!", events[1]), source, 255, 167, 0)
- setElementVisibleTo(pMarker, source, true)
- if (pBlip) then
- setElementVisibleTo(pBlip, source, true)
- end
- if (delivering[source]) then
- hit[source] = false
- delivering[source] = nil
- if (dMarker and isElementWithinMarker(driver, pMarker)) then
- triggerClientEvent(driver, "CITsoEvents.killProgressBar", driver)
- end
- end
- return true
- end
- if (pMarker and isElementVisibleTo(pMarker, source)) then
- setElementVisibleTo(pMarker, source, false)
- end
- if (pBlip and isElementVisibleTo(pBlip, source)) then
- setElementVisibleTo(pBlip, source, false)
- end
- if (dMarker and isElementVisibleTo(dMarker, source)) then
- setElementVisibleTo(dMarker, source, false)
- end
- if (dBlip and isElementVisibleTo(dBlip, source)) then
- setElementVisibleTo(dBlip, source, false)
- end
- end
- addEventHandler("onPlayerChangeTeam", root, plrTeamChanged)
- function stopEvent()
- if (not eventStatus or not pMarker) then
- return false
- end
- local acc = getAccountName(getPlayerAccount(client))
- local access = exports.CITstateOfficial:checkSOPermission(acc)
- if (not access) then
- return false
- end
- if (events[7] ~= acc and access:upper() == "SO") then
- outputChatBox(t(client, "Only HSO/AHSO can stop civilian events."), client, 0, 255, 0)
- return false
- end
- local text = getPlayerName(client).." has cancelled the State Officials event, "..events[2]
- local civs = getTeamFromName("Civilian Workers")
- local civilians = getPlayersInTeam(civs)
- for k, plr2 in pairs(civilians) do
- outputChatBox(getPlayerName(client).." "..t(plr2, "has cancelled the State Officials event, %s", events[2]), plr2, 255, 167, 0)
- end
- exports.CITstateOfficial:addToSOAccLogs(acc, text)
- exports.CITlogs:logSomething(text, "soevents", events[7])
- removeMarkers(events[2])
- end
- addEvent("CITsoEvents.stopEvent", true)
- addEventHandler("CITsoEvents.stopEvent", resourceRoot, stopEvent)
- function refreshLimit()
- if (tonumber(limitSO[1])) then
- limitSO = {}
- limitSO[1] = 0
- end
- limitPlr = {}
- end
- setTimer(refreshLimit, (3600000 / 2), 0)
- function startQuiz(quiz, answer, reward, timeToStop)
- local acc = getAccountName(getPlayerAccount(client))
- if (not exports.CITstateOfficial:checkSOPermission(acc) and port ~= 22013) then
- return false
- end
- if (#quizzes ~= 0) then
- exports.CIThelp:dm("There is a running quiz right now.", client, 190, 0, 0)
- return false
- end
- if (reward) then
- if (not limitSO[acc]) then
- limitSO[acc] = 0
- end
- if (not limitSO[1]) then
- limitSO[1] = 0
- end
- if (tonumber(limitSO[1]) + reward > 400000 or tonumber(limitSO[acc]) + reward > 100000) then
- outputChatBox(t(client, "You cannot host an event anymore. Use '/soevent bank' for check how much you have at SO bank."), client, 255, 0, 0)
- return false
- end
- limitSO[1] = limitSO[1] + reward
- limitSO[acc] = limitSO[acc] + reward
- end
- local quizTimer = setTimer(quizTime, timeToStop + 50, 1)
- quizzes = {quiz, answer, reward, getPlayerAccount(client), quizTimer, client}
- exports.CITstateOfficial:addToSOAccLogs(acc, getPlayerName(client).." created a quiz of '"..quiz.."', the answer is '"..answer.."', and the reward is $"..exports.CITmisc:comVal(reward or 0))
- exports.CITlogs:logSomething(getPlayerName(client).." created a quiz of '"..quiz.."', the answer is '"..answer.."', and the reward is $"..exports.CITmisc:comVal(reward or 0), "soevents", client)
- sendQuiz("#E6BC05(QUIZ CIVILIAN) "..getPlayerName(client)..": #FFFFFF"..quiz, exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
- sendQuiz("#E6BC05(QUIZ CIVILIAN) Type /acq <answer> to answer.", exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
- end
- addEvent("CITsoEvents.startQuiz", true)
- addEventHandler("CITsoEvents.startQuiz", resourceRoot, startQuiz)
- function stopQuiz()
- local acc = getAccountName(getPlayerAccount(client))
- if (not exports.CITstateOfficial:checkSOPermission(acc) and port ~= 22013) then
- return false
- end
- if (#quizzes == 0) then
- exports.CIThelp:dm("No quiz is running right now.", client, 190, 0, 0)
- return false
- end
- exports.CITstateOfficial:addToSOAccLogs(acc, getPlayerName(client).." stopped the current quiz of '"..quizzes[1].."', the answer is '"..quizzes[2].."', and the reward is $"..exports.CITmisc:comVal(quizzes[3] or 0))
- exports.CITlogs:logSomething(getPlayerName(client).." stopped a quiz of '"..quizzes[1].."', the answer was '"..quizzes[2].."', and the reward was $"..exports.CITmisc:comVal(quizzes[3] or 0), "soevents", client)
- sendQuiz("#E6BC05(QUIZ CIVILIAN) "..getPlayerName(client).." has stopped the current quiz. Answer was '"..quizzes[2].."'", exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
- if (quizzes[5]) then
- killTimer(quizzes[5])
- end
- quizzes = { }
- limitQuiz = { }
- end
- addEvent("CITsoEvents.stopQuiz", true)
- addEventHandler("CITsoEvents.stopQuiz", resourceRoot, stopQuiz)
- function quizTime()
- if (#quizzes == 0) then
- return false
- end
- sendQuiz("#E6BC05(QUIZ CIVILIAN) The current quiz is timed out. The answer was '"..quizzes[2].."'", exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
- quizzes = { }
- limitQuiz = { }
- end
- function sendQuiz(msg, plrs, r, g, b)
- triggerClientEvent(plrs, "CITsoEvents.receiveQuiz", resourceRoot, msg, r, g, b)
- end
- function answerQuiz(plr, cmdName, ...)
- if (not exports.CITteams:isPlayerInTeams(plr, "Civilian Workers", "Unoccupied")) then
- return false
- end
- if (#quizzes == 0) then
- exports.CIThelp:dm("No quiz is running right now.", plr, 190, 0, 0, true)
- return false
- end
- if (getPlayerAccount(plr) == quizzes[4] and port ~= 22013) then
- exports.CIThelp:dm("You can not answer your own quiz.", plr, 190, 0, 0)
- return false
- end
- if (limitQuiz[plr] and limitQuiz[plr] >= 10) then
- exports.CIThelp:dm("You reached the limit of %s answers to this quiz.", plr, 190, 0, 0, true, 10)
- return false
- end
- if (not arg) then
- exports.CIThelp:dm("Usage: %s", plr, 190, 0, 0, true, "/acq <answer>")
- return false
- end
- local str = ""
- for i, string in ipairs(arg) do
- str = str..((str ~= "" and " ") or "")..string
- end
- if (limitQuiz[plr]) then
- limitQuiz[plr] = limitQuiz[plr] + 1
- else
- limitQuiz[plr] = 1
- end
- if (string.lower(str) ~= string.lower(quizzes[2])) then
- outputChatBox(t(plr, "%s is wrong answer.", "'"..str.."'"), plr, 190, 0, 0)
- local host = quizzes[6]
- if (host and isElement(host)) then
- sendQuiz("#E6BC05(QUIZ CIVILIAN) #FFFFFF"..getPlayerName(plr).." answered '"..str.."'", host, 0, 210, 0)
- end
- return false
- end
- if (quizzes[3]) then
- exports.CITmoney:GPM(plr, quizzes[3], "Civilian quiz reward")
- end
- sendQuiz("#E6BC05(QUIZ CIVILIAN) #FFFFFF"..getPlayerName(plr).." has answered the quiz correctly! The answer was '"..quizzes[2].."'", exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
- triggerEvent("onPlayerAnsweredStateOfficialQuiz", plr)
- if (quizzes[5]) then
- killTimer(quizzes[5])
- end
- quizzes = { }
- limitQuiz = { }
- end
- addCommandHandler("acq", answerQuiz)
- function getOnlineSOs()
- local plrs = { }
- for i, plr in ipairs(getElementsByType("player")) do
- local acc = getPlayerAccount(plr)
- if (acc) then
- local accName = getAccountName(acc)
- if (exports.CITstateOfficial:checkSOPermission(accName)) then
- plrs[#plrs + 1] = plr
- end
- end
- end
- return plrs
- end
- -- MTA exports
- function getElementSpeed(theElement, unit)
- local unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
- local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
- return (Vector3(getElementVelocity(theElement)) * mult).length
- end
- -- Adding events
- addEvent("onPlayerAnsweredStateOfficialQuiz")
- addEvent("onPlayerFoundMysteryBox")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement