RyanUSNS

Server Side

Apr 5th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. local cash, soBlip, so, isRunning
  2.  
  3. function startSoChase(plr, cmd, money)
  4.     local acc = getAccountName(getPlayerAccount(plr))
  5.     local accessSO = exports.CITstateOfficial:checkSOPermission(acc)
  6.     if (not accessSO) then --Use this as it's ready for all SO checks. Even you can see who'se HSO, AHSO and SO.
  7.         return false
  8.     end
  9.     if (money == "stop") then
  10.         if (not isRunning and (so ~= plr and accessSO:upper() == "SO")) then
  11.             return false
  12.         end
  13.         stopEvent()
  14.         return true
  15.     end
  16.     if (isRunning) then
  17.         outputChatBox("An event is already running you dumbfuck!", plr, 255, 0, 0)
  18.         return false
  19.     end
  20.     if (not getPedOccupiedVehicle(plr)) then
  21.         outputChatBox("You need to be inside a vehicle to start the SO chase event you idiot", plr, 255, 0, 0)
  22.         return false
  23.     end
  24.     local money = tonumber(money)
  25.     if (not money or money < 10000 or money > 100000) then
  26.         outputChatBox("SYNTAX: /sochase <money>/<stop>, the amount of money must be more than $10,000 and lower than $100,000.", plr, 255, 0, 0)
  27.         return false
  28.     end
  29.     isRunning = true
  30.     cash = money
  31.     local vehicle = getPedOccupiedVehicle(plr)
  32.     soBlip = createBlipAttachedTo(vehicle, 41, 2, 255, 255, 255, 255, 0, 16383.0, resourceRoot)
  33.     so = plr
  34.     local x, y, z = getElementPosition(plr)
  35.     for k, v in ipairs(getPlayersInTeam(getTeamFromName("Civilian Workers"))) do
  36.         outputChatBox("State Official " ..getPlayerName(plr).. " is hosting SO chase event! Try to hit his " ..getVehicleNameFromModel(getElementModel(vehicle)).. " and win $" ..money.. ", his location is " ..getZoneName(x, y, z), v, 255, 167, 0)
  37.         setElementVisibleTo(soBlip, v, true)
  38.     end
  39.     --exports.CITmoney:TPM(plr, cash, "CIT.SOChaseEvent") -- Auto-Refund.
  40.  
  41.     removeEventHandler("onPlayerQuit", so, stopEvent)
  42.     removeEventHandler("onPlayerVehicleExit", so, stopEvent)
  43.     removeEventHandler("onPlayerWasted", so, stopEvent)
  44.     removeEventHandler("onPlayerLogin", root, loginPlr)
  45.     addEventHandler("onPlayerQuit", so, stopEvent)
  46.     addEventHandler("onPlayerVehicleExit", so, stopEvent)
  47.     addEventHandler("onPlayerWasted", so, stopEvent)
  48.     addEventHandler("onPlayerLogin", root, loginPlr)
  49.     triggerClientEvent(resourceRoot, "CIT.StartSoChaseEvent", resourceRoot, so, vehicle)
  50. end
  51. addCommandHandler("sochase", startSoChase)
  52.  
  53. function chaseRewards(plr)
  54.     if (not isRunning) then
  55.         return false
  56.     end
  57.     if (plr and isElement(plr) and getElementType(plr) == "player") then
  58.         for i, v in pairs(getPlayersInTeam(getTeamFromName("Civilian Workers"))) do
  59.             outputChatBox(""..getPlayerName(plr).." won the SO chase event!", v, 255, 167, 0)
  60.         end
  61.         exports.CITmoney:GPM(plr, cash, "CIT.SOChaseEventWinner")
  62.     end
  63.     if (soBlip or isElement(soBlip)) then
  64.         destroyElement(soBlip)
  65.         soBlip = nil
  66.     end
  67.     cash = nil
  68.     isRunning = false
  69. end
  70. addEvent("CIT.SOChaseWinner", true)
  71. addEventHandler("CIT.SOChaseWinner", resourceRoot, chaseRewards)
  72.  
  73. function stopEvent()
  74.     for i, v in pairs(getPlayersInTeam(getTeamFromName("Civilian Workers"))) do
  75.         outputChatBox("The SO chase event has been canceled!", v, 20, 255, 20)
  76.     end
  77.     isRunning = false
  78.     cash = nil
  79.     if (soBlip or isElement(soBlip)) then
  80.         destroyElement(soBlip)
  81.         soBlip = nil
  82.     end
  83.     removeEventHandler("onPlayerQuit", so, stopEvent)
  84.     removeEventHandler("onPlayerVehicleExit", so, stopEvent)
  85.     removeEventHandler("onPlayerWasted", so, stopEvent)
  86.     removeEventHandler("onPlayerLogin", root, loginPlr)
  87.     so = nil
  88. end
  89.  
  90. function plrTeamChanged(newTeam)
  91.     if (not isRunning) then
  92.         return false
  93.     end
  94.     if (source == so) then
  95.         stopEvent()
  96.         return true
  97.     end
  98.     if (getTeamName(newTeam) == "Civilian Workers") then
  99.         local x, y, z = getElementPosition(so)
  100.         outputChatBox("State Official " ..getPlayerName(so).. " is hosting SO chase event! Try to hit his " ..getVehicleNameFromModel(getElementModel(getPedOccupiedVehicle(so))).. " and win $" ..money.. ", his location is " ..getZoneName(x, y, z), source, 255, 167, 0)
  101.         setElementVisibleTo(soBlip, source, true)
  102.     end
  103.     if (soBlip and isElementVisibleTo(soBlip, source)) then
  104.         setElementVisibleTo(soBlip, source, false)
  105.     end
  106. end
  107. addEventHandler("onPlayerChangeTeam", root, plrTeamChanged)
  108.  
  109. function loginPlr()
  110.     local plrTeam = getPlayerTeam(source)
  111.     if (getTeamName(plrTeam) == "Civilian Workers") then
  112.         local x, y, z = getElementPosition(so)
  113.         outputChatBox("State Official " ..getPlayerName(so).. " is hosting SO chase event! Try to hit his " ..getVehicleNameFromModel(getElementModel(getPedOccupiedVehicle(so))).. " and win $" ..money.. ", his location is " ..getZoneName(x, y, z), source, 255, 167, 0)
  114.         setElementVisibleTo(soBlip, source, true)
  115.     end
  116. end
Add Comment
Please, Sign In to add comment