Advertisement
MaxPec

Untitled

Apr 23rd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.72 KB | None | 0 0
  1. local poleemploi = {
  2.     opened = false,
  3.     title = "Pôle emploi",
  4.     currentmenu = "main2",
  5.     lastmenu = nil,
  6.     currentpos = nil,
  7.     selectedbutton = 0,
  8.     marker = { r = 0, g = 155, b = 255, a = 200, type = 1 },
  9.     menu = {
  10.         x = 0.9,
  11.         y = 0.20,
  12.         width = 0.2,
  13.         height = 0.04,
  14.         buttons = 10,
  15.         from = 1,
  16.         to = 10,
  17.         scale = 0.4,
  18.         font = 0,
  19.         ["main2"] = {
  20.             title = "CATEGORIES",
  21.             name = "main2",
  22.             buttons = {
  23.                 {name = "Sans études", description = ""},
  24.                 {name = "Avec Diplômes(SOON)", description = ""},
  25.             }
  26.         },
  27.         ["sansetude"] = {
  28.             title = "Sans etudes",
  29.             name = "sansetude",
  30.             buttons = {
  31.             }
  32.         },
  33.         ["avecetude"] = {
  34.             title = "Avec Diplomes",
  35.             name = "avecetude",
  36.             buttons = {
  37.                 {name = "Vigneron (SOON)", costs = 0, description = {}, model = "Vigneron"},
  38.                 {name = "Joaillier (SOON)", costs = 0, description = {}, model = "Joaillier"},
  39.                 {name = "Pompiste (SOON)", costs = 0, description = {}, model = "Pompiste"},
  40.             }
  41.         },
  42.     }
  43. }
  44.  
  45.  
  46. RegisterNetEvent('PoleEmploiAddButton')
  47. AddEventHandler('PoleEmploiAddButton', function(tablejob)
  48.    
  49.     local a = tablejob
  50.    
  51.     poleemploi.menu["sansetude"].buttons = {}
  52.  
  53.     local i = 1
  54.     while a[i] do
  55.        
  56.     namejobclient = a[i]['name_job']
  57.     jobidjobclient = a[i]['job_id']
  58.     posxclient = a[i]['x']
  59.     posyclient = a[i]['y']
  60.     poszclient = a[i]['z']
  61.  
  62.     table.insert(poleemploi.menu["sansetude"].buttons, {name = namejobclient, description = "", jobid = jobidjobclient, posx = posxclient, posy = posyclient, posz = poszclient})
  63.  
  64.     i = i + 1
  65.     end
  66.  
  67. end)
  68.  
  69.  
  70. RegisterNetEvent('PoleEmploiAddButton2')
  71. AddEventHandler('PoleEmploiAddButton2', function()
  72.  
  73.     poleemploi.currentmenu = "sansetude"
  74.     poleemploi.opened = true
  75.     poleemploi.selectedbutton = 0
  76.    
  77. end)
  78.  
  79.  
  80. local fakecar = {model = '', car = nil}
  81. local poleemploi_locations = {
  82. {insidejob = {-266.5083,-960.6709,30.22313}},
  83. }
  84.  
  85. local poleemploi_blips ={}
  86. local inrangeofpoleemploi = false
  87. local currentlocation = nil
  88. local boughtcloth = false
  89.  
  90. local function LocalPed()
  91. return GetPlayerPed(-1)
  92. end
  93.  
  94. function drawTxt(text,font,centre,x,y,scale,r,g,b,a)
  95.     SetTextFont(font)
  96.     SetTextProportional(0)
  97.     SetTextScale(scale, scale)
  98.     SetTextColour(r, g, b, a)
  99.     SetTextDropShadow(0, 0, 0, 0,255)
  100.     SetTextEdge(1, 0, 0, 0, 255)
  101.     SetTextDropShadow()
  102.     SetTextOutline()
  103.     SetTextCentre(centre)
  104.     SetTextEntry("STRING")
  105.     AddTextComponentString(text)
  106.     DrawText(x , y)
  107. end
  108.  
  109. function IsPlayerInRangeOfpoleemploi()
  110. return inrangeofpoleemploi
  111. end
  112.  
  113. function ShowpoleemploiBlips(bool)
  114.     if bool and #poleemploi_blips == 0 then
  115.         for station,pos in pairs(poleemploi_locations) do
  116.             local loc = pos
  117.             pos = pos.insidejob
  118.             local blip = AddBlipForCoord(pos[1],pos[2],pos[3])
  119.             -- 60 58 137
  120.             SetBlipSprite(blip,407)    
  121.             SetBlipColour(blip, 15)
  122.             BeginTextCommandSetBlipName("STRING")
  123.             AddTextComponentString('Pôle Emploi')
  124.             EndTextCommandSetBlipName(blip)
  125.             SetBlipAsShortRange(blip,true)
  126.             SetBlipAsMissionCreatorBlip(blip,true)
  127.             table.insert(poleemploi_blips, {blip = blip, pos = loc})
  128.         end
  129.         Citizen.CreateThread(function()
  130.             while #poleemploi_blips > 0 do
  131.                 Citizen.Wait(0)
  132.                 local inrange = false
  133.                 for i,b in ipairs(poleemploi_blips) do
  134.                     if poleemploi.opened == false and  GetDistanceBetweenCoords(b.pos.insidejob[1],b.pos.insidejob[2],b.pos.insidejob[3],GetEntityCoords(LocalPed()),true) > 0 then
  135.                         -- DrawMarker(1,b.pos.insidejob[1],b.pos.insidejob[2],b.pos.insidejob[3],0,0,0,0,0,0,2.001,2.0001,0.5001,0,155,255,200,0,0,0,0)
  136.                         currentlocation = b
  137.                         if GetDistanceBetweenCoords(b.pos.insidejob[1],b.pos.insidejob[2],b.pos.insidejob[3],GetEntityCoords(LocalPed()),true) < 5 then
  138.                         Show("Appuyez sur ~INPUT_CONTEXT~ pour choisir un ~b~métier.")
  139.                         -- drawTxt('Appuyez sur ~g~ENTRER~s~ pour choisir un ~b~Job',0,1,0.5,0.8,0.6,255,255,255,255)
  140.                         inrange = true
  141.                         end
  142.                     end
  143.                     if GetDistanceBetweenCoords(b.pos.insidejob[1],b.pos.insidejob[2],b.pos.insidejob[3],GetEntityCoords(LocalPed()),true) > 5 then
  144.                         poleemploi.opened = false
  145.                         inrange = false
  146.                     end
  147.                 end
  148.                 inrangeofpoleemploi = inrange
  149.             end
  150.         end)
  151.     elseif bool == false and #poleemploi_blips > 0 then
  152.         for i,b in ipairs(poleemploi_blips) do
  153.             if DoesBlipExist(b.blip) then
  154.                 SetBlipAsMissionCreatorBlip(b.blip,false)
  155.                 Citizen.InvokeNative(0x86A652570E5F25DD, Citizen.PointerValueIntInitialized(b.blip))
  156.             end
  157.         end
  158.         poleemploi_blips = {}
  159.     end
  160. end
  161.  
  162. function fi(n)
  163. return n + 0.0001
  164. end
  165.  
  166. function LocalPed()
  167. return GetPlayerPed(-1)
  168. end
  169.  
  170. function trycloth(fi, catch_f)
  171. local status, exception = pcall(fi)
  172. if not status then
  173. catch_f(exception)
  174. end
  175. end
  176. function firstToUpperCloth(str)
  177.     return (str:gsub("^%l", string.upper))
  178. end
  179. --local veh = nil
  180. function OpenCreatorPoleEmploi()       
  181.     boughtcloth = false
  182.     local ped = LocalPed()
  183.     local pos = currentlocation.pos.insidejob
  184.     local g = Citizen.InvokeNative(0xC906A7DAB05C8D2B,pos[1],pos[2],pos[3],Citizen.PointerValueFloat(),0)
  185.     poleemploi.currentmenu = "main2"
  186.     poleemploi.opened = true
  187.     poleemploi.selectedbutton = 0
  188. end
  189. local cloth_price = 0
  190. function CloseCreatorPoleEmploi()
  191.     Citizen.CreateThread(function()
  192.         local ped = LocalPed()
  193.         if not boughtcloth then
  194.             local pos = currentlocation.pos.insidejob
  195.             FreezeEntityPosition(ped,false)
  196.             SetEntityVisible(ped,true)
  197.         else
  198.             local model = GetEntityModel(cloth)
  199.  
  200.             Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(cloth))
  201.             local pos = currentlocation.pos.insidejob
  202.  
  203.             FreezeEntityPosition(ped,false)
  204.             RequestModel(model)
  205.             while not HasModelLoaded(model) do
  206.                 Citizen.Wait(0)
  207.             end
  208.             SetModelAsNoLongerNeeded(model)
  209.             SetClothHasBeenOwnedByPlayer(skin,true)
  210.             local id = NetworkGetNetworkIdFromEntity(skin)
  211.             SetNetworkIdCanMigrate(id, true)
  212.             Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(skin))
  213.             SetEntityVisible(ped,true)
  214.             FreezeEntityPosition(ped,false)
  215.             TriggerEvent('BoughtPv',skin)          
  216.         end
  217.         poleemploi.opened = false
  218.         poleemploi.menu.from = 1
  219.         poleemploi.menu.to = 10
  220.     end)
  221. end
  222.    
  223. function drawMenuButton(button,x,y,selected)
  224.     local menu = poleemploi.menu
  225.     SetTextFont(menu.font)
  226.     SetTextProportional(0)
  227.     SetTextScale(menu.scale, menu.scale)
  228.     if selected then
  229.         SetTextColour(0, 0, 0, 255)
  230.     else
  231.         SetTextColour(255, 255, 255, 255)
  232.     end
  233.     SetTextCentre(0)
  234.     SetTextEntry("STRING")
  235.     AddTextComponentString(button.name)
  236.     if selected then
  237.         DrawRect(x,y,menu.width,menu.height,255,255,255,255)
  238.     else
  239.         DrawRect(x,y,menu.width,menu.height,0,0,0,150)
  240.     end
  241.     DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028) 
  242. end
  243.  
  244. function drawMenuInfo(text)
  245.     local menu = poleemploi.menu
  246.     SetTextFont(menu.font)
  247.     SetTextProportional(0)
  248.     SetTextScale(0.45, 0.45)
  249.     SetTextColour(255, 255, 255, 255)
  250.     SetTextCentre(0)
  251.     SetTextEntry("STRING")
  252.     AddTextComponentString(text)
  253.     DrawRect(0.675, 0.95,0.65,0.050,0,0,0,150)
  254.     DrawText(0.365, 0.934) 
  255. end
  256.  
  257. function drawMenuRight(txt,x,y,selected)
  258.     local menu = poleemploi.menu
  259.     SetTextFont(menu.font)
  260.     SetTextProportional(0)
  261.     SetTextScale(menu.scale, menu.scale)
  262.     SetTextRightJustify(1)
  263.     if selected then
  264.         SetTextColour(0, 0, 0, 255)
  265.     else
  266.         SetTextColour(255, 255, 255, 255)
  267.     end
  268.     SetTextCentre(0)
  269.     SetTextEntry("STRING")
  270.     AddTextComponentString(txt)
  271.     DrawText(x + menu.width/2 - 0.03, y - menu.height/2 + 0.0028)  
  272. end
  273.  
  274. function drawMenuTitlePole(txt,x,y)
  275. local menu = poleemploi.menu
  276.     SetTextFont(2)
  277.     SetTextProportional(0)
  278.     SetTextScale(0.5, 0.5)
  279.     SetTextColour(255, 255, 255, 255)
  280.     SetTextEntry("STRING")
  281.     AddTextComponentString(txt)
  282.     DrawRect(x,y,menu.width,menu.height,0,0,0,150)
  283.     DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028) 
  284. end
  285. function tablelength(T)
  286.   local count = 0
  287.   for _ in pairs(T) do count = count + 1 end
  288.   return count
  289. end
  290. function NotifyPoleEmploi(text)
  291. SetNotificationTextEntry('STRING')
  292. AddTextComponentString(text)
  293. DrawNotification(false, false)
  294. end
  295.  
  296. function DoesPlayerHaveJob(model,button,y,selected)
  297.         local t = false
  298.         --TODO:check if player own car
  299.         if t then
  300.             drawMenuRight("OWNED",poleemploi.menu.x,y,selected)
  301.         else
  302.             drawMenuRight(button.costs.."$",poleemploi.menu.x,y,selected)
  303.         end
  304. end
  305.  
  306. local backlock = false
  307. Citizen.CreateThread(function()
  308.     while true do
  309.         Citizen.Wait(0)
  310.         if IsControlJustPressed(1,38) and IsPlayerInRangeOfpoleemploi() then
  311.             if poleemploi.opened then
  312.                 CloseCreatorPoleEmploi()
  313.             else
  314.                 OpenCreatorPoleEmploi()
  315.                 clearPed()
  316.             end
  317.         end
  318.         if poleemploi.opened then
  319.             local ped = LocalPed()
  320.             local menu = poleemploi.menu[poleemploi.currentmenu]
  321.             drawTxt(poleemploi.title,1,1,poleemploi.menu.x,poleemploi.menu.y,1.0, 255,255,255,255)
  322.             drawMenuTitlePole(menu.title, poleemploi.menu.x,poleemploi.menu.y + 0.08)
  323.             drawTxt(poleemploi.selectedbutton.."/"..tablelength(menu.buttons),0,0,poleemploi.menu.x + poleemploi.menu.width/2 - 0.0385,poleemploi.menu.y + 0.067,0.4, 255,255,255,255)
  324.             local y = poleemploi.menu.y + 0.12
  325.             buttoncount = tablelength(menu.buttons)
  326.             local selected = false
  327.            
  328.             for i,button in pairs(menu.buttons) do
  329.                 if i >= poleemploi.menu.from and i <= poleemploi.menu.to then
  330.                    
  331.                     if i == poleemploi.selectedbutton then
  332.                         selected = true
  333.                     else
  334.                         selected = false
  335.                     end
  336.                     drawMenuButton(button,poleemploi.menu.x,y,selected)
  337.                     y = y + 0.04
  338.                     if selected and IsControlJustPressed(1,201) then
  339.                         ButtonSelectedPoleEmploi(button)
  340.                     end
  341.                 end
  342.             end
  343.         end
  344.         if poleemploi.opened then
  345.             if IsControlJustPressed(1,202) then
  346.                 BackJob()
  347.             end
  348.             if IsControlJustReleased(1,202) then
  349.                 backlock = false
  350.             end
  351.             if IsControlJustPressed(1,188) then
  352.                 if poleemploi.selectedbutton > 1 then
  353.                     poleemploi.selectedbutton = poleemploi.selectedbutton -1
  354.                     if buttoncount > 10 and poleemploi.selectedbutton < poleemploi.menu.from then
  355.                         poleemploi.menu.from = poleemploi.menu.from -1
  356.                         poleemploi.menu.to = poleemploi.menu.to - 1
  357.                     end
  358.                 end
  359.             end
  360.             if IsControlJustPressed(1,187)then
  361.                 if poleemploi.selectedbutton < buttoncount then
  362.                     poleemploi.selectedbutton = poleemploi.selectedbutton +1
  363.                     if buttoncount > 10 and poleemploi.selectedbutton > poleemploi.menu.to then
  364.                         poleemploi.menu.to = poleemploi.menu.to + 1
  365.                         poleemploi.menu.from = poleemploi.menu.from + 1
  366.                     end
  367.                 end
  368.             end
  369.         end
  370.        
  371.     end
  372. end)
  373.  
  374.  
  375. function roundPoleEmploi(num1, idp2)
  376.   if idp2 and idp2>0 then
  377.     local mult = 10^idp2
  378.     return math.floor(num1 * mult + 0.5) / mult
  379.   end
  380.   return math.floor(num1 + 0.5)
  381. end
  382. function ButtonSelectedPoleEmploi(button)
  383.     local ped = GetPlayerPed(-1)
  384.     local this = poleemploi.currentmenu
  385.     local btn = button.name
  386.     if this == "main2" then
  387.         if btn == "Sans études" then
  388.             TriggerServerEvent('PoleEmploi')
  389.         elseif btn == "Avec Diplômes" then
  390.             OpenMenuJob('avecetude')
  391.         end
  392.     elseif this == "sansetude" or this == "avecetude" then
  393.         TriggerServerEvent('CheckJobForPlayer',button.name,button.jobid,button.posx,button.posy,button.posz)
  394.         poleemploi.opened = false
  395.         poleemploi.menu.from = 1
  396.         poleemploi.menu.to = 10
  397.     end
  398. end
  399.  
  400. local polegoto = 0
  401.  
  402. RegisterNetEvent('GiveCoord')
  403. AddEventHandler('GiveCoord', function(posx, posy, posz)
  404.     polegoto = 1
  405.     coordpolex = tonumber(posx)
  406.     coordpoley = tonumber(posy)
  407.     coordpolez = tonumber(posz)
  408.     ShowNotificationMenuCivil2("~h~Coordonnées de votre nouvelle ~b~Entreprise~w~ envoyées sur votre GPS.")
  409. end)
  410.  
  411.  
  412. Citizen.CreateThread(function()
  413.     while true do
  414.     Wait(0)
  415.         if (polegoto == 1) then
  416.                 blipentreprise = AddBlipForCoord(coordpolex, coordpoley, coordpolez)
  417.                 N_0x80ead8e2e1d5d52e(blipentreprise)           
  418.                 SetBlipRoute(blipentreprise, 1)
  419.                 polegoto = 2
  420.         end
  421.         if polegoto == 2 then
  422.                 if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), coordpolex, coordpoley, coordpolez, true) > 4.0001 then
  423.                     DrawMarker(1, coordpolex, coordpoley, coordpolez-1.0001, 0, 0, 0, 0, 0, 0, 4.0, 4.0, 2.0, 11, 80, 169, 255, 0, 0, 1, 0, 0, 0, 0)
  424.                 else
  425.                     if blipentreprise ~= nil and DoesBlipExist(blipentreprise) then
  426.                         Citizen.InvokeNative(0x86A652570E5F25DD,Citizen.PointerValueIntInitialized(blipentreprise))
  427.                         blipentreprise = nil
  428.                         polegoto = 0
  429.                     end
  430.                 end
  431.         end
  432.     end
  433. end)
  434.  
  435. RegisterNetEvent('FinishCheckJobForPlayer')
  436. AddEventHandler('FinishCheckJobForPlayer', function(button)
  437.     boughtcloth = true
  438.     CloseCreatorPoleEmploi()
  439.     poleemploi.opened = false
  440.     poleemploi.menu.from = 1
  441.     poleemploi.menu.to = 10
  442.    
  443. end)
  444.  
  445. function OpenMenuJob(menu)
  446.     poleemploi.lastmenu = poleemploi.currentmenu
  447.     if menu == "sansetude" then
  448.         poleemploi.lastmenu = "main2"
  449.     elseif menu == "avecetude"  then
  450.         poleemploi.lastmenu = "main2"
  451.     elseif menu == 'race_create_objects' then
  452.         poleemploi.lastmenu = "main2"
  453.     elseif menu == "race_create_objects_spawn" then
  454.         poleemploi.lastmenu = "race_create_objects"
  455.     end
  456.     poleemploi.menu.from = 1
  457.     poleemploi.menu.to = 10
  458.     poleemploi.selectedbutton = 0
  459.     poleemploi.currentmenu = menu  
  460. end
  461.  
  462.  
  463. function BackJob()
  464.     if backlock then
  465.         return
  466.     end
  467.     backlock = true
  468.     if poleemploi.currentmenu == "main2" then
  469.         CloseCreatorPoleEmploi()
  470.         poleemploi.opened = false
  471.         poleemploi.menu.from = 1
  472.         poleemploi.menu.to = 10
  473.     elseif poleemploi.currentmenu == "sansetude" or poleemploi.currentmenu == "avecetude" then
  474.         OpenMenuJob('main2')
  475.     else
  476.         OpenMenuJob(poleemploi.lastmenu)
  477.     end
  478.    
  479. end
  480.  
  481. function stringstartsJob(String1,Start2)
  482.    return string.sub(String1,1,string.len(Start2))==Start2
  483. end
  484.  
  485. local firstspawn = 0
  486. AddEventHandler('playerSpawned', function(spawn)
  487. if firstspawn == 0 then
  488.     ShowpoleemploiBlips(true)
  489.     firstspawn = 1
  490. end
  491. end)
  492.  
  493.  
  494. onJob = 0
  495.  
  496. jobs = {peds = {}, flag = {}, blip = {}, cars = {}, coords = {cx={}, cy={}, cz={}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement