Advertisement
Foxmice

Untitled

Aug 22nd, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.81 KB | None | 0 0
  1. --
  2. -- Created by IntelliJ IDEA.
  3. -- User: Sling
  4. -- Date: 17-12-2018
  5. -- Time: 00:39
  6. -- Made for CiviliansNetwork
  7. --
  8. local Proxy = module("vrp", "lib/Proxy")
  9. vRP = Proxy.getInterface("vRP")
  10.  
  11. local users               = {}
  12. local PhoneNumbers        = {}
  13.  
  14. function notifyAlertSMS (number, alert, list)
  15.     if PhoneNumbers[number] ~= nil then
  16.         for k, _ in pairs(list) do
  17.             vRP.getUserIdentity({users[tonumber(k)].userid, function(identity)
  18.                 local n = identity.phone
  19.                 if n ~= nil then
  20.                     TriggerEvent('gcPhone:_internalAddMessage', number, n, 'SMS fra #' .. alert.numero  .. ' : ' .. alert.message, 0, function (smsMess)
  21.                         TriggerClientEvent("gcPhone:receiveMessage", tonumber(k), smsMess)
  22.                     end)
  23.                     if alert.coords ~= nil then
  24.                         TriggerEvent('gcPhone:_internalAddMessage', number, n, 'GPS: ' .. alert.coords.x .. ', ' .. alert.coords.y, 0, function (smsMess)
  25.                             TriggerClientEvent("gcPhone:receiveMessage", tonumber(k), smsMess)
  26.                         end)
  27.                     end
  28.                 end
  29.             end})
  30.         end
  31.     end
  32. end
  33.  
  34. --[[
  35. AddEventHandler('onResourceStart', function(name)
  36.     if name:lower() == GetCurrentResourceName():lower() then
  37.         local nusers = vRP.getUsers({})
  38.         for k,v in pairs(nusers) do
  39.             Citizen.Wait(50)
  40.             if v ~= nil then
  41.                 local group = vRP.getUserGroupByType({k,"job"})
  42.                 addToPhoneNumbers(group,v)
  43.                 users[v] = {userid = k, job = group}
  44.             end
  45.         end
  46.     end
  47. end)
  48. ]]
  49.  
  50. AddEventHandler("vRP:playerLeave",function(user_id, source)
  51.     if users[source] ~= nil then
  52.         PhoneNumbers[users[source].job].sources[tostring(source)] = nil
  53.         users[source] = nil
  54.     end
  55. end)
  56.  
  57. AddEventHandler("vRP:playerSpawn", function(user_id, source, first_spawn)
  58.     if users[source] ~= nil then
  59.         PhoneNumbers[users[source].job].sources[tostring(source)] = nil
  60.         users[source] = nil
  61.     end
  62.     local group = vRP.getUserGroupByType({user_id,"job"})
  63.     addToPhoneNumbers(group,source)
  64.     users[source] = {userid = user_id, job = group}
  65. end)
  66.  
  67. AddEventHandler("vRP:playerJoinGroup", function(user_id, group, gtype)
  68.     if gtype == "job" then
  69.         local source = vRP.getUserSource({user_id})
  70.         if users[source] ~= nil then
  71.             PhoneNumbers[users[source].job].sources[tostring(source)] = nil
  72.             users[source] = nil
  73.         end
  74.         addToPhoneNumbers(group,source)
  75.         users[source] = {userid = user_id, job = group}
  76.     end
  77. end)
  78.  
  79. RegisterServerEvent('service:startCall')
  80. AddEventHandler('service:startCall', function (number, message, coords)
  81.     local source = source
  82.     local user_id = vRP.getUserId({source})
  83.         if number == "Politibetjent" or number == "Ambulanceredde" then
  84.         vRP.getUserIdentity({user_id, function(identity)
  85.             local discord = "https://discordapp.com/api/webhooks/612549618693308446/_4K-IbciILLATH6VGpa6ap5otJusC0IngLbJzRjBJouzK0BH72yAZ3zqZoZUBg195i40"
  86.             if number == "Ambulanceredde" then
  87.                 discord = "https://discordapp.com/api/webhooks/612549812688125962/MjQxQn5pNUD9_G6TD_qSzkWBplVcQ5mz5t5l-R51sHOR1juWAmKHO253VE6av57KOypi"
  88.             end
  89.             webhookDiscord(identity.phone.." - "..identity.firstname.." "..identity.name,message,discord)
  90.         end})
  91.     end
  92.     if number == "Mekaniker" or number == "Taxa" then
  93.         vRP.getUserIdentity({user_id, function(identity)
  94.             local discord = "https://discordapp.com/api/webhooks/612550451279298560/lDWbg_l_kO16wgSVsOX5DVeApHr8cgFV5Xq8Nn8EDUkwyvK5rqLPFTIWeMVvo9OcnUh1"
  95.             if number == "Taxa" then
  96.                 discord = "https://discordapp.com/api/webhooks/612550059833425920/nbkvCKH8-STu9cvrjXjjvJLLhSqECzcDWHnnHiZ0uTqgfz1WtASrP7EAyaSzB63KxZaS"
  97.             end
  98.             webhookDiscord(identity.phone.." - "..identity.firstname.." "..identity.name,message,discord)
  99.         end})
  100.     end
  101.     if number == "Advokat" or number == "Psykolog" then
  102.         vRP.getUserIdentity({user_id, function(identity)
  103.             local discord = "https://discordapp.com/api/webhooks/612550224006873119/tMamo7LoihN5WRE2MNvWVVtJGOWK_uP6aw6DmaYM-hGu5xEV6eIuGahnc3hYyzXh4Lnt"
  104.             if number == "Psykolog" then
  105.                 discord = "https://discordapp.com/api/webhooks/614051679796592651/HBnJI90mlQ1BeRlz5HLZqX2xsnf5lhG6kvtSA2Ybyyle-JLJHVUutFwpTd5cIShQwdo3"
  106.             end
  107.             webhookDiscord(identity.phone.." - "..identity.firstname.." "..identity.name,message,discord)
  108.         end})
  109.     end
  110.     if PhoneNumbers[number] ~= nil then
  111.         vRP.getUserIdentity({user_id, function(identity)
  112.             local phone = identity.phone
  113.             notifyAlertSMS(number, {
  114.                 message = message,
  115.                 coords = (number == "Politibetjent" or number == "Ambulanceredde" or number == "Mekaniker" or number == "Taxa" or number == "Advokat" or number == "Psykolog") == true and coords or nil,
  116.                 numero = phone,
  117.                 userid = user_id,
  118.             }, PhoneNumbers[number].sources)
  119.         end})
  120.     end
  121. end)
  122.  
  123. function addToPhoneNumbers(number, source)
  124.     if PhoneNumbers[number] == nil then
  125.         PhoneNumbers[number] = {
  126.             type          = number,
  127.             sources       = {},
  128.             alerts        = {}
  129.         }
  130.     end
  131.     PhoneNumbers[number].sources[tostring(source)] = true
  132. end
  133. function webhookDiscord(name,message,discord)
  134.     if message == nil or message == '' or message:sub(1, 1) == '/' then return FALSE end
  135.     PerformHttpRequest(discord, function(err, text, headers) end, 'POST', json.encode({username = name, content = message}), { ['Content-Type'] = 'application/json' })
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement