mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
Feat(Contacts): Add contacts
This commit is contained in:
1 parent
5ae9f99f42
commit
328ab9b0d0
5 files changed
+88
-11
No files matched your search
+4
-2
@@ -2,12 +2,14 @@ fx_version "adamant"
|
||||
game "gta5"
|
||||
|
||||
client_script {
|
||||
'resources/client/cl_main.lua'
|
||||
'resources/client/cl_main.lua',
|
||||
'resources/client/cl_contacts.lua'
|
||||
}
|
||||
|
||||
server_script {
|
||||
"@mysql-async/lib/MySQL.lua",
|
||||
'resources/server/sv_main.lua'
|
||||
'resources/server/sv_main.lua',
|
||||
'resources/server/sv_contacts.lua'
|
||||
}
|
||||
|
||||
ui_page 'resources/html/index.html'
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
ESX = nil
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('phone:sendContacts')
|
||||
AddEventHandler('phone:sendContacts', function()
|
||||
ESX.TriggerServerCallback('phone:getContacts', function(contacts)
|
||||
SendNUIMessage(
|
||||
{
|
||||
app = 'BANK',
|
||||
method = 'setContacts',
|
||||
data = contacts
|
||||
}
|
||||
)
|
||||
end)
|
||||
end)
|
||||
@@ -12,11 +12,11 @@ end)
|
||||
--end, false)
|
||||
|
||||
RegisterCommand('phone:open', function(source, args, rawCommand)
|
||||
TriggerServerEvent('phone:server:getCredentials')
|
||||
TriggerServerEvent('phone:getCredentials', source)
|
||||
end, false)
|
||||
|
||||
RegisterNetEvent('phone:client:send')
|
||||
AddEventHandler('phone:client:send', function()
|
||||
RegisterNetEvent('phone:send')
|
||||
AddEventHandler('phone:send', function()
|
||||
SendNUIMessage(
|
||||
{
|
||||
app = 'PHONE',
|
||||
@@ -25,6 +25,7 @@ AddEventHandler('phone:client:send', function()
|
||||
}
|
||||
)
|
||||
SetNuiFocus(true, true)
|
||||
TriggerEvent('phone:sendContacts')
|
||||
end)
|
||||
|
||||
RegisterCommand('phone:hide', function(source, args, rawCommand)
|
||||
@@ -38,8 +39,19 @@ RegisterCommand('phone:hide', function(source, args, rawCommand)
|
||||
SetNuiFocus(false, false)
|
||||
end, false)
|
||||
|
||||
RegisterNetEvent('phone:client:sendCredentials')
|
||||
AddEventHandler('phone:client:sendCredentials', function(number)
|
||||
RegisterNUICallback('phone:close', function()
|
||||
SendNUIMessage(
|
||||
{
|
||||
app = 'PHONE',
|
||||
method = 'setVisibility',
|
||||
data = false
|
||||
}
|
||||
)
|
||||
SetNuiFocus(false, false)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('phone:sendCredentials')
|
||||
AddEventHandler('phone:sendCredentials', function(number)
|
||||
print(number)
|
||||
SendNUIMessage(
|
||||
{
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
ESX = nil
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj)
|
||||
ESX = obj
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('phone:getContacts', function(source, cb)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local _identifier = xPlayer.getIdentifier()
|
||||
MySQL.Async.fetchAll('SELECT * FROM phone_contacts WHERE `identifier`=@identifier',
|
||||
{
|
||||
['@identifier'] = _identifier
|
||||
}, function(contacts)
|
||||
cb(contacts)
|
||||
print("Contacts:")
|
||||
for k,v in pairs(contacts) do
|
||||
print(v.number, v.display)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterCommand('add_contact', function(source, args, rawCommand)
|
||||
local _source = source
|
||||
local display = args[1]
|
||||
local number = args[2]
|
||||
TriggerEvent('phone:addContacts', source, display, number)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('phone:addContacts')
|
||||
AddEventHandler('phone:addContacts', function(source, display, number)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local _identifier = xPlayer.getIdentifier()
|
||||
MySQL.Async.execute('INSERT INTO phone_contacts (`identifier`, `number`, `display`) VALUES (@identifier, @number, @display)',
|
||||
{
|
||||
identifier = _identifier,
|
||||
number = number,
|
||||
display = display
|
||||
}, function()
|
||||
end)
|
||||
end)
|
||||
@@ -5,8 +5,8 @@ TriggerEvent('esx:getSharedObject', function(obj)
|
||||
end)
|
||||
|
||||
|
||||
RegisterServerEvent('phone:server:getCredentials')
|
||||
AddEventHandler('phone:server:getCredentials', function()
|
||||
RegisterServerEvent('phone:getCredentials')
|
||||
AddEventHandler('phone:getCredentials', function()
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local _identifier = xPlayer.getIdentifier()
|
||||
@@ -19,7 +19,7 @@ AddEventHandler('phone:server:getCredentials', function()
|
||||
print(v.phone_number)
|
||||
number = v.phone_number
|
||||
end
|
||||
TriggerClientEvent('phone:client:sendCredentials', _source, number)
|
||||
TriggerClientEvent('phone:sendCredentials', _source, number)
|
||||
end)
|
||||
TriggerClientEvent('phone:client:send', _source)
|
||||
TriggerClientEvent('phone:send', _source)
|
||||
end)
|
||||
Reference in new issue
Block a user