Advertisement
Guest User

Untitled

a guest
May 8th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 34.69 KB | None | 0 0
  1. local CurrentActionData, handcuffTimer, dragStatus, currentTask = {}, {}, {}, {}
  2. local HasAlreadyEnteredMarker, isDead, isHandcuffed, hasAlreadyJoined, playerInService = false, false, false, false, false
  3. local LastStation, LastPart, LastPartNum, LastEntity, CurrentAction, CurrentActionMsg
  4. dragStatus.isDragged, isInShopMenu = false, false
  5. ESX = nil
  6.  
  7. Citizen.CreateThread(function()
  8.     while ESX == nil do
  9.         TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  10.         Citizen.Wait(0)
  11.     end
  12.  
  13.     while ESX.GetPlayerData().job2 == nil do
  14.         Citizen.Wait(10)
  15.     end
  16.  
  17.     ESX.PlayerData = ESX.GetPlayerData()
  18. end)
  19.  
  20.  
  21. RegisterNetEvent('esx:setJob2')
  22. AddEventHandler('esx:setJob2', function(job2)
  23.     PlayerData.job2 = job2
  24. end)
  25.  
  26.  
  27. function cleanPlayer(playerPed)
  28.     SetPedArmour(playerPed, 0)
  29.     ClearPedBloodDamage(playerPed)
  30.     ResetPedVisibleDamage(playerPed)
  31.     ClearPedLastWeaponDamage(playerPed)
  32.     ResetPedMovementClipset(playerPed, 0)
  33. end
  34.  
  35. function setUniform(uniform, playerPed)
  36.     TriggerEvent('skinchanger:getSkin', function(skin)
  37.         local uniformObject
  38.  
  39.         if skin.sex == 0 then
  40.             uniformObject = Config.Uniforms[uniform].male
  41.         else
  42.             uniformObject = Config.Uniforms[uniform].female
  43.         end
  44.  
  45.         if uniformObject then
  46.             TriggerEvent('skinchanger:loadClothes', skin, uniformObject)
  47.  
  48.             if uniform == 'bullet_wear' then
  49.                 SetPedArmour(playerPed, 100)
  50.             end
  51.         else
  52.             ESX.ShowNotification(_U('no_outfit'))
  53.         end
  54.     end)
  55. end
  56.  
  57. function OpenCloakroomMenu()
  58.     local playerPed = PlayerPedId()
  59.     local grade = ESX.PlayerData.job2.grade_name
  60.  
  61.     local elements = {
  62.         {label = _U('citizen_wear'), value = 'citizen_wear'},
  63.         {label = _U('rhodes_wear'), uniform = grade},
  64.         {label = _U('work_wear'), uniform = 'work_wear'},
  65.         {label = _U('workv2_wear'), uniform = 'workv2_wear'}
  66.     }
  67.  
  68.     if Config.EnableCustomPeds then
  69.         for k,v in ipairs(Config.CustomPeds.shared) do
  70.             table.insert(elements, {label = v.label, value = 'freemode_ped', maleModel = v.maleModel, femaleModel = v.femaleModel})
  71.         end
  72.  
  73.         for k,v in ipairs(Config.CustomPeds[grade]) do
  74.             table.insert(elements, {label = v.label, value = 'freemode_ped', maleModel = v.maleModel, femaleModel = v.femaleModel})
  75.         end
  76.     end
  77.  
  78.     ESX.UI.Menu.CloseAll()
  79.  
  80.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom', {
  81.         title    = _U('cloakroom'),
  82.         align    = 'top-left',
  83.         elements = elements
  84.     }, function(data, menu)
  85.         cleanPlayer(playerPed)
  86.  
  87.         if data.current.value == 'citizen_wear' then
  88.             if Config.EnableNonFreemodePeds then
  89.                 ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
  90.                     local isMale = skin.sex == 0
  91.  
  92.                     TriggerEvent('skinchanger:loadDefaultModel', isMale, function()
  93.                         ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
  94.                             TriggerEvent('skinchanger:loadSkin', skin)
  95.                             TriggerEvent('esx:restoreLoadout')
  96.                         end)
  97.                     end)
  98.  
  99.                 end)
  100.             else
  101.                 ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
  102.                     TriggerEvent('skinchanger:loadSkin', skin)
  103.                 end)
  104.             end
  105.         end
  106.  
  107.         if data.current.uniform then
  108.             setUniform(data.current.uniform, playerPed)
  109.         elseif data.current.value == 'freemode_ped' then
  110.             local modelHash
  111.  
  112.             ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
  113.                 if skin.sex == 0 then
  114.                     modelHash = GetHashKey(data.current.maleModel)
  115.                 else
  116.                     modelHash = GetHashKey(data.current.femaleModel)
  117.                 end
  118.  
  119.                 ESX.Streaming.RequestModel(modelHash, function()
  120.                     SetPlayerModel(PlayerId(), modelHash)
  121.                     SetModelAsNoLongerNeeded(modelHash)
  122.                     SetPedDefaultComponentVariation(PlayerPedId())
  123.  
  124.                     TriggerEvent('esx:restoreLoadout')
  125.                 end)
  126.             end)
  127.         end
  128.     end, function(data, menu)
  129.         menu.close()
  130.  
  131.         CurrentAction     = 'menu_cloakroom'
  132.         CurrentActionMsg  = _U('open_cloackroom')
  133.         CurrentActionData = {}
  134.     end)
  135. end
  136.  
  137. function OpenArmoryMenu(station)
  138.     local elements = {
  139.         {label = _U('buy_weapons'), value = 'buy_weapons'}
  140.     }
  141.  
  142.     if Config.EnableArmoryManagement then
  143.         table.insert(elements, {label = _U('get_weapon'),     value = 'get_weapon'})
  144.     end
  145.  
  146.     ESX.UI.Menu.CloseAll()
  147.  
  148.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory', {
  149.         title    = _U('armory'),
  150.         align    = 'top-left',
  151.         elements = elements
  152.     }, function(data, menu)
  153.  
  154.         if data.current.value == 'buy_weapons' then
  155.             OpenBuyWeaponsMenu()
  156.         end
  157.  
  158.     end, function(data, menu)
  159.         menu.close()
  160.  
  161.         CurrentAction     = 'menu_armory'
  162.         CurrentActionMsg  = _U('open_armory')
  163.         CurrentActionData = {station = station}
  164.     end)
  165. end
  166.  
  167. function OpenrhodesActionsMenu()
  168.     ESX.UI.Menu.CloseAll()
  169.  
  170.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'rhodes_actions', {
  171.         title    = 'rhodes',
  172.         align    = 'top-left',
  173.         elements = {
  174.             {label = _U('citizen_interaction'), value = 'citizen_interaction'},
  175.             {label = _U('vehicle_interaction'), value = 'vehicle_interaction'},
  176.     }}, function(data, menu)
  177.         if data.current.value == 'citizen_interaction' then
  178.             local elements = {
  179.                 {label = _U('id_card'), value = 'identity_card'},
  180.                 {label = _U('search'), value = 'search'},
  181.                 {label = _U('handcuff'), value = 'handcuff'},
  182.                 {label = _U('drag'), value = 'drag'},
  183.                 {label = _U('put_in_vehicle'), value = 'put_in_vehicle'},
  184.                 {label = _U('out_the_vehicle'), value = 'out_the_vehicle'},
  185.             }
  186.  
  187.             ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', {
  188.                 title    = _U('citizen_interaction'),
  189.                 align    = 'top-left',
  190.                 elements = elements
  191.             }, function(data2, menu2)
  192.                 local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
  193.                 if closestPlayer ~= -1 and closestDistance <= 3.0 then
  194.                     local action = data2.current.value
  195.  
  196.                     if action == 'identity_card' then
  197.                         OpenIdentityCardMenu(closestPlayer)
  198.                     elseif action == 'search' then
  199.                         OpenBodySearchMenu(closestPlayer)
  200.                     elseif action == 'handcuff' then
  201.                         TriggerServerEvent('r_rhodes:handcuff', GetPlayerServerId(closestPlayer))
  202.                     elseif action == 'drag' then
  203.                         TriggerServerEvent('r_rhodes:drag', GetPlayerServerId(closestPlayer))
  204.                     elseif action == 'put_in_vehicle' then
  205.                         TriggerServerEvent('r_rhodes:putInVehicle', GetPlayerServerId(closestPlayer))
  206.                     elseif action == 'out_the_vehicle' then
  207.                         TriggerServerEvent('r_rhodes:OutVehicle', GetPlayerServerId(closestPlayer))
  208.                     end
  209.                 else
  210.                     ESX.ShowNotification(_U('no_players_nearby'))
  211.                 end
  212.             end, function(data2, menu2)
  213.                 menu2.close()
  214.             end)
  215.         elseif data.current.value == 'vehicle_interaction' then
  216.             local elements  = {}
  217.             local playerPed = PlayerPedId()
  218.             local vehicle = ESX.Game.GetVehicleInDirection()
  219.  
  220.             if DoesEntityExist(vehicle) then
  221.                 table.insert(elements, {label = _U('vehicle_info'), value = 'vehicle_infos'})
  222.                 table.insert(elements, {label = _U('pick_lock'), value = 'hijack_vehicle'})
  223.                 table.insert(elements, {label = _U('impound'), value = 'impound'})
  224.             end
  225.  
  226.             table.insert(elements, {label = _U('search_database'), value = 'search_database'})
  227.  
  228.             ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_interaction', {
  229.                 title    = _U('vehicle_interaction'),
  230.                 align    = 'top-left',
  231.                 elements = elements
  232.             }, function(data2, menu2)
  233.                 local coords  = GetEntityCoords(playerPed)
  234.                 vehicle = ESX.Game.GetVehicleInDirection()
  235.                 action  = data2.current.value
  236.  
  237.                 if action == 'search_database' then
  238.                     LookupVehicle()
  239.                 elseif DoesEntityExist(vehicle) then
  240.                     if action == 'vehicle_infos' then
  241.                         local vehicleData = ESX.Game.GetVehicleProperties(vehicle)
  242.                         OpenVehicleInfosMenu(vehicleData)
  243.                     elseif action == 'hijack_vehicle' then
  244.                         if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 3.0) then
  245.                             TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_WELDING', 0, true)
  246.                             Citizen.Wait(20000)
  247.                             ClearPedTasksImmediately(playerPed)
  248.  
  249.                             SetVehicleDoorsLocked(vehicle, 1)
  250.                             SetVehicleDoorsLockedForAllPlayers(vehicle, false)
  251.                             ESX.ShowNotification(_U('vehicle_unlocked'))
  252.                         end
  253.                     elseif action == 'impound' then
  254.                         if currentTask.busy then
  255.                             return
  256.                         end
  257.  
  258.                         ESX.ShowHelpNotification(_U('impound_prompt'))
  259.                         TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
  260.  
  261.                         currentTask.busy = true
  262.                         currentTask.task = ESX.SetTimeout(10000, function()
  263.                             ClearPedTasks(playerPed)
  264.                             ImpoundVehicle(vehicle)
  265.                             Citizen.Wait(100)
  266.                         end)
  267.  
  268.                         Citizen.CreateThread(function()
  269.                             while currentTask.busy do
  270.                                 Citizen.Wait(1000)
  271.  
  272.                                 vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 3.0, 0, 71)
  273.                                 if not DoesEntityExist(vehicle) and currentTask.busy then
  274.                                     ESX.ShowNotification(_U('impound_canceled_moved'))
  275.                                     ESX.ClearTimeout(currentTask.task)
  276.                                     ClearPedTasks(playerPed)
  277.                                     currentTask.busy = false
  278.                                     break
  279.                                 end
  280.                             end
  281.                         end)
  282.                     end
  283.                 else
  284.                     ESX.ShowNotification(_U('no_vehicles_nearby'))
  285.                 end
  286.  
  287.             end, function(data2, menu2)
  288.                 menu2.close()
  289.             end)
  290.         end
  291.     end, function(data, menu)
  292.         menu.close()
  293.     end)
  294. end
  295.  
  296. function OpenIdentityCardMenu(player)
  297.     ESX.TriggerServerCallback('r_rhodes:getOtherPlayerData', function(data)
  298.         local elements = {
  299.             {label = _U('name', data.name)},
  300.             {label = _U('job2', ('%s - %s'):format(data.job2, data.grade))}
  301.         }
  302.  
  303.         if Config.EnableESXIdentity then
  304.             table.insert(elements, {label = _U('sex', _U(data.sex))})
  305.             table.insert(elements, {label = _U('dob', data.dob)})
  306.             table.insert(elements, {label = _U('height', data.height)})
  307.         end
  308.  
  309.         if data.drunk then
  310.             table.insert(elements, {label = _U('bac', data.drunk)})
  311.         end
  312.  
  313.         ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', {
  314.             title    = _U('citizen_interaction'),
  315.             align    = 'top-left',
  316.             elements = elements
  317.         }, nil, function(data, menu)
  318.             menu.close()
  319.         end)
  320.     end, GetPlayerServerId(player))
  321. end
  322.  
  323. function OpenBodySearchMenu(player)
  324.     ESX.TriggerServerCallback('r_rhodes:getOtherPlayerData', function(data)
  325.         local elements = {}
  326.  
  327.         for i=1, #data.accounts, 1 do
  328.             if data.accounts[i].name == 'black_money' and data.accounts[i].money > 0 then
  329.                 table.insert(elements, {
  330.                     label    = _U('confiscate_dirty', ESX.Math.Round(data.accounts[i].money)),
  331.                     value    = 'black_money',
  332.                     itemType = 'item_account',
  333.                     amount   = data.accounts[i].money
  334.                 })
  335.  
  336.                 break
  337.             end
  338.         end
  339.  
  340.         table.insert(elements, {label = _U('guns_label')})
  341.  
  342.         for i=1, #data.weapons, 1 do
  343.             table.insert(elements, {
  344.                 label    = _U('confiscate_weapon', ESX.GetWeaponLabel(data.weapons[i].name), data.weapons[i].ammo),
  345.                 value    = data.weapons[i].name,
  346.                 itemType = 'item_weapon',
  347.                 amount   = data.weapons[i].ammo
  348.             })
  349.         end
  350.  
  351.         table.insert(elements, {label = _U('inventory_label')})
  352.  
  353.         for i=1, #data.inventory, 1 do
  354.             if data.inventory[i].count > 0 then
  355.                 table.insert(elements, {
  356.                     label    = _U('confiscate_inv', data.inventory[i].count, data.inventory[i].label),
  357.                     value    = data.inventory[i].name,
  358.                     itemType = 'item_standard',
  359.                     amount   = data.inventory[i].count
  360.                 })
  361.             end
  362.         end
  363.  
  364.         ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'body_search', {
  365.             title    = _U('search'),
  366.             align    = 'top-left',
  367.             elements = elements
  368.         }, function(data, menu)
  369.             if data.current.value then
  370.                 TriggerServerEvent('r_rhodes:confiscatePlayerItem', GetPlayerServerId(player), data.current.itemType, data.current.value, data.current.amount)
  371.                 OpenBodySearchMenu(player)
  372.             end
  373.         end, function(data, menu)
  374.             menu.close()
  375.         end)
  376.     end, GetPlayerServerId(player))
  377. end
  378.  
  379. function LookupVehicle()
  380.     ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'lookup_vehicle', {
  381.         title = _U('search_database_title'),
  382.     }, function(data, menu)
  383.         local length = string.len(data.value)
  384.         if not data.value or length < 2 or length > 8 then
  385.             ESX.ShowNotification(_U('search_database_error_invalid'))
  386.         else
  387.             ESX.TriggerServerCallback('r_rhodes:getVehicleInfos', function(retrivedInfo)
  388.                 local elements = {{label = _U('plate', retrivedInfo.plate)}}
  389.                 menu.close()
  390.  
  391.                 if not retrivedInfo.owner then
  392.                     table.insert(elements, {label = _U('owner_unknown')})
  393.                 else
  394.                     table.insert(elements, {label = _U('owner', retrivedInfo.owner)})
  395.                 end
  396.  
  397.                 ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_infos', {
  398.                     title    = _U('vehicle_info'),
  399.                     align    = 'top-left',
  400.                     elements = elements
  401.                 }, nil, function(data2, menu2)
  402.                     menu2.close()
  403.                 end)
  404.             end, data.value)
  405.  
  406.         end
  407.     end, function(data, menu)
  408.         menu.close()
  409.     end)
  410. end
  411.  
  412. function OpenVehicleInfosMenu(vehicleData)
  413.     ESX.TriggerServerCallback('r_rhodes:getVehicleInfos', function(retrivedInfo)
  414.         local elements = {{label = _U('plate', retrivedInfo.plate)}}
  415.  
  416.         if not retrivedInfo.owner then
  417.             table.insert(elements, {label = _U('owner_unknown')})
  418.         else
  419.             table.insert(elements, {label = _U('owner', retrivedInfo.owner)})
  420.         end
  421.  
  422.         ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_infos', {
  423.             title    = _U('vehicle_info'),
  424.             align    = 'top-left',
  425.             elements = elements
  426.         }, nil, function(data, menu)
  427.             menu.close()
  428.         end)
  429.     end, vehicleData.plate)
  430. end
  431.  
  432. function OpenBuyWeaponsMenu()
  433.     local elements = {}
  434.     local playerPed = PlayerPedId()
  435.  
  436.     for k,v in ipairs(Config.AuthorizedWeapons[ESX.PlayerData.job2.grade_name]) do
  437.         local weaponNum, weapon = ESX.GetWeapon(v.weapon)
  438.         local components, label = {}
  439.         local hasWeapon = HasPedGotWeapon(playerPed, GetHashKey(v.weapon), false)
  440.  
  441.         if v.components then
  442.             for i=1, #v.components do
  443.                 if v.components[i] then
  444.                     local component = weapon.components[i]
  445.                     local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash)
  446.  
  447.                     if hasComponent then
  448.                         label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_owned'))
  449.                     else
  450.                         if v.components[i] > 0 then
  451.                             label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_item', ESX.Math.GroupDigits(v.components[i])))
  452.                         else
  453.                             label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_free'))
  454.                         end
  455.                     end
  456.  
  457.                     table.insert(components, {
  458.                         label = label,
  459.                         componentLabel = component.label,
  460.                         hash = component.hash,
  461.                         name = component.name,
  462.                         price = v.components[i],
  463.                         hasComponent = hasComponent,
  464.                         componentNum = i
  465.                     })
  466.                 end
  467.             end
  468.         end
  469.  
  470.         if hasWeapon and v.components then
  471.             label = ('%s: <span style="color:green;">></span>'):format(weapon.label)
  472.         elseif hasWeapon and not v.components then
  473.             label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_owned'))
  474.         else
  475.             if v.price > 0 then
  476.                 label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_item', ESX.Math.GroupDigits(v.price)))
  477.             else
  478.                 label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_free'))
  479.             end
  480.         end
  481.  
  482.         table.insert(elements, {
  483.             label = label,
  484.             weaponLabel = weapon.label,
  485.             name = weapon.name,
  486.             components = components,
  487.             price = v.price,
  488.             hasWeapon = hasWeapon
  489.         })
  490.     end
  491.  
  492.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_buy_weapons', {
  493.         title    = _U('armory_weapontitle'),
  494.         align    = 'top-left',
  495.         elements = elements
  496.     }, function(data, menu)
  497.         if data.current.hasWeapon then
  498.             if #data.current.components > 0 then
  499.                 OpenWeaponComponentShop(data.current.components, data.current.name, menu)
  500.             end
  501.         else
  502.             ESX.TriggerServerCallback('r_rhodes:buyWeapon', function(bought)
  503.                 if bought then
  504.                     if data.current.price > 0 then
  505.                         ESX.ShowNotification(_U('armory_bought', data.current.weaponLabel, ESX.Math.GroupDigits(data.current.price)))
  506.                     end
  507.  
  508.                     menu.close()
  509.                     OpenBuyWeaponsMenu()
  510.                 else
  511.                     ESX.ShowNotification(_U('armory_money'))
  512.                 end
  513.             end, data.current.name, 1)
  514.         end
  515.     end, function(data, menu)
  516.         menu.close()
  517.     end)
  518. end
  519.  
  520. AddEventHandler('r_rhodes:hasEnteredMarker', function(station, part, partNum)
  521.     if part == 'Cloakroom' then
  522.         CurrentAction     = 'menu_cloakroom'
  523.         CurrentActionMsg  = _U('open_cloackroom')
  524.         CurrentActionData = {}
  525.     elseif part == 'Armory' then
  526.         CurrentAction     = 'menu_armory'
  527.         CurrentActionMsg  = _U('open_armory')
  528.         CurrentActionData = {station = station}
  529.     end
  530. end)
  531.  
  532. AddEventHandler('r_rhodes:hasExitedMarker', function(station, part, partNum)
  533.     if not isInShopMenu then
  534.         ESX.UI.Menu.CloseAll()
  535.     end
  536.  
  537.     CurrentAction = nil
  538. end)
  539.  
  540. RegisterNetEvent('r_rhodes:handcuff')
  541. AddEventHandler('r_rhodes:handcuff', function()
  542.     isHandcuffed = not isHandcuffed
  543.     local playerPed = PlayerPedId()
  544.  
  545.     if isHandcuffed then
  546.         RequestAnimDict('mp_arresting')
  547.         while not HasAnimDictLoaded('mp_arresting') do
  548.             Citizen.Wait(100)
  549.         end
  550.  
  551.         TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0, 0, 0, 0)
  552.  
  553.         SetEnableHandcuffs(playerPed, true)
  554.         DisablePlayerFiring(playerPed, true)
  555.         SetCurrentPedWeapon(playerPed, GetHashKey('WEAPON_UNARMED'), true)
  556.         SetPedCanPlayGestureAnims(playerPed, false)
  557.         FreezeEntityPosition(playerPed, false)
  558.         DisplayRadar(false)
  559.  
  560.         if Config.EnableHandcuffTimer then
  561.             if handcuffTimer.active then
  562.                 ESX.ClearTimeout(handcuffTimer.task)
  563.             end
  564.  
  565.             StartHandcuffTimer()
  566.         end
  567.     else
  568.         if Config.EnableHandcuffTimer and handcuffTimer.active then
  569.             ESX.ClearTimeout(handcuffTimer.task)
  570.         end
  571.  
  572.         ClearPedSecondaryTask(playerPed)
  573.         SetEnableHandcuffs(playerPed, false)
  574.         DisablePlayerFiring(playerPed, false)
  575.         SetPedCanPlayGestureAnims(playerPed, true)
  576.         FreezeEntityPosition(playerPed, false)
  577.         DisplayRadar(true)
  578.     end
  579. end)
  580.  
  581. RegisterNetEvent('r_rhodes:unrestrain')
  582. AddEventHandler('r_rhodes:unrestrain', function()
  583.     if isHandcuffed then
  584.         local playerPed = PlayerPedId()
  585.         isHandcuffed = false
  586.  
  587.         ClearPedSecondaryTask(playerPed)
  588.         SetEnableHandcuffs(playerPed, false)
  589.         DisablePlayerFiring(playerPed, false)
  590.         SetPedCanPlayGestureAnims(playerPed, true)
  591.         FreezeEntityPosition(playerPed, false)
  592.         DisplayRadar(true)
  593.  
  594.         if Config.EnableHandcuffTimer and handcuffTimer.active then
  595.             ESX.ClearTimeout(handcuffTimer.task)
  596.         end
  597.     end
  598. end)
  599.  
  600. RegisterNetEvent('r_rhodes:drag')
  601. AddEventHandler('r_rhodes:drag', function(copId)
  602.     if isHandcuffed then
  603.         dragStatus.isDragged = not dragStatus.isDragged
  604.         dragStatus.CopId = copId
  605.     end
  606. end)
  607.  
  608. Citizen.CreateThread(function()
  609.     local wasDragged
  610.  
  611.     while true do
  612.         Citizen.Wait(0)
  613.         local playerPed = PlayerPedId()
  614.  
  615.         if isHandcuffed and dragStatus.isDragged then
  616.             local targetPed = GetPlayerPed(GetPlayerFromServerId(dragStatus.CopId))
  617.  
  618.             if DoesEntityExist(targetPed) and IsPedOnFoot(targetPed) and not IsPedDeadOrDying(targetPed, true) then
  619.                 if not wasDragged then
  620.                     AttachEntityToEntity(playerPed, targetPed, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
  621.                     wasDragged = true
  622.                 else
  623.                     Citizen.Wait(1000)
  624.                 end
  625.             else
  626.                 wasDragged = false
  627.                 dragStatus.isDragged = false
  628.                 DetachEntity(playerPed, true, false)
  629.             end
  630.         elseif wasDragged then
  631.             wasDragged = false
  632.             DetachEntity(playerPed, true, false)
  633.         else
  634.             Citizen.Wait(500)
  635.         end
  636.     end
  637. end)
  638.  
  639. RegisterNetEvent('r_rhodes:putInVehicle')
  640. AddEventHandler('r_rhodes:putInVehicle', function()
  641.     if isHandcuffed then
  642.         local playerPed = PlayerPedId()
  643.         local coords = GetEntityCoords(playerPed)
  644.  
  645.         if IsAnyVehicleNearPoint(coords, 5.0) then
  646.             local vehicle = GetClosestVehicle(coords, 5.0, 0, 71)
  647.  
  648.             if DoesEntityExist(vehicle) then
  649.                 local maxSeats, freeSeat = GetVehicleMaxNumberOfPassengers(vehicle)
  650.  
  651.                 for i=maxSeats - 1, 0, -1 do
  652.                     if IsVehicleSeatFree(vehicle, i) then
  653.                         freeSeat = i
  654.                         break
  655.                     end
  656.                 end
  657.  
  658.                 if freeSeat then
  659.                     TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
  660.                     dragStatus.isDragged = false
  661.                 end
  662.             end
  663.         end
  664.     end
  665. end)
  666.  
  667. RegisterNetEvent('r_rhodes:OutVehicle')
  668. AddEventHandler('r_rhodes:OutVehicle', function()
  669.     local playerPed = PlayerPedId()
  670.  
  671.     if IsPedSittingInAnyVehicle(playerPed) then
  672.         local vehicle = GetVehiclePedIsIn(playerPed, false)
  673.         TaskLeaveVehicle(playerPed, vehicle, 16)
  674.     end
  675. end)
  676.  
  677. Citizen.CreateThread(function()
  678.     while true do
  679.         Citizen.Wait(0)
  680.         local playerPed = PlayerPedId()
  681.  
  682.         if isHandcuffed then
  683.             DisableControlAction(0, 1, true)
  684.             DisableControlAction(0, 2, true)
  685.             DisableControlAction(0, 24, true)
  686.             DisableControlAction(0, 257, true)
  687.             DisableControlAction(0, 25, true)
  688.             DisableControlAction(0, 263, true)
  689.  
  690.             DisableControlAction(0, 45, true)
  691.             DisableControlAction(0, 22, true)
  692.             DisableControlAction(0, 44, true)
  693.             DisableControlAction(0, 37, true)
  694.             DisableControlAction(0, 23, true)
  695.  
  696.             DisableControlAction(0, 288,  true)
  697.             DisableControlAction(0, 289, true)
  698.             DisableControlAction(0, 170, true)
  699.             DisableControlAction(0, 167, true)
  700.  
  701.             DisableControlAction(0, 0, true)
  702.             DisableControlAction(0, 26, true)
  703.             DisableControlAction(0, 73, true)
  704.             DisableControlAction(2, 199, true)
  705.  
  706.             DisableControlAction(0, 59, true)
  707.             DisableControlAction(0, 71, true)
  708.             DisableControlAction(0, 72, true)
  709.  
  710.             DisableControlAction(2, 36, true)
  711.  
  712.             DisableControlAction(0, 47, true)  
  713.             DisableControlAction(0, 264, true)
  714.             DisableControlAction(0, 257, true)
  715.             DisableControlAction(0, 140, true)
  716.             DisableControlAction(0, 141, true)
  717.             DisableControlAction(0, 142, true)
  718.             DisableControlAction(0, 143, true)
  719.             DisableControlAction(0, 75, true)
  720.             DisableControlAction(27, 75, true)
  721.  
  722.             if IsEntityPlayingAnim(playerPed, 'mp_arresting', 'idle', 3) ~= 1 then
  723.                 ESX.Streaming.RequestAnimDict('mp_arresting', function()
  724.                     TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0.0, false, false, false)
  725.                 end)
  726.             end
  727.         else
  728.             Citizen.Wait(500)
  729.         end
  730.     end
  731. end)
  732.  
  733. Citizen.CreateThread(function()
  734.     while true do
  735.         Citizen.Wait(0)
  736.  
  737.         if ESX.PlayerData.job2 and ESX.PlayerData.job2.name == 'rhodes' then
  738.             local playerPed = PlayerPedId()
  739.             local playerCoords = GetEntityCoords(playerPed)
  740.             local isInMarker, hasExited, letSleep = false, false, true
  741.             local currentStation, currentPart, currentPartNum
  742.  
  743.             for k,v in pairs(Config.rhodesStations) do
  744.                 for i=1, #v.Cloakrooms, 1 do
  745.                     local distance = #(playerCoords - v.Cloakrooms[i])
  746.  
  747.                     if distance < Config.DrawDistance then
  748.                         DrawMarker(20, v.Cloakrooms[i], 0.0, 0.0, 0.0, 0, 0.0, 0.0, 0.5, 0.5, 0.5, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
  749.                         letSleep = false
  750.  
  751.                         if distance < Config.MarkerSize.x then
  752.                             isInMarker, currentStation, currentPart, currentPartNum = true, k, 'Cloakroom', i
  753.                         end
  754.                     end
  755.                 end
  756.  
  757.                 for i=1, #v.Armories, 1 do
  758.                     local distance = #(playerCoords - v.Armories[i])
  759.  
  760.                     if distance < Config.DrawDistance then
  761.                         DrawMarker(20, v.Armories[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
  762.                         letSleep = false
  763.  
  764.                         if distance < Config.MarkerSize.x then
  765.                             isInMarker, currentStation, currentPart, currentPartNum = true, k, 'Armory', i
  766.                         end
  767.                     end
  768.                 end
  769.             end
  770.  
  771.             if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastStation ~= currentStation or LastPart ~= currentPart or LastPartNum ~= currentPartNum)) then
  772.                 if
  773.                     (LastStation and LastPart and LastPartNum) and
  774.                     (LastStation ~= currentStation or LastPart ~= currentPart or LastPartNum ~= currentPartNum)
  775.                 then
  776.                     TriggerEvent('r_rhodes:hasExitedMarker', LastStation, LastPart, LastPartNum)
  777.                     hasExited = true
  778.                 end
  779.  
  780.                 HasAlreadyEnteredMarker = true
  781.                 LastStation             = currentStation
  782.                 LastPart                = currentPart
  783.                 LastPartNum             = currentPartNum
  784.  
  785.                 TriggerEvent('r_rhodes:hasEnteredMarker', currentStation, currentPart, currentPartNum)
  786.             end
  787.  
  788.             if not hasExited and not isInMarker and HasAlreadyEnteredMarker then
  789.                 HasAlreadyEnteredMarker = false
  790.                 TriggerEvent('r_rhodes:hasExitedMarker', LastStation, LastPart, LastPartNum)
  791.             end
  792.  
  793.             if letSleep then
  794.                 Citizen.Wait(500)
  795.             end
  796.         else
  797.             Citizen.Wait(500)
  798.         end
  799.     end
  800. end)
  801.  
  802. Citizen.CreateThread(function()
  803.     while true do
  804.         Citizen.Wait(0)
  805.  
  806.         if CurrentAction then
  807.             ESX.ShowHelpNotification(CurrentActionMsg)
  808.  
  809.             if IsControlJustReleased(0, 38) and ESX.PlayerData.job2 and ESX.PlayerData.job2.name == 'rhodes' then
  810.  
  811.                 if CurrentAction == 'menu_cloakroom' then
  812.                     OpenCloakroomMenu()
  813.                 elseif CurrentAction == 'menu_armory' then
  814.                         OpenArmoryMenu(CurrentActionData.station)
  815.                 elseif CurrentAction == 'remove_entity' then
  816.                     DeleteEntity(CurrentActionData.entity)
  817.                 end
  818.  
  819.                 CurrentAction = nil
  820.             end
  821.         end
  822.  
  823.         if IsControlJustReleased(0, 167) and not isDead and ESX.PlayerData.job2 and ESX.PlayerData.job2.name == 'rhodes' and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'rhodes_actions') then
  824.                 OpenrhodesActionsMenu()
  825.         end
  826.  
  827.         if IsControlJustReleased(0, 38) and currentTask.busy then
  828.             ESX.ShowNotification(_U('impound_canceled'))
  829.             ESX.ClearTimeout(currentTask.task)
  830.             ClearPedTasks(PlayerPedId())
  831.  
  832.             currentTask.busy = false
  833.         end
  834.     end
  835. end)
  836.  
  837. AddEventHandler('playerSpawned', function(spawn)
  838.     isDead = false
  839.     TriggerEvent('r_rhodes:unrestrain')
  840.  
  841.     if not hasAlreadyJoined then
  842.         TriggerServerEvent('r_rhodes:spawned')
  843.     end
  844.     hasAlreadyJoined = true
  845. end)
  846.  
  847. AddEventHandler('esx:onPlayerDeath', function(data)
  848.     isDead = true
  849. end)
  850.  
  851. AddEventHandler('onResourceStop', function(resource)
  852.     if resource == GetCurrentResourceName() then
  853.         TriggerEvent('r_rhodes:unrestrain')
  854.  
  855.         if Config.EnableHandcuffTimer and handcuffTimer.active then
  856.             ESX.ClearTimeout(handcuffTimer.task)
  857.         end
  858.     end
  859. end)
  860.  
  861. function StartHandcuffTimer()
  862.     if Config.EnableHandcuffTimer and handcuffTimer.active then
  863.         ESX.ClearTimeout(handcuffTimer.task)
  864.     end
  865.  
  866.     handcuffTimer.active = true
  867.  
  868.     handcuffTimer.task = ESX.SetTimeout(Config.HandcuffTimer, function()
  869.         ESX.ShowNotification(_U('unrestrained_timer'))
  870.         TriggerEvent('r_rhodes:unrestrain')
  871.         handcuffTimer.active = false
  872.     end)
  873. end
  874.  
  875. local PlayerData              = {}
  876.  
  877. Citizen.CreateThread(function ()
  878.     while ESX == nil do
  879.         TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  880.         Citizen.Wait(1)
  881.     end
  882.  
  883.     while ESX.GetPlayerData() == nil do
  884.         Citizen.Wait(10)
  885.     end
  886.  
  887.     PlayerData = ESX.GetPlayerData()
  888.  
  889.     LoadMarkers()
  890. end)
  891.  
  892. RegisterNetEvent('esx:playerLoaded')
  893. AddEventHandler('esx:playerLoaded', function(xPlayer)
  894.     PlayerData = xPlayer
  895. end)
  896.  
  897. function LoadMarkers()
  898.     Citizen.CreateThread(function()
  899.    
  900.         while true do
  901.             Citizen.Wait(5)
  902.  
  903.             local plyCoords = GetEntityCoords(PlayerPedId())
  904.  
  905.             for location, val in pairs(Config.Teleporters) do
  906.  
  907.                 local Enter = val['Enter']
  908.                 local Exit = val['Exit']
  909.                 local Job2Needed = val['Job2']
  910.  
  911.                 local dstCheckEnter, dstCheckExit = GetDistanceBetweenCoords(plyCoords, Enter['x'], Enter['y'], Enter['z'], true), GetDistanceBetweenCoords(plyCoords, Exit['x'], Exit['y'], Exit['z'], true)
  912.  
  913.                 if dstCheckEnter <= 7.5 then
  914.                     if Job2Needed ~= 'none' then
  915.                         if PlayerData.job2.name == Job2Needed then
  916.  
  917.                             if dstCheckEnter <= 1.2 then
  918.                                 if IsControlJustPressed(0, 38) then
  919.                                     Teleport(val, 'enter')
  920.                                 end
  921.                             end
  922.  
  923.                         end
  924.                     else
  925.  
  926.                         if dstCheckEnter <= 1.2 then
  927.  
  928.                             if IsControlJustPressed(0, 38) then
  929.                                 Teleport(val, 'enter')
  930.                             end
  931.  
  932.                         end
  933.  
  934.                     end
  935.                 end
  936.  
  937.                 if dstCheckExit <= 7.5 then
  938.                     if Job2Needed ~= 'none' then
  939.                         if PlayerData.job2.name == Job2Needed then
  940.  
  941.  
  942.                             if dstCheckExit <= 1.2 then
  943.                                 if IsControlJustPressed(0, 38) then
  944.                                     Teleport(val, 'exit')
  945.                                 end
  946.                             end
  947.  
  948.                         end
  949.                     else
  950.  
  951.  
  952.                         if dstCheckExit <= 1.2 then
  953.  
  954.                             if IsControlJustPressed(0, 38) then
  955.                                 Teleport(val, 'exit')
  956.                             end
  957.  
  958.                         end
  959.                     end
  960.                 end
  961.  
  962.             end
  963.  
  964.         end
  965.  
  966.     end)
  967. end
  968.  
  969. function Teleport(table, location)
  970.     if location == 'enter' then
  971.         DoScreenFadeOut(100)
  972.  
  973.         Citizen.Wait(750)
  974.  
  975.         ESX.Game.Teleport(PlayerPedId(), table['Exit'])
  976.  
  977.         DoScreenFadeIn(100)
  978.     else
  979.         DoScreenFadeOut(100)
  980.  
  981.         Citizen.Wait(750)
  982.  
  983.         ESX.Game.Teleport(PlayerPedId(), table['Enter'])
  984.  
  985.         DoScreenFadeIn(100)
  986.     end
  987. end
  988.  
  989.     local blips = {
  990.         {title="Rhodes Informatique", colour=3, id=606, x=263.7, y=-643.4, 108.468},
  991.         }
  992.  
  993. Citizen.CreateThread(function()
  994.  
  995.     for _, info in pairs(blips) do
  996.       info.blip = AddBlipForCoord(info.x, info.y, info.z)
  997.       SetBlipSprite(info.blip, info.id)
  998.       SetBlipDisplay(info.blip, 4)
  999.       SetBlipScale(info.blip, 0.8)
  1000.       SetBlipColour(info.blip, info.colour)
  1001.       SetBlipAsShortRange(info.blip, true)
  1002.       BeginTextCommandSetBlipName("STRING")
  1003.       AddTextComponentString(info.title)
  1004.       EndTextCommandSetBlipName(info.blip)
  1005.     end
  1006. end)
  1007.  
  1008. local CurrentActionData, this_Spawner = {}, {}
  1009. local HasAlreadyEnteredMarker, IsInMainMenu = false, false
  1010. local LastZone, CurrentAction, CurrentActionMsg
  1011.  
  1012. Citizen.CreateThread(function()
  1013.     while ESX == nil do
  1014.         TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  1015.         Citizen.Wait(0)
  1016.     end
  1017. end)
  1018.  
  1019. function OpenSpawnerMenu()
  1020.     IsInMainMenu = true
  1021.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_spawner', {
  1022.         title = _U('vehicle_spawner'),
  1023.         align = GetConvar('esx_MenuAlign', 'top-left'),
  1024.         elements = {
  1025.             {label = _U('default_veh'), value = 'default_veh'}
  1026.     }}, function(data, menu)
  1027.         local action = data.current.value
  1028.  
  1029.         if action == 'default_veh' then
  1030.             local elements2 = {}
  1031.  
  1032.             for i=1, #Config.Vehicles, 1 do
  1033.                  table.insert(elements2, {
  1034.                     label = Config.Vehicles[i].label,
  1035.                     model = Config.Vehicles[i].model
  1036.                  })
  1037.             end
  1038.  
  1039.             ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'default_veh', {
  1040.                 title = _U('default_veh'),
  1041.                 align = GetConvar('esx_MenuAlign', 'top-left'),
  1042.                 elements = elements2
  1043.             }, function(data, menu)
  1044.                 if ESX.Game.IsSpawnPointClear(this_Spawner.Loc, 5.0) then
  1045.                     IsInMainMenu = false
  1046.                     menu.close()
  1047.                     SpawnVehicle(data.current.model)
  1048.                     ESX.ShowNotification(_U('spawn_vehicle'))
  1049.                 else
  1050.                     ESX.ShowNotification(_U('spawnpoint_blocked'))
  1051.                 end
  1052.             end)
  1053.         end
  1054.     end, function(data, menu)
  1055.         IsInMainMenu = false
  1056.         menu.close()
  1057.         CurrentAction = 'spawner_point'
  1058.         CurrentActionMsg = _U('press_to_enter')
  1059.         CurrentActionData = {}
  1060.     end)
  1061. end
  1062.  
  1063. function OpenReturnMenu()
  1064.     local playerCoords = GetEntityCoords(PlayerPedId())
  1065.  
  1066.     vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 5.0)
  1067.     if #vehicles > 0 then
  1068.         for k,v in ipairs(vehicles) do
  1069.             ESX.Game.DeleteVehicle(v)
  1070.         end
  1071.     end
  1072. end
  1073.  
  1074. function SpawnVehicle(model)
  1075.     ESX.Game.SpawnVehicle(model, this_Spawner.Loc, this_Spawner.Heading)
  1076. end
  1077.  
  1078. AddEventHandler('esx_vehiclespawner:hasEnteredMarker', function(zone)
  1079.     if zone == 'spawner_point' then
  1080.         CurrentAction = 'spawner_point'
  1081.         CurrentActionMsg = _U('press_to_enter')
  1082.         CurrentActionData = {}
  1083.     elseif zone == 'deleter_point' then
  1084.         CurrentAction = 'deleter_point'
  1085.         CurrentActionMsg = _U('press_to_enter2')
  1086.         CurrentActionData = {}
  1087.     end
  1088. end)
  1089.  
  1090. AddEventHandler('esx_vehiclespawner:hasExitedMarker', function()
  1091.     if not IsInMainMenu or IsInMainMenu then
  1092.         ESX.UI.Menu.CloseAll()
  1093.     end
  1094.  
  1095.     CurrentAction = nil
  1096. end)
  1097.  
  1098. AddEventHandler('onResourceStop', function(resource)
  1099.     if resource == GetCurrentResourceName() then
  1100.         if IsInMainMenu then
  1101.             ESX.UI.Menu.CloseAll()
  1102.         end
  1103.     end
  1104. end)
  1105.  
  1106. Citizen.CreateThread(function()
  1107.     while true do
  1108.         Citizen.Wait(0)
  1109.         local plyCoords = GetEntityCoords(PlayerPedId())
  1110.         local playerCoords = GetEntityCoords(PlayerPedId())
  1111.         local isInMarker, letSleep, currentZone = false, true
  1112.        
  1113.         for k,v in pairs(Config.Zones) do
  1114.             local distance = #(playerCoords - v.Pos)
  1115.             local distance2 = #(playerCoords - v.Del)
  1116.            
  1117.             if distance < Config.DrawDistance then
  1118.                 letSleep = false
  1119.  
  1120.                 if ESX.PlayerData.job2.name == "rhodes" then
  1121.                  
  1122.                     if Config.MenuMarker.Type ~= -1 then
  1123.                         DrawMarker(Config.MenuMarker.Type, v.Pos, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MenuMarker.x, Config.MenuMarker.y, Config.MenuMarker.z, Config.MenuMarker.r, Config.MenuMarker.g, Config.MenuMarker.b, 100, false, true, 2, false, false, false, false)
  1124.                     end
  1125.                
  1126.                     if Config.DelMarker.Type ~= -1 then
  1127.                       DrawMarker(Config.DelMarker.Type, v.Del, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.DelMarker.x, Config.DelMarker.y, Config.DelMarker.z, Config.DelMarker.r, Config.DelMarker.g, Config.DelMarker.b, 100, false, true, 2, false, false, false, false)
  1128.                     end
  1129.                
  1130.                     if distance < Config.MenuMarker.x then
  1131.                         isInMarker, currentZone = true, 'spawner_point'
  1132.                         this_Spawner = v
  1133.                     end
  1134.                
  1135.                     if distance2 < Config.DelMarker.x then
  1136.                         isInMarker, currentZone = true, 'deleter_point'
  1137.                         this_Spawner = v
  1138.                     end
  1139.             end
  1140.         end
  1141.        
  1142.         if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
  1143.             HasAlreadyEnteredMarker, LastZone = true, currentZone
  1144.             TriggerEvent('esx_vehiclespawner:hasEnteredMarker', currentZone)
  1145.         end
  1146.        
  1147.         if not isInMarker and HasAlreadyEnteredMarker then
  1148.             HasAlreadyEnteredMarker = false
  1149.             TriggerEvent('esx_vehiclespawner:hasExitedMarker', LastZone)
  1150.         end
  1151.        
  1152.         if letSleep then
  1153.             Citizen.Wait(500)
  1154.             end
  1155.         end
  1156.     end
  1157. end)
  1158.  
  1159. Citizen.CreateThread(function()
  1160.     while true do
  1161.         Citizen.Wait(0)
  1162.  
  1163.         if CurrentAction then
  1164.             ESX.ShowHelpNotification(CurrentActionMsg)
  1165.  
  1166.             if IsControlJustReleased(0, 38) then
  1167.                 if CurrentAction == 'spawner_point' then
  1168.                     OpenSpawnerMenu()
  1169.                 elseif CurrentAction == 'deleter_point' then
  1170.                     OpenReturnMenu()
  1171.                     ESX.ShowNotification(_U('delete_vehicle'))
  1172.                 end
  1173.  
  1174.                 CurrentAction = nil
  1175.             end
  1176.         else
  1177.             Citizen.Wait(500)
  1178.         end
  1179.     end
  1180. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement