Advertisement
RyanUSNS

ServerSide - SOevents

Nov 16th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 41.00 KB | None | 0 0
  1. ------------------------------------------------------------------------------------
  2. --  PROJECT:    Community of Integrity and Transparency 2.0
  3. --  RIGHTS:     All rights reserved by developers
  4. --  FILE:       CITsoEvents/soevents.slua
  5. --  PURPOSE:    State official events - Server side
  6. --  DEVELOPERS: Ryan#USNS (IRC: Ryan1) (Discord: Ryan#9516)
  7. ------------------------------------------------------------------------------------
  8. local t = function(...) return exports.CITt:t(...) or arg[2] end
  9.  
  10. local eventStatus, object, dMarker, pMarker, dBlip, pBlip, timer, updateTimer
  11. local hit, trailer, events, delivering, limitPlr, limitSO, quizzes, limitQuiz, badPlrTimer = {}, {}, {}, {}, {}, {}, {}, {}
  12. local allowVeh = {
  13.     ["Delivery Clothes"] = {[403]=true, [515]=true, [514]=true},
  14.     ["Delivery Glasses"] = {[482]=true, [413]=true, [440]=true, [414]=true, [499]=true, [456]=true},
  15.     ["Delivery Fish"] = "Boat"
  16.     ["From Danger to Safety"] = {[431]=true, [437]=true},
  17.     ["Sick Person"] = {[416]=true, [458]=true},
  18. }
  19. local port = getServerPort()
  20. local resourcesWorth = {
  21.     ["Iron"] = 9,
  22.     ["Oil"] = 31,
  23.     ["Fish"] = 11,
  24.     ["Wheat"] = 17,
  25.     ["Herbs"] = 40,
  26.     ["Hemp"] = 40,
  27.     ["Meat"] = 16,
  28.     ["Explosive"] = 200,
  29.     ["Gold"] = 500,
  30.     ["Chemicals"] = 550,
  31.     ["Nitrous"] = 7,
  32.     ["Electronics"] = 650,
  33. }
  34.  
  35. function showPanel(plr, cmd, info)
  36.     if (info == "info") then
  37.         local civs = getTeamFromName("Civilian Workers")
  38.         if (getPlayerTeam(plr) ~= civs) then
  39.             outputChatBox(t(plr, "You need be a civilian to see State Official event information."), plr, 255, 0, 0)
  40.             return false
  41.         end
  42.         if (not eventStatus) then
  43.             outputChatBox(t(plr, "Nobody is hosting civilian event right now."), plr, 255, 0, 0)
  44.             return false
  45.         end
  46.         outputChatBox(t(plr, "Hosted by: %s", events[1]), plr, 255, 167, 0)
  47.         outputChatBox(t(plr, "Event type: %s", events[2]), plr, 255, 167, 0)
  48.         outputChatBox(t(plr, "Detail: %s", events[5]), plr, 255, 167, 0)
  49.         outputChatBox(t(plr, "Location: %s", events[4]..", "..events[3]), plr, 255, 167, 0)
  50.         if (events[2] ~= "Mystery Box") then
  51.             triggerClientEvent(plr, "gpswp", root, events[8], events[9])
  52.         end
  53.         return true
  54.     end
  55.     local acc = getAccountName(getPlayerAccount(plr))
  56.     if (not exports.CITstateOfficial:checkSOPermission(acc) and port ~= 22013) then
  57.         return false
  58.     end
  59.     if (getElementData(plr, "o") ~= "State Official" and port ~= 22013) then
  60.         outputChatBox(t(plr, "You need to be on duty state official to open events GUI."), plr, 0, 255, 0)
  61.         return false
  62.     end
  63.     if (info == "bank") then
  64.         if (not tonumber(limitSO[1])) then
  65.             outputChatBox("ERROR: limitSO[1] was "..tostring(limitSO[1]), plr)
  66.             return false
  67.         end
  68.         outputChatBox(t(plr, "SO bank: %s", (400000 - tonumber(limitSO[1]))), plr, 255, 167, 0)
  69.         if (not tonumber(limitSO[acc])) then
  70.             limitSO[acc] = 0
  71.         end
  72.         outputChatBox(t(plr, "Your bank: %s", (100000 - tonumber(limitSO[acc]))), plr, 255, 167, 0)
  73.         return true
  74.     end
  75.     triggerClientEvent(plr, "CITsoEvents.toggleWindow", plr)
  76. end
  77. addCommandHandler("soevent", showPanel)
  78.  
  79. function cancelOutput()
  80.     local civs = getTeamFromName("Civilian Workers")
  81.     local civilians = getPlayersInTeam(civs)
  82.     for k, plr2 in pairs(civilians) do
  83.         outputChatBox(t(plr2, "State official event timed out, nobody won the event!"), plr2, 255, 167, 0)
  84.     end
  85.     removeMarkers(events[2])
  86. end
  87.  
  88. function startMission(mission, detail, reward, t2, px, py, pz, pb, dx, dy, dz, db)
  89.     local t2 = tonumber(t2) or 1
  90.     local acc = getAccountName(getPlayerAccount(client))
  91.     if (eventStatus) then
  92.         outputChatBox(t(client, "An event is already in progress."), client, 255, 0, 0)
  93.         return false
  94.     end
  95.     if (not tonumber(limitSO[1])) then
  96.         limitSO[1] = 0
  97.     end
  98.     if (not tonumber(limitSO[acc])) then
  99.         limitSO[acc] = 0
  100.     end
  101.     if (not reward:find(":")) then
  102.         if (tonumber(limitSO[1]) + reward > 400000 or tonumber(limitSO[acc]) + reward > 100000) then
  103.             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)
  104.             return false
  105.         end
  106.     else
  107.         local spl = split(reward, ":")
  108.         if (not exports.CITaccounts:invGet(getPlayerAccount(client), spl[1]:lower())) then
  109.             outputChatBox("You don't have the required resources to host the event.", client, 255, 0, 0)
  110.             return false
  111.         end
  112.         local worth = resourcesWorth[spl[1]] * tonumber(spl[2])
  113.         if (tonumber(limitSO[1]) + worth > 400000 or tonumber(limitSO[acc]) + worth > 100000) then
  114.             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)
  115.             return false
  116.         end
  117.     end
  118.     if (mission == "Mystery Box") then
  119.         pMarker = createMarker(px, py, pz-1, 'cylinder', 2, 255, 167, 0, 0)
  120.         object = createObject(2912, px, py, pz-1, 0,0,0)
  121.         setElementFrozen(object, true)
  122.         events = {getPlayerName(client), mission, exports.CITmapMisc:getZoneName2(px, py, pz, true), exports.CITmapMisc:getZoneName2(px, py, pz), detail, reward, acc, px, py}
  123.         removeEventHandler("onMarkerHit", pMarker, hitBag)
  124.         removeEventHandler("onPlayerQuit", root, quitHandler)
  125.         addEventHandler("onMarkerHit", pMarker, hitBag)
  126.         addEventHandler("onPlayerQuit", root, quitHandler)
  127.         outputChatBox(t(client, "You created an Event: %s", mission), client, 0, 255, 0)
  128.         local civs = getTeamFromName("Civilian Workers")
  129.         local civilians = getPlayersInTeam(civs)
  130.         for k, plr2 in pairs(civilians) do
  131.             outputChatBox(t(plr2, "State Official %s is hosting an event. Type '/soevent info' for more information!", getPlayerName(client)), plr2, 255, 167, 0)
  132.         end
  133.         exports.CITstateOfficial:addToSOAccLogs(acc, "Hosted Civilian event; "..mission)
  134.         exports.CITlogs:logSomething("Hosted Civilian event; "..mission, "soevents", acc)
  135.         eventStatus = true
  136.         timer = setTimer(cancelOutput, t2 * 60 * 1000, 0)
  137.         triggerClientEvent("CITsoEvents.mysteryBagStarted", resourceRoot, object)
  138.         removeEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
  139.         addEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
  140.         return true
  141.     end
  142.     if (mission == "Awesome Bag") then
  143.         pMarker = createMarker(px, py, pz, "cylinder", 2, 255, 167, 0, 255, resourceRoot)
  144.         dMarker = createMarker(dx, dy, dz, "cylinder", 2, 255, 167, 0, 255, resourceRoot)
  145.         dBlip = createBlipAttachedTo(dMarker, db, 2, 255, 255, 255, 255, 0, 3000, resourceRoot)
  146.         events = {getPlayerName(client), mission, getZoneName(px, py, pz, true), getZoneName(px, py, pz), detail, reward, getAccountName(getPlayerAccount(client))}
  147.         removeEventHandler("onMarkerHit", pMarker, hitSB)
  148.         removeEventHandler("onMarkerHit", dMarker, deliverySB)
  149.         removeEventHandler("onPlayerQuit", root, quitHandler)
  150.         removeEventHandler("onPlayerWasted", root, onPlrDies)
  151.         removeEventHandler("CITsoEvents.showMarker", root, showMarker)
  152.         addEventHandler("onMarkerHit", pMarker, hitSB)
  153.         addEventHandler("onMarkerHit", dMarker, deliverySB)
  154.         addEventHandler("onPlayerQuit", root, quitHandler)
  155.         addEventHandler("onPlayerWasted", root, onPlrDies)
  156.         addEventHandler("CITsoEvents.showMarker", root, showMarker)
  157.         outputChatBox("You created an event: "..mission, client, 0, 255, 0)
  158.         local players = getPlayersInTeam(getTeamFromName("Civilian Workers"))
  159.         for i, plr in ipairs(players) do
  160.             setElementVisibleTo(pMarker, plr, true)
  161.         end
  162.         for k, plr2 in pairs(players) do
  163.             outputChatBox(t(plr2, "State Official %s is hosting an event. Type '/soevent info' for more information!", getPlayerName(client)), plr2, 255, 167, 0)
  164.         end
  165.         exports.CITstateOfficial:addToSOAccLogs(acc, "Hosted Civilian event; "..mission)
  166.         exports.CITlogs:logSomething("Hosted Civilian event; "..mission, "soevents", acc)
  167.         eventStatus = true
  168.         timer = setTimer(cancelOutput, t2 * 60 * 1000, 0)
  169.         return true
  170.     end
  171.     pMarker = createMarker(px, py, pz - 1.5, "cylinder", 4, 255, 167, 0, 255, resourceRoot)
  172.     pBlip = createBlipAttachedTo(pMarker, pb, 2, 255, 255, 255, 255, 0, 3000, resourceRoot)
  173.     dMarker = createMarker(dx, dy, dz - 1.5, "cylinder", 4, 255, 167, 0, 255, resourceRoot)
  174.     dBlip = createBlipAttachedTo(dMarker, db, 2, 255, 255, 255, 255, 0, 3000, resourceRoot)
  175.     events = {getPlayerName(client), mission, exports.CITmapMisc:getZoneName2(px, py, pz, true), exports.CITmapMisc:getZoneName2(px, py, pz), detail, reward, acc, px, py}
  176.     removeEventHandler("onMarkerHit", pMarker, pickupStuff)
  177.     removeEventHandler("onMarkerHit", dMarker, deliveryStuff)
  178.     removeEventHandler("onPlayerQuit", root, quitHandler)
  179.     removeEventHandler("onVehicleExit", root, exitVehicle)
  180.     removeEventHandler("onElementDestroy", root, destroyVehicle)
  181.     removeEventHandler("onVehicleExplode", root, destroyVehicle)
  182.     removeEventHandler("onPlayerWasted", root, onPlrDies)
  183.     removeEventHandler("CITsoEvents.showMarker", root, showMarker)
  184.     addEventHandler("onMarkerHit", pMarker, pickupStuff)
  185.     addEventHandler("onMarkerHit", dMarker, deliveryStuff)
  186.     addEventHandler("onPlayerQuit", root, quitHandler)
  187.     addEventHandler("onVehicleExit", root, exitVehicle)
  188.     addEventHandler("onElementDestroy", root, destroyVehicle)
  189.     addEventHandler("onVehicleExplode", root, destroyVehicle)
  190.     addEventHandler("onPlayerWasted", root, onPlrDies)
  191.     addEventHandler("CITsoEvents.showMarker", root, showMarker)
  192.     if (mission == "Delivery Clothes") then
  193.         removeEventHandler("onTrailerDetach", root, reattachTrailerDC)
  194.         addEventHandler("onTrailerDetach", root, reattachTrailerDC)
  195.     end
  196.     outputChatBox(t(client, "You created an event: %s", mission), client, 0, 255, 0)
  197.     local players = getPlayersInTeam(getTeamFromName("Civilian Workers"))
  198.     for i, plr in ipairs(players) do
  199.         setElementVisibleTo(pMarker, plr, true)
  200.         setElementVisibleTo(pBlip, plr, true)
  201.     end
  202.     local name = getPlayerName(client)
  203.     for k, plr2 in pairs(players) do
  204.         outputChatBox(t(plr2, "State Official %s is hosting an event. Type '/soevent info' for more information!", name), plr2, 255, 167, 0)
  205.     end
  206.     exports.CITstateOfficial:addToSOAccLogs(acc, "Hosted Civilian event; "..mission)
  207.     exports.CITlogs:logSomething("Hosted Civilian event; "..mission, "soevents", acc)
  208.     eventStatus = true
  209.     timer = setTimer(cancelOutput, t2 * 60 * 1000, 0)
  210. end
  211. addEvent("CITsoEvents.startMission", true)
  212. addEventHandler("CITsoEvents.startMission", resourceRoot, startMission)
  213.  
  214. function hitBag(plr)
  215.     if (getElementType(plr) ~= "player") then
  216.         return false
  217.     end
  218.     local civs = getTeamFromName("Civilian Workers")
  219.     local soPlr = getAccountPlayer(getAccount(events[7]))
  220.     if (getPlayerTeam(plr) ~= civs or isPedInVehicle(plr) or plr == soPlr)then
  221.         return false
  222.     end
  223.     local serial = getPlayerSerial(plr)
  224.     local acc = getAccountName(getPlayerAccount(plr))
  225.     local reward = nil
  226.     if (limitPlr[acc] or limitPlr[serial]) then
  227.         outputChatBox(t(plr, "You cannot participate in this event. Try within 30 minutes"), plr, 255, 0, 0)
  228.         return false
  229.     end
  230.     if (tonumber(events[6])) then
  231.         worth = tonumber(events[6])
  232.         exports.CITmoney:GPM(plr, tonumber(events[6]), "Won at SO Event "..events[2].." (money)", false, 1)
  233.         events[6] = "$"..events[6]
  234.     else
  235.         local spl = split(events[6], ":")
  236.         events[6] = spl[2].." "..spl[1]
  237.         worth = resourcesWorth[spl[1]] * tonumber(spl[2])
  238.         if (not exports.CITmoney:checkMoneyIncome(plr, worth)) then
  239.             return false
  240.         end
  241.         exports.CITcrafting:modifyPlayerItem(plr, spl[1], spl[2], "Won SO Event Mystery Box")
  242.     end
  243.     outputChatBox(t(plr, "You found %s from mystery box.", tostring(events[6])), plr, 0, 255, 0)
  244.     triggerEvent("onPlayerFoundMysteryBox", plr, "SO", events[6])
  245.     local civs = getTeamFromName("Civilian Workers")
  246.     local civilians = getPlayersInTeam(civs)
  247.     for k, plr2 in pairs(civilians) do
  248.         outputChatBox(getPlayerName(plr).." "..t(plr2, "found the mystery box placed by %s and got %s", events[1], events[6]), plr2, 255, 167, 0)
  249.     end
  250.     exports.CITstateOfficial:addToSOAccLogs(events[7], getPlayerName(plr).." has picked up mystery box and got "..events[6])
  251.     exports.CITlogs:logSomething(getPlayerName(plr).." has picked up mystery box and got "..events[6], "soevents", events[7], plr)
  252.     removeMarkers(events[2], events[6], acc, serial)
  253.     limitPlr[acc] = true
  254.     limitPlr[serial] = true
  255. end
  256.  
  257. -- Awesome Bag (Briefcase)
  258. function hitSB(plr)
  259.     if (not plr or getElementType(plr) ~= "player" or isPedInVehicle(plr)) then
  260.         return false
  261.     end
  262.     local civs = getTeamFromName("Civilian Workers")
  263.     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
  264.         return false
  265.     end
  266.     local serial = getPlayerSerial(plr)
  267.     local acc = getAccountName(getPlayerAccount(plr))
  268.     if (limitPlr[acc] or limitPlr[serial]) then
  269.         outputChatBox(t(plr, "You cannot participate this event. Try within 30 minutes"), plr, 255, 0, 0)
  270.         return false
  271.     end
  272.     triggerClientEvent(plr, "CITsoEvents.addProgressBar", plr)
  273.     hit[plr] = true
  274.     setElementVisibleTo(pMarker, plr, false)
  275.     setElementVisibleTo(dMarker, plr, true)
  276.     setElementFrozen(plr, true)
  277.     setTimer(setElementFrozenDelay, 10000, 1, plr, false)
  278.     outputChatBox(t(plr, "Now deliver the stuff to next location marked in your map."), plr, 255, 167, 0)
  279.     removeEventHandler("onPlayerVehicleEnter", plr, enterVehicle)
  280.     addEventHandler("onPlayerVehicleEnter", plr, enterVehicle)
  281. end
  282.  
  283. function deliverySB(plr)
  284.     if (not plr or getElementType(plr) ~= "player" or isPedInVehicle(plr)) then
  285.         return false
  286.     end
  287.     local civs = getTeamFromName("Civilian Workers")
  288.     if (getPlayerTeam(plr) ~= civs or not isElementVisibleTo(dMarker, plr))then
  289.         return false
  290.     end
  291.     if (not events[6]) then
  292.         outputChatBox("deliveryStuff: money is nil", plr)
  293.         return false
  294.     end
  295.     local soPlr = getAccountPlayer(getAccount(events[7]))
  296.     local worth = nil
  297.     if (tonumber(events[6])) then
  298.         worth = tonumber(events[6])
  299.         exports.CITmoney:GPM(plr, worth, "Won at SO Event "..events[2], false, 1)
  300.         events[6] = "$"..events[6]
  301.     else
  302.         local spl = split(events[6], ":")
  303.         events[6] = spl[2].." "..spl[1]
  304.         worth = resourcesWorth[spl[1]] * tonumber(spl[2])
  305.         if (not exports.CITmoney:checkMoneyIncome(plr, worth)) then
  306.             return false
  307.         end
  308.         exports.CITcrafting:modifyPlayerItem(plr, spl[1], spl[2], "Won SO Event DeliveryStuff")
  309.     end
  310.     exports.CITstateOfficial:addToSOAccLogs(events[7], getPlayerName(plr).." has delivered cargo at SO event and got "..events[6])
  311.     exports.CITlogs:logSomething(getPlayerName(plr).." has delivered cargo at SO event and got "..events[6], "soevents", events[7], plr)
  312.     outputChatBox(t(plr, "You deliveried a lost bag and you got $%s.", money), plr, 0, 255, 0)
  313.     local civilians = getPlayersInTeam(civs)
  314.     for k, plr2 in pairs(civilians) do
  315.         outputChatBox(getPlayerName(plr).." "..t("found the lost bag and deliveried to %s and got $s", events[1], events[6]), plr2, 255, 167, 0)
  316.     end
  317.     removeMarkers(events[2], money, plr, serial)
  318. end
  319.  
  320. function enterVehicle()
  321.     removePedFromVehicle(source)
  322.     outputChatBox("You are not allowed to enter on vehicle while you are in event!", source, 255, 0, 0)
  323. end
  324.  
  325. function checkBadPlrs(plr)
  326.     local x, y, z = getElementPosition(plr)
  327.     if (doesPedHaveJetPack(plr) or (savePosPlr[plr] and getDistanceBetweenPoints2D(x, y, savePosPlr[plr][1], savePosPlr[plr][2]) > 20)) then
  328.         outputChatBox(t(plr, "You are trying to cheat. The bag will be destroyed."), plr, 255, 0, 0)
  329.         killTimer(badPlrTimer[plr])
  330.         badPlrTimer[plr] = nil
  331.         hit[plr] = nil
  332.         setElementVisibleTo(pMarker, plr, true)
  333.         setElementVisibleTo(dMarker, plr, false)
  334.         setElementVisibleTo(dBlip, plr, false)
  335.         removeEventHandler("onPlayerVehicleEnter", plr, enterVehicle)
  336.         return true
  337.     end
  338.     savePosPlr[plr] = {x, y, z}
  339. end
  340.  
  341. -- Delivery Clothes and Delivery Glassers.
  342. function pickupStuff(hitElement)
  343.     if (not hitElement or getElementType(hitElement) ~= "vehicle" or not dMarker) then
  344.         return false
  345.     end
  346.     local driver = getVehicleController(hitElement)
  347.     if (not driver) then
  348.         return false
  349.     end
  350.     local civs = getTeamFromName("Civilian Workers")
  351.     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
  352.         return false
  353.     end
  354.     if (getElementSpeed(hitElement, 2) > 40) then
  355.         outputChatBox(t(driver, "You are driving too fast. Slow down to under 64 kph (40 mph)."), driver, 255, 0, 0)
  356.         return false
  357.     end
  358.     local serial = getPlayerSerial(driver)
  359.     local acc = getAccountName(getPlayerAccount(driver))
  360.     --if (limitPlr[acc] or limitPlr[serial]) then
  361.     --  outputChatBox(t(driver, "You cannot participate in this event. Try within 30 minutes"), driver, 255, 0, 0)
  362.     --  return false
  363.     --end
  364.     if (events[2] == "Delivery Clothes") then  
  365.         if (getElementModel(hitElement) == 435) then
  366.             return false
  367.         end
  368.         if (not truckerVehicles[getElementModel(hitElement)]) then
  369.             outputChatBox(t(driver, "You need a Trucker job vehicle!"), driver, 255, 0, 0)
  370.             return false
  371.         end
  372.         if (getVehicleTowedByVehicle(hitElement)) then
  373.             outputChatBox(t(driver, "You already have the trailer. If it is bugged, respawn the vehicle."), driver, 255, 0, 0)
  374.             return false
  375.         end
  376.         delivering[driver] = true
  377.         triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
  378.         local x, y, z = getElementPosition(pMarker)
  379.         local rx, ry, rz = getElementRotation(hitElement)
  380.         trailer[hitElement] = createVehicle(435, x, y, z, rx, ry, rz)
  381.         attachTrailerToVehicle(hitElement, trailer[hitElement])
  382.         fixVehicle(hitElement)
  383.         hit[driver] = true
  384.         setElementVisibleTo(pMarker, driver, false)
  385.         setElementVisibleTo(pBlip, driver, false)
  386.         setElementVisibleTo(dMarker, driver, true)
  387.         setElementFrozen(hitElement, true)
  388.         setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
  389.         outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
  390.         return true
  391.     end
  392.     if (events[2] == "Delivery Fish") then
  393.         if (getVehicleType(hitElement) ~= allowVeh[events[2]]) then
  394.             outputChatBox(t(driver, "You need a boat!"), driver, 255, 0, 0)
  395.             return false
  396.         end
  397.         triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
  398.         hit[driver] = true
  399.         fixVehicle(hitElement)
  400.         setElementVisibleTo(pMarker, driver, false)
  401.         setElementVisibleTo(pBlip, driver, false)
  402.         setElementVisibleTo(dMarker, driver, true)
  403.         setElementFrozen(hitElement, true)
  404.         setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
  405.         outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
  406.         return true
  407.     end
  408.     if (events[2] == "From Danger to Safety") then
  409.         if (not allowVeh[events[2]][getElementModel(hitElement)]) then
  410.             outputChatBox(t(driver, "You need a Bus Driver job vehicle!"), driver, 255, 0, 0)
  411.             return false
  412.         end
  413.         if (winnerTable[driver]) then
  414.             outputChatBox(t(driver, "You already finished the event. Wait for few seconds for get the winner!"), driver, 255, 0, 0)
  415.             return false
  416.         end
  417.         triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
  418.         hit[driver] = true
  419.         fixVehicle(hitElement)
  420.         setElementVisibleTo(pMarker, driver, false)
  421.         setElementVisibleTo(pBlip, driver, false)
  422.         setElementVisibleTo(dMarker, driver, true)
  423.         setElementFrozen(hitElement, true)
  424.         setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
  425.         outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
  426.         return true
  427.     end
  428.     if (not deliveryVehicles[getElementModel(hitElement)])then
  429.         outputChatBox(t(driver, "You need a Delivery Man vehicle!"), driver, 255, 0, 0)
  430.         return false
  431.     end
  432.     delivering[driver] = true
  433.     triggerClientEvent(driver, "CITsoEvents.addProgressBar", driver)
  434.     hit[driver] = true
  435.     fixVehicle(hitElement)
  436.     setElementVisibleTo(pMarker, driver, false)
  437.     setElementVisibleTo(pBlip, driver, false)
  438.     setElementVisibleTo(dMarker, driver, true)
  439.     setElementVisibleTo(dBlip, driver, true)
  440.     setElementFrozen(hitElement, true)
  441.     setTimer(setElementFrozenDelay, 10000, 1, hitElement, false)
  442.     outputChatBox(t(driver, "Now deliver the stuff to next location marked in your map."), driver, 255, 167, 0)
  443. end
  444.  
  445. function setElementFrozenDelay(element, bool)
  446.     if (isElement(element)) then
  447.         setElementFrozen(element, bool)
  448.     end
  449. end
  450.  
  451. function deliveryStuff(hitElement) 
  452.     if (not hitElement or getElementType(hitElement) ~= "vehicle") then
  453.         return false
  454.     end
  455.     local driver = getVehicleController(hitElement)
  456.     if (not driver) then
  457.         return false
  458.     end
  459.     local civs = getTeamFromName("Civilian Workers")
  460.     if (getPlayerTeam(driver) ~= civs or not isElementVisibleTo(dMarker, driver))then
  461.         return false
  462.     end
  463.     if (getElementSpeed(hitElement, 2) > 40) then
  464.         outputChatBox(t(driver, "You are driving too fast. Slow down to under 64 kph (40 mph)."), driver, 255, 0, 0)
  465.         return false
  466.     end
  467.     local serial = getPlayerSerial(driver)
  468.     local acc = getAccountName(getPlayerAccount(driver))
  469.     if (limitPlr[acc] or limitPlr[serial]) then
  470.         outputChatBox(t(driver, "You cannot participate in this event. Try within 30 minutes"), driver, 255, 0, 0)
  471.         return false
  472.     end
  473.     if (getElementHealth(hitElement) / 10 < 95) then
  474.         outputChatBox(t(driver, "You need to fix your vehicle. It is below 95%%"), driver, 255, 0, 0)
  475.         outputChatBox(t(driver, "Go to first marker!"), driver, 255, 0, 0)
  476.         setElementVisibleTo(dMarker, driver, false)
  477.         setElementVisibleTo(dBlip, driver, false)
  478.         setElementVisibleTo(pMarker, driver, true)
  479.         setElementVisibleTo(pBlip, driver, true)
  480.         hit[driver] = false
  481.         if (trailer[hitElement]) then
  482.             destroyElement(trailer[hitElement])
  483.         end
  484.         trailer[hitElement] = nil
  485.         delivering[driver] = nil
  486.         return true
  487.     end
  488.     if (events[2] == "From Danger to Safety") then
  489.         if (not timerBusDriver) then
  490.             timerBusDriver = setTimer(getWinners, 10000, 1)
  491.         end
  492.         local accPlr = getAccountName(getPlayerAccount(driver))
  493.         if (not winnerTable[accPlr]) then
  494.             winnerTable[accPlr] = {0, getPlayerSerial(driver)}
  495.         end
  496.         winnerTable[accPlr][1] = getElementHealth(hitElement) / 10
  497.         setElementVisibleTo(dMarker, driver, false)
  498.         setElementVisibleTo(dBlip, driver, false)
  499.         outputChatBox(t(driver, "Wait few seconds. You are in winner Table."), driver, 0, 255, 0)
  500.         return true
  501.     end
  502.     if (not events[6]) then
  503.         outputChatBox("deliveryStuff: money is nil", driver)
  504.         return false
  505.     end
  506.     local soPlr = getAccountPlayer(getAccount(events[7]))
  507.     local worth = nil
  508.     if (tonumber(events[6])) then
  509.         worth = tonumber(events[6])
  510.         exports.CITmoney:GPM(driver, worth, "Won at SO Event "..events[2], false, 1)
  511.         events[6] = "$"..events[6]
  512.     else
  513.         local spl = split(events[6], ":")
  514.         events[6] = spl[2].." "..spl[1]
  515.         worth = resourcesWorth[spl[1]] * tonumber(spl[2])
  516.         if (not exports.CITmoney:checkMoneyIncome(driver, worth)) then
  517.             return false
  518.         end
  519.         exports.CITcrafting:modifyPlayerItem(driver, spl[1], spl[2], "Won SO Event DeliveryStuff")
  520.     end
  521.     exports.CITstateOfficial:addToSOAccLogs(events[7], getPlayerName(driver).." has delivered cargo at SO event and got "..events[6])
  522.     exports.CITlogs:logSomething(getPlayerName(driver).." has delivered cargo at SO event and got "..events[6], "soevents", events[7], driver)
  523.     local civilians = getPlayersInTeam(civs)
  524.     delivering[driver] = nil
  525.     if (events[2] == "Delivery Clothes") then
  526.         outputChatBox(t(driver, "You delivered clothes successfully and won $%s", events[6]), driver, 0, 255, 0)
  527.         for k, plr2 in pairs(civilians) do
  528.             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)
  529.         end
  530.         removeMarkers(events[2], events[6], acc, serial)
  531.         return true
  532.     end
  533.     if (events[2] == "Delivery Fish") then
  534.         outputChatBox(t(driver, "You delivered fish successfully and won $%s", events[6]), driver, 0, 255, 0)
  535.         for k, plr2 in ipairs(civilians) do
  536.             outputChatBox(getPlayerName(driver).." "..t(plr2, "delivered the fish to fish market in State Official event and won %s", events[6]), plr2, 255, 167, 0)
  537.         end
  538.         removeMarkers(events[2], money, driver, serial)
  539.         return true
  540.     end
  541.     outputChatBox(t(driver, "You delivered glasses successfully and won $%s", events[6]), driver, 0, 255, 0)
  542.     for k, plr2 in pairs(civilians) do
  543.         outputChatBox(getPlayerName(driver).." "..t(plr2, "delivered the glasses to IKEA shop in State Official event and won %s", events[6]), plr2, 255, 167, 0)
  544.     end
  545.     removeMarkers(events[2], events[6], acc, serial)
  546. end
  547.  
  548. function getWinners()
  549.     local sortTable = {}
  550.     for acc, val in pairs(winnerTable) do
  551.         sortTable[#sortTable + 1] = {acc, val[1], val[2]}
  552.     end
  553.     table.sort(sortTable, sortMyTable)
  554.     local winnerAcc = sortTable[1][1]
  555.     local winnerSerial = sortTable[1][3]
  556.     local winnerPlr = getAccountPlayer(getAccount(winnerAcc))
  557.     local soPlr = getAccountPlayer(getAccount(events[7]))
  558.     if (not events[6]) then
  559.         outputChatBox("deliveryStuff: money is nil", winnerPlr)
  560.         return false
  561.     end
  562.     local soPlr = getAccountPlayer(getAccount(events[7]))
  563.     local worth = nil
  564.     if (tonumber(events[6])) then
  565.         worth = tonumber(events[6])
  566.         exports.CITmoney:GPM(winnerPlr, worth, "Won at SO Event "..events[2], false, 1)
  567.         events[6] = "$"..events[6]
  568.     else
  569.         local spl = split(events[6], ":")
  570.         events[6] = spl[2].." "..spl[1]
  571.         worth = resourcesWorth[spl[1]] * tonumber(spl[2])
  572.         if (not exports.CITmoney:checkMoneyIncome(winnerPlr, worth)) then
  573.             return false
  574.         end
  575.         exports.CITcrafting:modifyPlayerItem(winnerPlr, spl[1], spl[2], "Won SO Event DeliveryStuff")
  576.     end
  577.     exports.CITstateOfficial:addToSOAccLogs(events[7], winnerPlr.." has delivered cargo at SO event and got "..events[6])
  578.     exports.CITlogs:logSomething(winnerPlr.." has delivered cargo at SO event and got "..events[6], "soevents", events[7], winnerPlr)
  579.     outputChatBox(t(winnerPlr, "You delivered people from dangerous to safe zone and won $%s", events[6]), winnerPlr, 0, 255, 0)
  580.     local civilians = getPlayersInTeam(getTeamFromName("Civilian Workers"))
  581.     for k, plr2 in pairs(civilians) do
  582.         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)
  583.     end
  584.     winnerTable = {}
  585.     removeMarkers(events[2], worth, winnerAcc, winnerSerial)
  586. end
  587.  
  588. function sortMyTable(a, b)
  589.     return a[2] > b[2]
  590. end
  591.  
  592. -- For every mission
  593. function mysteryBagPreventUAV()
  594.     if (not object) then
  595.         removeEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
  596.         return false
  597.     end
  598.     triggerClientEvent("CITsoEvents.mysteryBagStarted", source, object)
  599. end
  600.  
  601. function removeMarkers(typeEvent, cash, acc, serial)
  602.     if (not pMarker) then
  603.         return false
  604.     end
  605.     if (timer) then
  606.         killTimer(timer)
  607.         timer = nil
  608.     end
  609.     if (cash) then
  610.         cash = cash:gsub("%$", "")
  611.         if (not tonumber(cash)) then
  612.             local spl = split(cash, " ")
  613.             cash = resourcesWorth[spl[2]] * tonumber(spl[1])
  614.         end
  615.     end
  616.     eventStatus = false
  617.     if (cash and acc and serial and events[7]) then
  618.         limitSO[1] = limitSO[1] + cash
  619.         limitSO[events[7]] = (limitSO[events[7]] or 0) + cash
  620.         limitPlr[acc] = true
  621.         limitPlr[serial] = true
  622.     end
  623.     if (typeEvent == "Mystery Box") then
  624.         triggerClientEvent("CITsoEvents.mysteryBagStopped", resourceRoot)
  625.         removeEventHandler("onPlayerLogin", root, mysteryBagPreventUAV)
  626.         removeEventHandler("onMarkerHit", pMarker, hitBag)
  627.         destroyElement(pMarker)
  628.         destroyElement(object)
  629.         events = {}
  630.         object = nil
  631.         pMarker = nil
  632.         return true
  633.     end
  634.     if (not dMarker) then
  635.         return false
  636.     end
  637.     if (typeEvent == "Awesome Bag") then
  638.         removeEventHandler("onPickupHit", pMarker, hitSB)
  639.         removeEventHandler("onMarkerHit", dMarker, deliverySB)
  640.         removeEventHandler("onPlayerQuit", root, quitHandler)
  641.         removeEventHandler("onPlayerWasted", root, onPlrDies)
  642.         destroyElement(pMarker)
  643.         destroyElement(dMarker)
  644.         destroyElement(dBlip)
  645.         for civ, bool in pairs(hit) do
  646.             if (civ) then
  647.                 if (badPlrTimer[civ]) then
  648.                     killTimer(badPlrTimer[civ])
  649.                 end
  650.                 removeEventHandler("onPlayerVehicleEnter", civ, enterVehicle)
  651.             end
  652.         end
  653.         badPlrTimer = {}
  654.         savePosPlr = {}
  655.         hit = {}
  656.         events = {}
  657.         pMarker = nil
  658.         dMarker = nil
  659.         dBlip = nil
  660.         return true
  661.     end
  662.     if (typeEvent == "Delivery Clothes") then
  663.         removeEventHandler("onTrailerDetach", root, reattachTrailerDC)
  664.         for i, trail in pairs(trailer) do
  665.             if (isElement(trail)) then
  666.                 destroyElement(trail)
  667.             end
  668.             trailer[i] = nil
  669.         end
  670.     end
  671.     removeEventHandler("onMarkerHit", pMarker, pickupStuff)
  672.     removeEventHandler("onMarkerHit", dMarker, deliveryStuff)
  673.     removeEventHandler("onPlayerQuit", root, quitHandler)
  674.     removeEventHandler("onVehicleExit", root, exitVehicle)
  675.     removeEventHandler("onElementDestroy", root, destroyVehicle)
  676.     removeEventHandler("onVehicleExplode", root, destroyVehicle)
  677.     removeEventHandler("CITsoEvents.showMarker", root, showMarker)
  678. --  triggerClientEvent(root, "CITsoEvents.killProgressBar", root)
  679.     removeEventHandler("onPlayerWasted", root, onPlrDies)
  680.     destroyElement(pMarker)
  681.     destroyElement(pBlip)
  682.     destroyElement(dMarker)
  683.     destroyElement(dBlip)
  684.     pMarker = nil
  685.     pBlip = nil
  686.     dMarker = nil
  687.     dBlip = nil
  688.     hit = {}
  689.     events = {}
  690.     trailer = {}
  691.     delivering = {}
  692. end
  693.  
  694. function showMarker()
  695.     if (#events == 0) then
  696.         return false
  697.     end
  698.     if (not pMarker or events[2] == "Mystery Box") then
  699.         return false
  700.     end
  701.     local text = "Deliver the glasses to IKEA!"
  702.     if (events[2] == "Delivery Clothes") then
  703.         text = "Deliver the clothes to Pull & Bear shop!"
  704.     end
  705.     if (events[2] == "Delivery Fish") then
  706.         text = "Deliver the fish to fish market!"
  707.     end
  708.     if (events[2] == "From Danger to Safety") then
  709.         text = "Deliver people to safe zone!"
  710.     end
  711.     if (events[2] == "Awesome Bag") then
  712.         text = "Deliver bag to Civilian HQ"
  713.         badPlrTimer[client] = setTimer(checkBadPlrs, 1000, 0, client)
  714.     end
  715.     setElementVisibleTo(dBlip, client, true)
  716.     outputChatBox(t(client, text), client, 0, 255, 0)
  717. end
  718. addEvent("CITsoEvents.showMarker", true)
  719.  
  720. function reattachTrailerDC(theTruck)
  721.     if (trailer[theTruck]) then
  722.         attachTrailerToVehicle(theTruck, trailer[theTruck])
  723.     end
  724. end
  725.  
  726. function quitHandler()
  727.     if (not events[1]) then
  728.         return false
  729.     end
  730.     local veh = getPedOccupiedVehicle(source)
  731.     if (trailer[veh]) then
  732.         destroyElement(trailer[veh])
  733.         trailer[veh] = nil
  734.     end
  735.     local soPlr = getAccountPlayer(getAccount(events[7]))
  736.     if (getElementType(source) ~= "player" or not pMarker or not soPlr) then
  737.         return false
  738.     end
  739.     local acc = getAccountName(getPlayerAccount(source))
  740.     if (events[2] == "From Danger to Safety" and winnerTable[acc]) then
  741.         winnerTable[acc] = nil
  742.     end
  743.     if (source == soPlr) then
  744.         local text = "Event auto cancelled, "..getPlayerName(soPlr).." disconnected."
  745.         local civs = getTeamFromName("Civilian Workers")
  746.         local civilians = getPlayersInTeam(civs)
  747.         for k, plr2 in pairs(civilians) do
  748.             outputChatBox(t(plr2, "Event auto cancelled, %s disconnected.", getPlayerName(soPlr)), plr2, 255, 167, 0)
  749.         end
  750.         exports.CITstateOfficial:addToSOAccLogs(getAccount(events[7]), text)
  751.         exports.CITlogs:logSomething(text, "soevents", events[7])
  752.         removeMarkers(events[2])
  753.         return true
  754.     end
  755.     hit[source] = false
  756. end
  757.  
  758. function exitVehicle(plr)
  759.     local civs = getTeamFromName("Civilian Workers")
  760.     if (events[2] == "Mystery Box" or events[2] == "Awesome Bag" or getPlayerTeam(plr) ~= civs or not delivering[plr]) then
  761.         return false
  762.     end
  763.     setElementVisibleTo(dMarker, plr, false)
  764.     setElementVisibleTo(dBlip, plr, false)
  765.     setElementVisibleTo(pMarker, plr, true)
  766.     setElementVisibleTo(pBlip, plr, true)
  767.     hit[plr] = false
  768.     delivering[plr] = nil
  769.     outputChatBox(t(plr, "You lost the cargo. Go to first marker again."), plr, 255, 0, 0)
  770.     if (trailer[source]) then
  771.         destroyElement(trailer[source])
  772.         trailer[source] = nil
  773.     end
  774. end
  775.  
  776. function destroyVehicle()
  777.     if (getElementType(source) ~= "vehicle") then
  778.         return false
  779.     end
  780.     local driver = getVehicleController(source)
  781.     local civs = getTeamFromName("Civilian Workers")
  782.     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
  783.         return false
  784.     end
  785.     hit[driver] = false
  786.     delivering[driver] = nil
  787.     setElementVisibleTo(dMarker, driver, false)
  788.     setElementVisibleTo(dBlip, driver, false)
  789.     setElementVisibleTo(pMarker, driver, true)
  790.     setElementVisibleTo(pBlip, driver, true)
  791.     if (trailer[source]) then
  792.         destroyElement(trailer[source])
  793.         trailer[source] = nil
  794.     end
  795.     outputChatBox(t(driver, "You lost the cargo. Go to first marker again."), driver, 255, 0, 0)
  796.     if (dMarker and isElementWithinMarker(driver, pMarker)) then
  797.         triggerClientEvent(driver, "CITsoEvents.killProgressBar", driver)
  798.     end
  799. end
  800.  
  801. function onPlrDies()
  802.     local civs = getTeamFromName("Civilian Workers")
  803.     if (events[2] == "Mystery Box" or getPlayerTeam(source) ~= civs or not delivering[source]) then
  804.         return false
  805.     end
  806.     local acc = getAccountName(getPlayerAccount(source))
  807.     if (events[2] == "From Danger to Safety" and winnerTable[acc]) then
  808.         winnerTable[acc] = nil
  809.     end
  810.     local veh = getPedOccupiedVehicle(source)
  811.     hit[source] = false
  812.     delivering[source] = nil
  813.     setElementVisibleTo(dMarker, source, false)
  814.     setElementVisibleTo(dBlip, source, false)
  815.     setElementVisibleTo(pMarker, source, true)
  816.     setElementVisibleTo(pBlip, source, true)
  817.     if (trailer[veh]) then
  818.         destroyElement(trailer[veh])
  819.         trailer[source] = nil
  820.     end
  821.     outputChatBox(t(source, "You lost the cargo. Go to first marker again."), source, 255, 0, 0)
  822. end
  823.  
  824. function plrTeamChanged(newTeam)
  825.     if (not pMarker) then
  826.         return false
  827.     end
  828.     if (getTeamName(newTeam) == "Civilian Workers") then
  829.         outputChatBox(t(source, "State Official %s is hosting an event. Type '/soevent info' for more information!", events[1]), source, 255, 167, 0)
  830.         setElementVisibleTo(pMarker, source, true)
  831.         if (pBlip) then
  832.             setElementVisibleTo(pBlip, source, true)
  833.         end
  834.         if (delivering[source]) then
  835.             hit[source] = false
  836.             delivering[source] = nil
  837.             if (dMarker and isElementWithinMarker(driver, pMarker)) then
  838.                 triggerClientEvent(driver, "CITsoEvents.killProgressBar", driver)
  839.             end
  840.         end
  841.         return true
  842.     end
  843.     if (pMarker and isElementVisibleTo(pMarker, source)) then
  844.         setElementVisibleTo(pMarker, source, false)
  845.     end
  846.     if (pBlip and isElementVisibleTo(pBlip, source)) then
  847.         setElementVisibleTo(pBlip, source, false)
  848.     end
  849.     if (dMarker and isElementVisibleTo(dMarker, source)) then
  850.         setElementVisibleTo(dMarker, source, false)
  851.     end
  852.     if (dBlip and isElementVisibleTo(dBlip, source)) then
  853.         setElementVisibleTo(dBlip, source, false)
  854.     end
  855. end
  856. addEventHandler("onPlayerChangeTeam", root, plrTeamChanged)
  857.  
  858. function stopEvent()
  859.     if (not eventStatus or not pMarker) then
  860.         return false
  861.     end
  862.     local acc = getAccountName(getPlayerAccount(client))
  863.     local access = exports.CITstateOfficial:checkSOPermission(acc)
  864.     if (not access) then
  865.         return false
  866.     end
  867.     if (events[7] ~= acc and access:upper() == "SO") then
  868.         outputChatBox(t(client, "Only HSO/AHSO can stop civilian events."), client, 0, 255, 0)
  869.         return false
  870.     end
  871.     local text = getPlayerName(client).." has cancelled the State Officials event, "..events[2]
  872.     local civs = getTeamFromName("Civilian Workers")
  873.     local civilians = getPlayersInTeam(civs)
  874.     for k, plr2 in pairs(civilians) do
  875.         outputChatBox(getPlayerName(client).." "..t(plr2, "has cancelled the State Officials event, %s", events[2]), plr2, 255, 167, 0)
  876.     end
  877.     exports.CITstateOfficial:addToSOAccLogs(acc, text)
  878.     exports.CITlogs:logSomething(text, "soevents", events[7])
  879.     removeMarkers(events[2])
  880. end
  881. addEvent("CITsoEvents.stopEvent", true)
  882. addEventHandler("CITsoEvents.stopEvent", resourceRoot, stopEvent)
  883.  
  884. function refreshLimit()
  885.     if (tonumber(limitSO[1])) then
  886.         limitSO = {}
  887.         limitSO[1] = 0
  888.     end
  889.     limitPlr = {}
  890. end
  891. setTimer(refreshLimit, (3600000 / 2), 0)
  892.  
  893. function startQuiz(quiz, answer, reward, timeToStop)
  894.     local acc = getAccountName(getPlayerAccount(client))
  895.     if (not exports.CITstateOfficial:checkSOPermission(acc) and port ~= 22013) then
  896.         return false
  897.     end
  898.     if (#quizzes ~= 0) then
  899.         exports.CIThelp:dm("There is a running quiz right now.", client, 190, 0, 0)
  900.         return false
  901.     end
  902.     if (reward) then
  903.         if (not limitSO[acc]) then
  904.             limitSO[acc] = 0
  905.         end
  906.         if (not limitSO[1]) then
  907.             limitSO[1] = 0
  908.         end
  909.         if (tonumber(limitSO[1]) + reward > 400000 or tonumber(limitSO[acc]) + reward > 100000) then
  910.             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)
  911.             return false
  912.         end
  913.         limitSO[1] = limitSO[1] + reward
  914.         limitSO[acc] = limitSO[acc] + reward
  915.     end
  916.     local quizTimer = setTimer(quizTime, timeToStop + 50, 1)
  917.     quizzes = {quiz, answer, reward, getPlayerAccount(client), quizTimer, client}
  918.     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))
  919.     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)
  920.     sendQuiz("#E6BC05(QUIZ CIVILIAN) "..getPlayerName(client)..": #FFFFFF"..quiz, exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
  921.     sendQuiz("#E6BC05(QUIZ CIVILIAN) Type /acq <answer> to answer.", exports.CITJava:getPlayersInTeams(true, "Civilian Workers", "Unoccupied"), 0, 210, 0)
  922. end
  923. addEvent("CITsoEvents.startQuiz", true)
  924. addEventHandler("CITsoEvents.startQuiz", resourceRoot, startQuiz)
  925.  
  926. function stopQuiz()
  927.     local acc = getAccountName(getPlayerAccount(client))
  928.     if (not exports.CITstateOfficial:checkSOPermission(acc) and port ~= 22013) then
  929.         return false
  930.     end
  931.     if (#quizzes == 0) then
  932.         exports.CIThelp:dm("No quiz is running right now.", client, 190, 0, 0)
  933.         return false
  934.     end
  935.     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))
  936.     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)
  937.     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)
  938.     if (quizzes[5]) then
  939.         killTimer(quizzes[5])
  940.     end
  941.     quizzes = { }
  942.     limitQuiz = { }
  943. end
  944. addEvent("CITsoEvents.stopQuiz", true)
  945. addEventHandler("CITsoEvents.stopQuiz", resourceRoot, stopQuiz)
  946.  
  947. function quizTime()
  948.     if (#quizzes == 0) then
  949.         return false
  950.     end
  951.     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)
  952.     quizzes = { }
  953.     limitQuiz = { }
  954. end
  955.  
  956. function sendQuiz(msg, plrs, r, g, b)
  957.     triggerClientEvent(plrs, "CITsoEvents.receiveQuiz", resourceRoot, msg, r, g, b)
  958. end
  959.  
  960. function answerQuiz(plr, cmdName, ...)
  961.     if (not exports.CITteams:isPlayerInTeams(plr, "Civilian Workers", "Unoccupied")) then
  962.         return false
  963.     end
  964.     if (#quizzes == 0) then
  965.         exports.CIThelp:dm("No quiz is running right now.", plr, 190, 0, 0, true)
  966.         return false
  967.     end
  968.     if (getPlayerAccount(plr) == quizzes[4] and port ~= 22013) then
  969.         exports.CIThelp:dm("You can not answer your own quiz.", plr, 190, 0, 0)
  970.         return false
  971.     end
  972.     if (limitQuiz[plr] and limitQuiz[plr] >= 10) then
  973.         exports.CIThelp:dm("You reached the limit of %s answers to this quiz.", plr, 190, 0, 0, true, 10)
  974.         return false
  975.     end
  976.     if (not arg) then
  977.         exports.CIThelp:dm("Usage: %s", plr, 190, 0, 0, true, "/acq <answer>")
  978.         return false
  979.     end
  980.     local str = ""
  981.     for i, string in ipairs(arg) do
  982.         str = str..((str ~= "" and " ") or "")..string
  983.     end
  984.     if (limitQuiz[plr]) then
  985.         limitQuiz[plr] = limitQuiz[plr] + 1
  986.     else
  987.         limitQuiz[plr] = 1
  988.     end
  989.     if (string.lower(str) ~= string.lower(quizzes[2])) then
  990.         outputChatBox(t(plr, "%s is wrong answer.", "'"..str.."'"), plr, 190, 0, 0)
  991.         local host = quizzes[6]
  992.         if (host and isElement(host)) then
  993.             sendQuiz("#E6BC05(QUIZ CIVILIAN) #FFFFFF"..getPlayerName(plr).." answered '"..str.."'", host, 0, 210, 0)
  994.         end
  995.         return false
  996.     end
  997.     if (quizzes[3]) then
  998.         exports.CITmoney:GPM(plr, quizzes[3], "Civilian quiz reward")
  999.     end
  1000.     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)
  1001.     triggerEvent("onPlayerAnsweredStateOfficialQuiz", plr)
  1002.     if (quizzes[5]) then
  1003.         killTimer(quizzes[5])
  1004.     end
  1005.     quizzes = { }
  1006.     limitQuiz = { }
  1007. end
  1008. addCommandHandler("acq", answerQuiz)
  1009.  
  1010. function getOnlineSOs()
  1011.     local plrs = { }
  1012.     for i, plr in ipairs(getElementsByType("player")) do
  1013.         local acc = getPlayerAccount(plr)
  1014.         if (acc) then
  1015.             local accName = getAccountName(acc)
  1016.             if (exports.CITstateOfficial:checkSOPermission(accName)) then
  1017.                 plrs[#plrs + 1] = plr
  1018.             end
  1019.         end
  1020.     end
  1021.     return plrs
  1022. end
  1023.  
  1024. -- MTA exports
  1025. function getElementSpeed(theElement, unit)
  1026.     local unit = unit == nil and 0 or ((not tonumber(unit)) and unit or tonumber(unit))
  1027.     local mult = (unit == 0 or unit == "m/s") and 50 or ((unit == 1 or unit == "km/h") and 180 or 111.84681456)
  1028.     return (Vector3(getElementVelocity(theElement)) * mult).length
  1029. end
  1030.  
  1031. -- Adding events
  1032. addEvent("onPlayerAnsweredStateOfficialQuiz")
  1033. addEvent("onPlayerFoundMysteryBox")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement