Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.81 KB | None | 0 0
  1. --====================================================================================
  2. -- #Author: Jonathan D @ Gannon
  3. --====================================================================================
  4.  
  5. -- Configuration
  6. local KeyToucheCloseEvent = {
  7. { code = 172, event = 'ArrowUp' },
  8. { code = 111, event = 'ArrowUp' },
  9. { code = 173, event = 'ArrowDown' },
  10. { code = 174, event = 'ArrowLeft' },
  11. { code = 175, event = 'ArrowRight' },
  12. { code = 176, event = 'Enter' },
  13. { code = 177, event = 'Backspace' },
  14. }
  15. local KeyOpenClose = 289 -- F2
  16. local KeyTakeCall = 38 -- E
  17. local menuIsOpen = false
  18. local contacts = {}
  19. local messages = {}
  20. local myPhoneNumber = ''
  21. local isDead = false
  22. local USE_RTC = false
  23. local useMouse = false
  24. local ignoreFocus = false
  25. local lastFrameIsOpen = false
  26.  
  27. local PhoneInCall = {}
  28. local currentPlaySound = false
  29. local soundId = 1485
  30.  
  31.  
  32. --====================================================================================
  33. -- Check si le joueurs poséde un téléphone
  34. -- Callback true or false
  35. --====================================================================================
  36. function hasPhone (cb)
  37. cb(true)
  38. end
  39. --====================================================================================
  40. -- Que faire si le joueurs veut ouvrir sont téléphone n'est qu'il en a pas ?
  41. --====================================================================================
  42. function ShowNoPhoneWarning ()
  43. end
  44.  
  45. --[[
  46. Ouverture du téphone lié a un item
  47. Un solution ESC basé sur la solution donnée par HalCroves
  48. https://forum.fivem.net/t/tutorial-for-gcphone-with-call-and-job-message-other/177904
  49. --]]
  50. --[[
  51. ESX = nil
  52. Citizen.CreateThread(function()
  53. while ESX == nil do
  54. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  55. Citizen.Wait(0)
  56. end
  57. end)
  58.  
  59. function hasPhone (cb)
  60. if (ESX == nil) then return cb(0) end
  61. ESX.TriggerServerCallback('gcphone:getItemAmount', function(qtty)
  62. cb(qtty > 0)
  63. end, 'phone')
  64. end
  65. function ShowNoPhoneWarning ()
  66. if (ESX == nil) then return end
  67. ESX.ShowNotification("You do not have a ~r~phone~s~")
  68. end
  69. --]]
  70.  
  71.  
  72. --====================================================================================
  73. --
  74. --====================================================================================
  75. Citizen.CreateThread(function()
  76. while true do
  77. Citizen.Wait(0)
  78. if IsControlJustPressed(1, KeyOpenClose) then
  79. hasPhone(function (hasPhone)
  80. if hasPhone == true then
  81. TooglePhone()
  82. else
  83. ShowNoPhoneWarning()
  84. end
  85. end)
  86.  
  87. end
  88. if menuIsOpen == true then
  89. for _, value in ipairs(KeyToucheCloseEvent) do
  90. if IsControlJustPressed(1, value.code) then
  91. SendNUIMessage({keyUp = value.event})
  92. end
  93. end
  94. local nuiFocus = useMouse and not ignoreFocus
  95. SetNuiFocus(nuiFocus, nuiFocus)
  96. lastFrameIsOpen = true
  97. else
  98. if lastFrameIsOpen == true then
  99. SetNuiFocus(false, false)
  100. lastFrameIsOpen = false
  101. end
  102. end
  103. end
  104. end)
  105.  
  106.  
  107.  
  108. --====================================================================================
  109. -- Active ou Deactive une application (appName => config.json)
  110. --====================================================================================
  111. RegisterNetEvent('gcPhone:setEnableApp')
  112. AddEventHandler('gcPhone:setEnableApp', function(appName, enable)
  113. SendNUIMessage({event = 'setEnableApp', appName = appName, enable = enable })
  114. end)
  115.  
  116. --====================================================================================
  117. -- Gestion des appels fixe
  118. --====================================================================================
  119. function startFixeCall (fixeNumber)
  120. local number = ''
  121. DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", "", "", "", "", 10)
  122. while (UpdateOnscreenKeyboard() == 0) do
  123. DisableAllControlActions(0);
  124. Wait(0);
  125. end
  126. if (GetOnscreenKeyboardResult()) then
  127. number = GetOnscreenKeyboardResult()
  128. end
  129. if number ~= '' then
  130. TriggerEvent('gcphone:autoCall', number, {
  131. useNumber = fixeNumber
  132. })
  133. PhonePlayCall(true)
  134. end
  135. end
  136.  
  137. function TakeAppel (infoCall)
  138. TriggerEvent('gcphone:autoAcceptCall', infoCall)
  139. end
  140.  
  141. RegisterNetEvent("gcPhone:notifyFixePhoneChange")
  142. AddEventHandler("gcPhone:notifyFixePhoneChange", function(_PhoneInCall)
  143. PhoneInCall = _PhoneInCall
  144. end)
  145.  
  146. --[[
  147. Affiche les imformations quant le joueurs est proche d'un fixe
  148. --]]
  149. function showFixePhoneHelper (coords)
  150. for number, data in pairs(FixePhone) do
  151. local dist = GetDistanceBetweenCoords(
  152. data.coords.x, data.coords.y, data.coords.z,
  153. coords.x, coords.y, coords.z, 1)
  154. if dist <= 2.0 then
  155. SetTextComponentFormat("STRING")
  156. AddTextComponentString("~g~" .. data.name .. ' ~o~' .. number .. '~n~~INPUT_PICKUP~~w~ Use')
  157. DisplayHelpTextFromStringLabel(0, 0, 0, -1)
  158. if IsControlJustPressed(1, KeyTakeCall) then
  159. startFixeCall(number)
  160. end
  161. break
  162. end
  163. end
  164. end
  165.  
  166.  
  167. Citizen.CreateThread(function ()
  168. while true do
  169. local playerPed = PlayerPedId()
  170. local coords = GetEntityCoords(playerPed)
  171. local inRangeToActivePhone = false
  172. for i, _ in pairs(PhoneInCall) do
  173. local dist = GetDistanceBetweenCoords(
  174. PhoneInCall[i].coords.x, PhoneInCall[i].coords.y, PhoneInCall[i].coords.z,
  175. coords.x, coords.y, coords.z, 1)
  176. if (dist <= 5.0) then
  177. DrawMarker(1, PhoneInCall[i].coords.x, PhoneInCall[i].coords.y, PhoneInCall[i].coords.z,
  178. 0,0,0, 0,0,0, 0.1,0.1,0.1, 0,255,0,255, 0,0,0,0,0,0,0)
  179. inRangeToActivePhone = true
  180. if (dist <= 1.5) then
  181. SetTextComponentFormat("STRING")
  182. AddTextComponentString("~INPUT_PICKUP~ to take off the hook")
  183. DisplayHelpTextFromStringLabel(0, 0, 1, -1)
  184. if IsControlJustPressed(1, KeyTakeCall) then
  185. PhonePlayCall(true)
  186. TakeAppel(PhoneInCall[i])
  187. PhoneInCall = {}
  188. StopSound(soundId)
  189. end
  190. end
  191. break
  192. end
  193. end
  194. if inRangeToActivePhone == false then
  195. showFixePhoneHelper(coords)
  196. end
  197. if inRangeToActivePhone == true and currentPlaySound == false then
  198. PlaySound(soundId, "Remote_Ring", "Phone_SoundSet_Michael", 0, 0, 1)
  199. currentPlaySound = true
  200. elseif inRangeToActivePhone == false and currentPlaySound == true then
  201. currentPlaySound = false
  202. StopSound(soundId)
  203. end
  204. Citizen.Wait(0)
  205. end
  206. end)
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221. RegisterNetEvent("gcPhone:forceOpenPhone")
  222. AddEventHandler("gcPhone:forceOpenPhone", function(_myPhoneNumber)
  223. if menuIsOpen == false then
  224. TooglePhone()
  225. end
  226. end)
  227.  
  228. --====================================================================================
  229. -- Events
  230. --====================================================================================
  231. RegisterNetEvent("gcPhone:myPhoneNumber")
  232. AddEventHandler("gcPhone:myPhoneNumber", function(_myPhoneNumber)
  233. myPhoneNumber = _myPhoneNumber
  234. SendNUIMessage({event = 'updateMyPhoneNumber', myPhoneNumber = myPhoneNumber})
  235. end)
  236.  
  237. RegisterNetEvent("gcPhone:contactList")
  238. AddEventHandler("gcPhone:contactList", function(_contacts)
  239. SendNUIMessage({event = 'updateContacts', contacts = _contacts})
  240. contacts = _contacts
  241. end)
  242.  
  243. RegisterNetEvent("gcPhone:allMessage")
  244. AddEventHandler("gcPhone:allMessage", function(allmessages)
  245. SendNUIMessage({event = 'updateMessages', messages = allmessages})
  246. messages = allmessages
  247. end)
  248.  
  249. RegisterNetEvent("gcPhone:getBourse")
  250. AddEventHandler("gcPhone:getBourse", function(bourse)
  251. SendNUIMessage({event = 'updateBourse', bourse = bourse})
  252. end)
  253.  
  254. RegisterNetEvent("gcPhone:receiveMessage")
  255. AddEventHandler("gcPhone:receiveMessage", function(message)
  256. -- SendNUIMessage({event = 'updateMessages', messages = messages})
  257. SendNUIMessage({event = 'newMessage', message = message})
  258. table.insert(messages, message)
  259. if message.owner == 0 then
  260. local text = '~o~New Message'
  261. if ShowNumberNotification == true then
  262. text = '~o~New Message from ~y~'.. message.transmitter
  263. for _,contact in pairs(contacts) do
  264. if contact.number == message.transmitter then
  265. text = '~o~New Message from ~g~'.. contact.display
  266. break
  267. end
  268. end
  269. end
  270. SetNotificationTextEntry("STRING")
  271. AddTextComponentString(text)
  272. DrawNotification(false, false)
  273. PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
  274. Citizen.Wait(300)
  275. PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
  276. Citizen.Wait(300)
  277. PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
  278. end
  279. end)
  280.  
  281. --====================================================================================
  282. -- Function client | Contacts
  283. --====================================================================================
  284. function addContact(display, num)
  285. TriggerServerEvent('gcPhone:addContact', display, num)
  286. end
  287.  
  288. function deleteContact(num)
  289. TriggerServerEvent('gcPhone:deleteContact', num)
  290. end
  291. --====================================================================================
  292. -- Function client | Messages
  293. --====================================================================================
  294. function sendMessage(num, message)
  295. TriggerServerEvent('gcPhone:sendMessage', num, message)
  296. end
  297.  
  298. function deleteMessage(msgId)
  299. TriggerServerEvent('gcPhone:deleteMessage', msgId)
  300. for k, v in ipairs(messages) do
  301. if v.id == msgId then
  302. table.remove(messages, k)
  303. SendNUIMessage({event = 'updateMessages', messages = messages})
  304. return
  305. end
  306. end
  307. end
  308.  
  309. function deleteMessageContact(num)
  310. TriggerServerEvent('gcPhone:deleteMessageNumber', num)
  311. end
  312.  
  313. function deleteAllMessage()
  314. TriggerServerEvent('gcPhone:deleteAllMessage')
  315. end
  316.  
  317. function setReadMessageNumber(num)
  318. TriggerServerEvent('gcPhone:setReadMessageNumber', num)
  319. for k, v in ipairs(messages) do
  320. if v.transmitter == num then
  321. v.isRead = 1
  322. end
  323. end
  324. end
  325.  
  326. function requestAllMessages()
  327. TriggerServerEvent('gcPhone:requestAllMessages')
  328. end
  329.  
  330. function requestAllContact()
  331. TriggerServerEvent('gcPhone:requestAllContact')
  332. end
  333.  
  334.  
  335.  
  336. --====================================================================================
  337. -- Function client | Appels
  338. --====================================================================================
  339. local aminCall = false
  340. local inCall = false
  341.  
  342. RegisterNetEvent("gcPhone:waitingCall")
  343. AddEventHandler("gcPhone:waitingCall", function(infoCall, initiator)
  344. SendNUIMessage({event = 'waitingCall', infoCall = infoCall, initiator = initiator})
  345. if initiator == true then
  346. PhonePlayCall()
  347. TriggerEvent("Trigger_Success_Notification:Client", "Incoming Call")
  348. if menuIsOpen == false then
  349. TooglePhone()
  350. end
  351. end
  352. end)
  353.  
  354. RegisterNetEvent("gcPhone:acceptCall")
  355. AddEventHandler("gcPhone:acceptCall", function(infoCall, initiator)
  356. if inCall == false and USE_RTC == false then
  357. inCall = true
  358. NetworkSetVoiceChannel(infoCall.id + 1)
  359. NetworkSetTalkerProximity(0.0)
  360. end
  361. if menuIsOpen == false then
  362. TooglePhone()
  363. end
  364. PhonePlayCall()
  365. SendNUIMessage({event = 'acceptCall', infoCall = infoCall, initiator = initiator})
  366. end)
  367.  
  368. RegisterNetEvent("gcPhone:rejectCall")
  369. AddEventHandler("gcPhone:rejectCall", function(infoCall)
  370. if inCall == true then
  371. inCall = false
  372. Citizen.InvokeNative(0xE036A705F989E049)
  373. NetworkSetTalkerProximity(2.5)
  374. end
  375. PhonePlayText()
  376. SendNUIMessage({event = 'rejectCall', infoCall = infoCall})
  377. end)
  378.  
  379.  
  380. RegisterNetEvent("gcPhone:historiqueCall")
  381. AddEventHandler("gcPhone:historiqueCall", function(historique)
  382. SendNUIMessage({event = 'historiqueCall', historique = historique})
  383. end)
  384.  
  385.  
  386. function startCall (phone_number, rtcOffer, extraData)
  387. TriggerServerEvent('gcPhone:startCall', phone_number, rtcOffer, extraData)
  388. end
  389.  
  390. function acceptCall (infoCall, rtcAnswer)
  391. TriggerServerEvent('gcPhone:acceptCall', infoCall, rtcAnswer)
  392. end
  393.  
  394. function rejectCall(infoCall)
  395. TriggerServerEvent('gcPhone:rejectCall', infoCall)
  396. end
  397.  
  398. function ignoreCall(infoCall)
  399. TriggerServerEvent('gcPhone:ignoreCall', infoCall)
  400. end
  401.  
  402. function requestHistoriqueCall()
  403. TriggerServerEvent('gcPhone:getHistoriqueCall')
  404. end
  405.  
  406. function appelsDeleteHistorique (num)
  407. TriggerServerEvent('gcPhone:appelsDeleteHistorique', num)
  408. end
  409.  
  410. function appelsDeleteAllHistorique ()
  411. TriggerServerEvent('gcPhone:appelsDeleteAllHistorique')
  412. end
  413.  
  414.  
  415. --====================================================================================
  416. -- Event NUI - Appels
  417. --====================================================================================
  418.  
  419. RegisterNUICallback('startCall', function (data, cb)
  420. startCall(data.numero, data.rtcOffer, data.extraData)
  421. cb()
  422. end)
  423.  
  424. RegisterNUICallback('acceptCall', function (data, cb)
  425. acceptCall(data.infoCall, data.rtcAnswer)
  426. cb()
  427. end)
  428. RegisterNUICallback('rejectCall', function (data, cb)
  429. rejectCall(data.infoCall)
  430. cb()
  431. end)
  432.  
  433. RegisterNUICallback('ignoreCall', function (data, cb)
  434. ignoreCall(data.infoCall)
  435. cb()
  436. end)
  437.  
  438. RegisterNUICallback('notififyUseRTC', function (use, cb)
  439. USE_RTC = use
  440. if USE_RTC == true and inCall == true then
  441. print('USE RTC ON')
  442. inCall = false
  443. Citizen.InvokeNative(0xE036A705F989E049)
  444. NetworkSetTalkerProximity(2.5)
  445. end
  446. cb()
  447. end)
  448.  
  449.  
  450. RegisterNUICallback('onCandidates', function (data, cb)
  451. TriggerServerEvent('gcPhone:candidates', data.id, data.candidates)
  452. cb()
  453. end)
  454.  
  455. RegisterNetEvent("gcPhone:candidates")
  456. AddEventHandler("gcPhone:candidates", function(candidates)
  457. SendNUIMessage({event = 'candidatesAvailable', candidates = candidates})
  458. end)
  459.  
  460.  
  461.  
  462. RegisterNetEvent('gcphone:autoCall')
  463. AddEventHandler('gcphone:autoCall', function(number, extraData)
  464. if number ~= nil then
  465. SendNUIMessage({ event = "autoStartCall", number = number, extraData = extraData})
  466. end
  467. end)
  468.  
  469. RegisterNetEvent('gcphone:autoCallNumber')
  470. AddEventHandler('gcphone:autoCallNumber', function(data)
  471. TriggerEvent('gcphone:autoCall', data.number)
  472. end)
  473.  
  474. RegisterNetEvent('gcphone:autoAcceptCall')
  475. AddEventHandler('gcphone:autoAcceptCall', function(infoCall)
  476. SendNUIMessage({ event = "autoAcceptCall", infoCall = infoCall})
  477. end)
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539. --====================================================================================
  540. -- Gestion des evenements NUI
  541. --====================================================================================
  542. RegisterNUICallback('log', function(data, cb)
  543. print(data)
  544. cb()
  545. end)
  546. RegisterNUICallback('focus', function(data, cb)
  547. cb()
  548. end)
  549. RegisterNUICallback('blur', function(data, cb)
  550. cb()
  551. end)
  552. RegisterNUICallback('reponseText', function(data, cb)
  553. local limit = data.limit or 255
  554. local text = data.text or ''
  555.  
  556. DisplayOnscreenKeyboard(1, "FMMC_MPM_NA", "", text, "", "", "", limit)
  557. while (UpdateOnscreenKeyboard() == 0) do
  558. DisableAllControlActions(0);
  559. Wait(0);
  560. end
  561. if (GetOnscreenKeyboardResult()) then
  562. text = GetOnscreenKeyboardResult()
  563. end
  564. cb(json.encode({text = text}))
  565. end)
  566. --====================================================================================
  567. -- Event - Messages
  568. --====================================================================================
  569. RegisterNUICallback('getMessages', function(data, cb)
  570. cb(json.encode(messages))
  571. end)
  572. RegisterNUICallback('sendMessage', function(data, cb)
  573. if data.message == '%pos%' then
  574. local myPos = GetEntityCoords(PlayerPedId())
  575. data.message = 'GPS: ' .. myPos.x .. ', ' .. myPos.y
  576. end
  577. TriggerServerEvent('gcPhone:sendMessage', data.phoneNumber, data.message)
  578. end)
  579. RegisterNUICallback('deleteMessage', function(data, cb)
  580. deleteMessage(data.id)
  581. cb()
  582. end)
  583. RegisterNUICallback('deleteMessageNumber', function (data, cb)
  584. deleteMessageContact(data.number)
  585. cb()
  586. end)
  587. RegisterNUICallback('deleteAllMessage', function (data, cb)
  588. deleteAllMessage()
  589. cb()
  590. end)
  591. RegisterNUICallback('setReadMessageNumber', function (data, cb)
  592. setReadMessageNumber(data.number)
  593. cb()
  594. end)
  595. --====================================================================================
  596. -- Event - Contacts
  597. --====================================================================================
  598. RegisterNUICallback('addContact', function(data, cb)
  599. TriggerServerEvent('gcPhone:addContact', data.display, data.phoneNumber)
  600. end)
  601. RegisterNUICallback('updateContact', function(data, cb)
  602. TriggerServerEvent('gcPhone:updateContact', data.id, data.display, data.phoneNumber)
  603. end)
  604. RegisterNUICallback('deleteContact', function(data, cb)
  605. TriggerServerEvent('gcPhone:deleteContact', data.id)
  606. end)
  607. RegisterNUICallback('getContacts', function(data, cb)
  608. cb(json.encode(contacts))
  609. end)
  610. RegisterNUICallback('setGPS', function(data, cb)
  611. SetNewWaypoint(tonumber(data.x), tonumber(data.y))
  612. cb()
  613. end)
  614.  
  615. -- Add security for event (leuit#0100)
  616. RegisterNUICallback('callEvent', function(data, cb)
  617. local eventName = data.eventName or ''
  618. if string.match(eventName, 'gcphone') then
  619. if data.data ~= nil then
  620. TriggerEvent(data.eventName, data.data)
  621. else
  622. TriggerEvent(data.eventName)
  623. end
  624. else
  625. print('Event not allowed')
  626. end
  627. cb()
  628. end)
  629. RegisterNUICallback('useMouse', function(um, cb)
  630. useMouse = um
  631. end)
  632. RegisterNUICallback('deleteALL', function(data, cb)
  633. TriggerServerEvent('gcPhone:deleteALL')
  634. cb()
  635. end)
  636.  
  637.  
  638.  
  639. function TooglePhone()
  640. menuIsOpen = not menuIsOpen
  641. SendNUIMessage({show = menuIsOpen})
  642. if menuIsOpen == true then
  643. PhonePlayIn()
  644. else
  645. PhonePlayOut()
  646. end
  647. end
  648. RegisterNUICallback('takePhoto', function(data, cb)
  649. menuIsOpen = false
  650. SendNUIMessage({show = false})
  651. cb()
  652. TriggerEvent('camera:open')
  653. end)
  654.  
  655. RegisterNUICallback('closePhone', function(data, cb)
  656. menuIsOpen = false
  657. SendNUIMessage({show = false})
  658. PhonePlayOut()
  659. cb()
  660. end)
  661.  
  662.  
  663.  
  664.  
  665. ----------------------------------
  666. ---------- GESTION APPEL ---------
  667. ----------------------------------
  668. RegisterNUICallback('appelsDeleteHistorique', function (data, cb)
  669. appelsDeleteHistorique(data.numero)
  670. cb()
  671. end)
  672. RegisterNUICallback('appelsDeleteAllHistorique', function (data, cb)
  673. appelsDeleteAllHistorique(data.infoCall)
  674. cb()
  675. end)
  676.  
  677.  
  678. ----------------------------------
  679. ---------- GESTION VIA WEBRTC ----
  680. ----------------------------------
  681. AddEventHandler('onClientResourceStart', function(res)
  682. DoScreenFadeIn(300)
  683. if res == "gcphone" then
  684. TriggerServerEvent('gcPhone:allUpdate')
  685. end
  686. end)
  687.  
  688.  
  689. RegisterNUICallback('setIgnoreFocus', function (data, cb)
  690. ignoreFocus = data.ignoreFocus
  691. cb()
  692. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement