Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.54 KB | None | 0 0
  1. -- --------------------------------------------
  2. -- Variables
  3. -- --------------------------------------------
  4.  
  5. local fields
  6. local process
  7. local sellers
  8. local blanchi
  9. local sellingPnj
  10. local sellings
  11.  
  12. local NbrCops = 0
  13. local HappyHour = 20
  14. local Hour = 1
  15.  
  16. local hasDrugs = false
  17. local drugs = {
  18.     [14] = 0,
  19.     [231] = 0,
  20.     [28] = 0,
  21.     [259] = 0,
  22.     [258] = 0,
  23.     [232] = 0,
  24.     [8] = 0,
  25. }
  26.  
  27. local closePed = false
  28. local pedCloseTo
  29. local pedSold = {}
  30.  
  31. local IsInAppart = false
  32.  
  33. function mapBlipsDebug()
  34.     if fields ~= nil then
  35.         for k, v in pairs(fields) do
  36.             for _, point in pairs(fields[k].loc) do
  37.                 AddBlip("Champs " .. k, 1, 1, point.x, point.y, point.z, 0.7)
  38.             end
  39.         end
  40.     end
  41.  
  42.     if sellers.settings ~= nil then
  43.         for k, v in pairs(sellers.settings) do
  44.             AddBlip("Sale", 1, 1, sellers.loc[v.id].x, sellers.loc[v.id].y, sellers.loc[v.id].z, 0.7)
  45.         end
  46.     end
  47.  
  48.     if blanchi.loc ~= nil then
  49.         for k, v in pairs(blanchi.loc) do
  50.             AddBlip("Blanchiment", 1, 1, v.x, v.y, v.z, 0.7)
  51.         end
  52.     end
  53. end
  54.  
  55. -- --------------------------------------------
  56. -- Evènements pour l'utilisation du matériel
  57. -- --------------------------------------------
  58.  
  59. local Particles = {}
  60. local Props = {}
  61.  
  62. function beginProcess(type)
  63.     local playerPed = PlayerPedId()
  64.     local propCoords = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 2.0, 0.0)
  65.     TriggerServerEvent('drugs:addProcess', type, { x = propCoords['x'], y = propCoords['y'], z = propCoords['z'] })
  66. end
  67.  
  68. function addProcessObjects(_type, _coords)
  69.     -- Table
  70.     table.insert(process[_type].loc, _coords)
  71.  
  72.     -- Particules
  73.     if process[_type].settings.particle ~= '' then
  74.         RequestNamedPtfxAsset('core')
  75.         SetPtfxAssetNextCall('core')
  76.  
  77.         local effet = StartParticleFxLoopedAtCoord(process[_type].settings.particle, _coords.x, _coords.y, _coords.z + 5.0, 0.0, 0.0, 0.0, 1.0, 1, 1, 1, 0)
  78.         Particles[math.floor(_coords.x * 100)] = effet
  79.     end
  80.  
  81.     -- Prop
  82.     if Props[math.floor(_coords.x * 100)] == nil then
  83.         local object = CreateObject(GetHashKey(process[_type].settings.prop), _coords.x, _coords.y, _coords.z - 1.0, false, false, false)
  84.         PlaceObjectOnGroundProperly(object)
  85.  
  86.         Props[math.floor(_coords.x * 100)] = object
  87.     end
  88. end
  89.  
  90. RegisterNetEvent('drugs:shareAddProcess')
  91. AddEventHandler('drugs:shareAddProcess', function(type, coords)
  92.     addProcessObjects(type, coords)
  93. end)
  94.  
  95. RegisterNetEvent('drugs:shareRemoveProcess')
  96. AddEventHandler('drugs:shareRemoveProcess', function(type, coords)
  97.     -- Table
  98.     if process ~= nil then
  99.         RemoveSpec(process[type].loc, coords)
  100.     end
  101.  
  102.     -- Particules
  103.     if Particles[math.floor(coords.x * 100)] ~= nil then
  104.         StopParticleFxLooped(Particles[math.floor(coords.x * 100)], 0)
  105.     end
  106.  
  107.     -- Prop
  108.     if Props[math.floor(coords.x * 100)] ~= nil then
  109.         DeleteObject(Props[math.floor(coords.x * 100)])
  110.     end
  111. end)
  112.  
  113. AddEventHandler('apart:enteredAppart', function(_status)
  114.     IsInAppart = _status
  115. end)
  116.  
  117. AddEventHandler('drugs:materiel-joints', function()
  118.     if not IsInAppart and sellers.settings['Joints'] ~= nil then
  119.         beginProcess('Joints')
  120.         TriggerServerEvent('pinventory:looseItem', sellers.settings['Joints'].item, 1)
  121.     else
  122.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  123.     end
  124. end)
  125.  
  126. AddEventHandler('drugs:materiel-shit', function()
  127.     if not IsInAppart and sellers.settings['Shit'] ~= nil then
  128.         beginProcess('Shit')
  129.         TriggerServerEvent('pinventory:looseItem', sellers.settings['Shit'].item, 1)
  130.     else
  131.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  132.     end
  133. end)
  134.  
  135. AddEventHandler('drugs:materiel-skuff', function()
  136.     if not IsInAppart and sellers.settings['Skuff'] ~= nil then
  137.         beginProcess('Skuff')
  138.         TriggerServerEvent('pinventory:looseItem', sellers.settings['Skuff'].item, 1)
  139.     else
  140.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  141.     end
  142. end)
  143.  
  144. AddEventHandler('drugs:materiel-bho', function()
  145.     if not IsInAppart and sellers.settings['BHO'] ~= nil then
  146.         beginProcess('BHO')
  147.         TriggerServerEvent('pinventory:looseItem', sellers.settings['BHO'].item, 1)
  148.     else
  149.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  150.     end
  151. end)
  152.  
  153. AddEventHandler('drugs:materiel-cocaine', function()
  154.     if not IsInAppart and sellers.settings['Cocaine'] ~= nil then
  155.         beginProcess('Cocaine')
  156.         TriggerServerEvent('pinventory:looseItem', sellers.settings['Cocaine'].item, 1)
  157.     else
  158.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  159.     end
  160. end)
  161.  
  162. AddEventHandler('drugs:materiel-crack', function()
  163.     if not IsInAppart and sellers.settings['Crack'] ~= nil then
  164.         beginProcess('Crack')
  165.         TriggerServerEvent('pinventory:looseItem', sellers.settings['Crack'].item, 1)
  166.     else
  167.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  168.     end
  169. end)
  170.  
  171. AddEventHandler('drugs:materiel-ecsta', function()
  172.     if not IsInAppart and sellers.settings['Ecstasy'] ~= nil then
  173.         beginProcess('Ecstasy')
  174.         TriggerServerEvent('pinventory:looseItem', sellers.settings['Ecstasy'].item, 1)
  175.     else
  176.         SendNotification('Vous ne pouvez pas placer ça ici...', 'error')
  177.     end
  178. end)
  179.  
  180. -- --------------------------------------------
  181. -- Gestions des données
  182. -- --------------------------------------------
  183.  
  184. AddEventHandler('jointransition:ended', function()
  185.     TriggerServerEvent('drugs:getData')
  186. end)
  187.  
  188. RegisterNetEvent('drugs:setData')
  189. AddEventHandler('drugs:setData', function(_fields, _process, _sellers, _blanchi, _sellingPnj, _sellings)
  190.     fields = _fields
  191.     process = _process
  192.     sellers = _sellers
  193.     blanchi = _blanchi
  194.     sellingPnj = _sellingPnj
  195.     sellings = _sellings
  196.  
  197.     -- mapBlipsDebug() -- Laisser désactivé si production
  198.     TriggerEvent('drugs:initSpawnedData', process)
  199. end)
  200.  
  201. -- Charge les objets au spawn
  202. AddEventHandler('drugs:initSpawnedData', function(_process)
  203.     for drugtype, processdata in pairs(_process) do
  204.         for idx, coords in ipairs(processdata.loc) do
  205.             addProcessObjects(drugtype, processdata.loc[idx])
  206.             Citizen.Wait(250)
  207.         end
  208.     end
  209. end)
  210.  
  211. RegisterNetEvent('drugs:shareUpdateRecolte')
  212. AddEventHandler('drugs:shareUpdateRecolte', function(type, id, amount)
  213.     if fields ~= nil then
  214.         fields[type].loc[id].qty = fields[type].loc[id].qty + amount
  215.     end
  216. end)
  217.  
  218. RegisterNetEvent('drugs:returnInfo')
  219. AddEventHandler('drugs:returnInfo', function(_Policiers, _Hour)
  220.     NbrCops = _Policiers
  221.     Hour = _Hour
  222. end)
  223.  
  224. -- A COMMENTER
  225. -- RegisterCommand('debug', function(source, args)
  226. --     TriggerServerEvent("drugs:getData")
  227. -- end)
  228.  
  229. -- RegisterCommand('pol', function(source, args)
  230. --     NbrCops = tonumber(args[1])
  231. -- end)
  232.  
  233. -- --------------------------------------------
  234. -- Calculs des distances et autres infos
  235. -- --------------------------------------------
  236.  
  237. Citizen.CreateThread(function()
  238.     while true do
  239.         Wait(750)
  240.  
  241.         if fields ~= nil then
  242.             for k,v in pairs(fields) do
  243.                 v.settings.close.yes, v.settings.close.id = CloseTo(v.loc, v.settings.close.dist)
  244.             end
  245.  
  246.             for k,v in pairs(process) do
  247.                 v.settings.close.int, v.settings.close.id = CloseTo(v.loc, v.settings.close.distInt)
  248.             end
  249.  
  250.             for k,v in pairs(sellers.settings) do
  251.                 v.close.int, v.close.id = CloseTo({sellers.loc[v.id]}, v.close.distInt)
  252.             end
  253.  
  254.             blanchi.settings.close.yes,_ = CloseTo(blanchi.loc, blanchi.settings.close.dist)
  255.  
  256.             sellingPnj.settings.close.yes,_ = CloseTo(sellingPnj.loc, sellingPnj.settings.close.dist)
  257.  
  258.             sellings.settings.close.yes,_ = CloseTo({sellings.loc[sellings.settings.id]}, sellings.settings.close.dist)
  259.  
  260.             drugs = GetDrugs(drugs)
  261.             hasDrugs = HasDrugs(drugs)
  262.  
  263.             if hasDrugs and sellingPnj.settings.close.yes then
  264.                 closePed, pedCloseTo = CloseToPed()
  265.             end
  266.         end
  267.     end
  268. end)
  269.  
  270. Citizen.CreateThread(function()
  271.     while true do
  272.         TriggerServerEvent('drugs:getInfo')
  273.         Wait(480000)
  274.     end
  275. end)
  276.  
  277. -- --------------------------------------------
  278. -- Interactions avec les points
  279. -- --------------------------------------------
  280.  
  281. Citizen.CreateThread(function()
  282.     while true do
  283.         Wait(0)
  284.  
  285.         if sellingPnj ~= nil then
  286.             if hasDrugs then
  287.                 if closePed then
  288.                     if NbrCops >= sellingPnj.settings.cops or Hour >= HappyHour then
  289.                         DisplayHelpText("Appuyez sur ~INPUT_CONTEXT~ pour ~y~proposer ton tosma.")
  290.  
  291.                         if IsControlJustReleased(1, 51) then
  292.  
  293.                             if not IsInTable(pedCloseTo, pedSold) then
  294.  
  295.                                 if math.random(1, 100) == 1 then
  296.                                     SendNotification(sellings.phrase[sellings.settings.id] .. '<b><span style="color:#CC2D2D;">' .. sellings.settings.mdp .. '</span></b>' .. '.', "success", 15000)
  297.                                 end
  298.  
  299.                                 if math.random(1, 2) == 1 then
  300.                                     TriggerServerEvent("drugs:sellPnj", drugs)
  301.                                     MissionText("~y~Client :~w~ Je vais te prendre ça.", 2500)
  302.                                     PlayAnimation(sellingPnj.settings.anim)
  303.                                     Wait(2000)
  304.                                     ClearPedTasks(PlayerPedId())
  305.                                     table.insert(pedSold, pedCloseTo)
  306.                                 else
  307.                                     MissionText("~y~Client :~w~ Non merci.", 2500)
  308.                                     table.insert(pedSold, pedCloseTo)
  309.                                 end
  310.                             else
  311.                                 MissionText("~y~Client :~w~ Encore ? Casse toi.", 2500)
  312.                                 if math.random(1, 10) == 1 then
  313.                                     TaskPlayAnim(pedCloseTo, 'amb@code_human_wander_texting@male@enter', 'enter', 8.0, 1.0, -1, 50)
  314.                                     Wait(8000)
  315.                                     if not IsPedInjured(pedCloseTo) then
  316.                                         TriggerEvent('orgCallLSPD:call', {
  317.                                             type = "Quelqu'un me propose de la drogue !",
  318.                                             hide = false,
  319.                                             expire = 60,
  320.                                             noplayer = true,
  321.                                         })
  322.                                     end
  323.                                     ClearPedTasks(pedCloseTo)
  324.                                 end
  325.                             end
  326.  
  327.                         end
  328.                     else
  329.                         DisplayHelpText("~r~Aucun client ne sera intéressé pour le moment ...")
  330.                     end
  331.                 end
  332.             end
  333.         end
  334.  
  335.         if fields ~= nil then
  336.             for k,v in pairs(fields) do
  337.                 if v.settings.close.yes then
  338.                     if NbrCops >= v.settings.cops or Hour >= HappyHour then
  339.  
  340.                         if v.loc[v.settings.close.id].qty > 0 then
  341.                             DisplayHelpText('Appuyez sur ~INPUT_CONTEXT~ pour ~g~ramasser ' .. v.settings.text .. '.')
  342.  
  343.                             if IsControlJustReleased(1, 51) then
  344.                                 TriggerServerEvent('drugs:updateRecolte', k, v.settings.close.id)
  345.                                 TriggerServerEvent('pinventory:receiveItem', v.settings.item.id, v.settings.item.qty, 0, true)
  346.                                 PlayAnimation(v.settings.anim)
  347.                                 Wait(v.settings.timers.harvest/2)
  348.                                 ClearPedTasks(PlayerPedId())
  349.                                 Wait(v.settings.timers.harvest/2)
  350.                             end
  351.  
  352.                         else
  353.                             DisplayHelpText('~r~Il n\'y a plus rien ici ...')
  354.                         end
  355.  
  356.                     else
  357.                         DisplayHelpText('~r~Repasse plus tard, ça craint là ...')
  358.                     end
  359.                 end
  360.             end
  361.         end
  362.  
  363.         if process ~= nil then
  364.             for k,v in pairs(process) do
  365.                 if v.settings.close.int then
  366.  
  367.                     DisplayHelpText('Restez appuyé sur ~INPUT_CONTEXT~ pour ~b~ramasser le matériel.')
  368.  
  369.                     if NbrCops >= v.settings.cops or Hour >= HappyHour then
  370.  
  371.                         TriggerServerEvent('pinventory:craft', v.settings.item.from, v.settings.item.to)
  372.                         PlayAnimation(v.settings.anim)
  373.                         Wait(v.settings.timers.process)
  374.                         ClearPedTasks(PlayerPedId())
  375.  
  376.                     else
  377.                         MissionText('~r~Repasse plus tard, ça craint là ...')
  378.                     end
  379.  
  380.                     if IsControlPressed(1, 51) then
  381.                         TriggerServerEvent('drugs:removeProcess', k, v.loc[v.settings.close.id])
  382.                         while IsControlPressed(1, 51) do
  383.                             Wait(100)
  384.                         end
  385.                         Wait(5000)
  386.                     end
  387.                 end
  388.             end
  389.         end
  390.  
  391.         if sellers ~= nil then
  392.             for k,v in pairs(sellers.settings) do
  393.                 if v.close.int then
  394.                     DisplayHelpText('Appuyez sur ~INPUT_CONTEXT~ pour ~r~acheter ' .. v.text .. '. ~w~(' .. v.price .. ' $)')
  395.  
  396.                     if IsControlJustReleased(1, 51) then
  397.                         TriggerServerEvent('drugs:buyMateriel', k)
  398.                     end
  399.                 end
  400.             end
  401.         end
  402.  
  403.         if blanchi ~= nil then
  404.             if blanchi.settings.close.yes then
  405.                 if NbrCops >= blanchi.settings.cops then
  406.                     DisplayHelpText("Appuyez sur ~INPUT_CONTEXT~ pour ~y~blanchir votre argent.")
  407.  
  408.                     if IsControlJustReleased(1, 51) then
  409.  
  410.                         while blanchi.settings.close.yes do
  411.                             TriggerServerEvent('drugs:blanchi')
  412.                             Wait(blanchi.settings.time)
  413.                         end
  414.  
  415.                     end
  416.  
  417.                 else
  418.                     DisplayHelpText("~r~Repasse plus tard, ça craint là ...")
  419.                 end
  420.             end
  421.         end
  422.  
  423.         if sellings ~= nil then
  424.             if sellings.settings.close.yes and hasDrugs then
  425.                 if NbrCops >= sellings.settings.cops or Hour >= HappyHour then
  426.                     DisplayHelpText("Appuyez sur ~INPUT_CONTEXT~ pour ~y~pour vendre votre tosma.")
  427.  
  428.                     if IsControlJustReleased(1, 51) then
  429.                         local try = OpenTextInput("Mot de passe :", "")
  430.                         print(try)
  431.                         print(sellings.settings.mdp)
  432.                         if try == sellings.settings.mdp then
  433.  
  434.                             while sellings.settings.close.yes do
  435.                                 TriggerServerEvent('drugs:sell', drugs)
  436.                                 Wait(sellings.settings.time)
  437.                             end
  438.                         else
  439.                             SendNotification('C\'est pas le bon mot de passe.', 'error')
  440.                         end
  441.                     end
  442.                 else
  443.                     DisplayHelpText("~r~Repasse plus tard, ça craint là ...")
  444.                 end
  445.             end
  446.         end
  447.  
  448.         -- if IsControlJustReleased(1, 182) then
  449.             -- local coords = GetEntityCoords(PlayerPedId())
  450.             -- local heading = GetEntityHeading(PlayerPedId())
  451.             -- print('{ x = ' ..coords['x']..', y = '..coords['y']..', z = '..coords['z']..', h = '..heading..' }')
  452.         -- end
  453.     end
  454. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement