See description, resolves #38, resolves #36

- Fixed console error when adding invalid number (use _source)
- Fix contacts not refreshing when added (fixed broken code)
- Play sound when message recieved
- Close phone if open when script is stopping
- Get back contacts, etc when restarted mid-game
This commit is contained in:
ElPumpo
2018-10-30 15:25:53 +01:00
parent 291f6eb753
commit bc233a1441
2 changed files with 83 additions and 59 deletions
+15 -5
View File
@@ -82,13 +82,13 @@ AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts)
end)
RegisterNetEvent('esx_phone:addContact')
AddEventHandler('esx_phone:addContact', function(name, phoneNumber)
AddEventHandler('esx_phone:addContact', function(name, phoneNumber, playerOnline)
table.insert(PhoneData.contacts, {
name = name,
number = phoneNumber,
online = (PhoneNumberSources[contacts[i].number] == nil and false or NetworkIsPlayerActive(GetPlayerFromServerId(PhoneNumberSources[contacts[i].number]))),
online = playerOnline
})
-- CALL HERE RELOADCONTACT
SendNUIMessage({
contactAdded = true,
phoneData = PhoneData
@@ -103,7 +103,7 @@ AddEventHandler('esx_phone:removeContact', function(name, phoneNumber)
break
end
end
-- CALL HERE RELOADCONTACT
SendNUIMessage({
contactRemoved = true,
phoneData = PhoneData
@@ -131,7 +131,7 @@ end)
RegisterNUICallback('add_contact', function(data, cb)
local phoneNumber = tonumber(data.phoneNumber)
local contactName = tostring(data.contactName)
if phoneNumber then
TriggerServerEvent('esx_phone:addPlayerContact', phoneNumber, contactName)
else
@@ -164,6 +164,8 @@ AddEventHandler('esx_phone:onMessage', function(phoneNumber, message, position,
ESX.ShowNotification('~b~' .. job .. ': ~s~' .. message)
end
PlaySound(-1, "Menu_Accept", "Phone_SoundSet_Default", 0, 0, 1)
SendNUIMessage({
newMessage = true,
phoneNumber = phoneNumber,
@@ -277,6 +279,14 @@ Citizen.CreateThread(function()
end
end)
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
if GUI.PhoneIsShowed then
ESX.UI.Menu.CloseAll()
end
end
end)
-- Key controls
Citizen.CreateThread(function()
while true do