feat(modules): add npwd support

This commit is contained in:
Csoki
2023-01-22 13:02:06 +01:00
parent 91f854cd76
commit d6fe06d9f5
4 changed files with 113 additions and 11 deletions
+2 -1
View File
@@ -402,7 +402,8 @@ CREATE TABLE `users` (
`disabled` TINYINT(1) NULL DEFAULT '0',
`last_property` varchar(255) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`last_seen` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
`last_seen` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`phone_number` VARCHAR(20) DEFAULT NULL
) ENGINE=InnoDB;
-- --------------------------------------------------------
@@ -0,0 +1,55 @@
local npwd = GetResourceState('npwd'):find('start') and exports.npwd or nil
local function checkPhone()
if not npwd then
return
end
npwd:setPhoneDisabled((ESX.SearchInventory('phone').count or 0) <= 0)
end
RegisterNetEvent('esx:playerLoaded', checkPhone)
AddEventHandler('onClientResourceStart', function(resource)
if resource ~= 'npwd' then
return
end
npwd = GetResourceState('npwd'):find('start') and exports.npwd or nil
if ESX.PlayerLoaded then
checkPhone()
end
end)
AddEventHandler('onClientResourceStop', function(resource)
if resource == 'npwd' then
npwd = nil
end
end)
RegisterNetEvent('esx:onPlayerLogout', function()
if not npwd then
return
end
npwd:setPhoneVisible(false)
npwd:setPhoneDisabled(true)
end)
RegisterNetEvent('esx:removeInventoryItem', function(item, count)
if not npwd then
return
end
if item == 'phone' and count == 0 then
npwd:setPhoneDisabled(true)
end
end)
RegisterNetEvent('esx:addInventoryItem', function(item)
if not npwd or item ~= 'phone' then
return
end
npwd:setPhoneDisabled(false)
end)
+7 -10
View File
@@ -27,9 +27,9 @@ server_scripts {
'server/main.lua',
'server/commands.lua',
'common/modules/math.lua',
'common/modules/table.lua',
'common/functions.lua'
'common/modules/*.lua',
'common/functions.lua',
'server/modules/*.lua'
}
client_scripts {
@@ -37,14 +37,11 @@ client_scripts {
'client/functions.lua',
'client/wrapper.lua',
'client/main.lua',
'common/modules/*.lua',
'common/functions.lua',
'client/modules/death.lua',
'client/modules/scaleform.lua',
'client/modules/streaming.lua',
'common/modules/math.lua',
'common/modules/table.lua',
'common/functions.lua'
'client/modules/*.lua'
}
ui_page {
@@ -0,0 +1,49 @@
local npwd = GetResourceState('npwd'):find('start') and exports.npwd or nil
AddEventHandler('onServerResourceStart', function(resource)
if resource ~= 'npwd' then
return
end
npwd = GetResourceState('npwd'):find('start') and exports.npwd or nil
for _, xPlayer in pairs(ESX.Players) do
npwd:newPlayer({
source = xPlayer.source,
identifier = xPlayer.identifier,
firstname = xPlayer.get('firstName'),
lastname = xPlayer.get('lastName')
})
end
end)
AddEventHandler('onServerResourceStop', function(resource)
if resource == 'npwd' then
npwd = nil
end
end)
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
if not npwd then
return
end
if not xPlayer then
xPlayer = ESX.GetPlayerFromId(playerId)
end
npwd:newPlayer({
source = playerId,
identifier = xPlayer.identifier,
firstname = xPlayer.get('firstName'),
lastname = xPlayer.get('lastName')
})
end)
AddEventHandler('esx:playerLogout', function(playerId)
if not npwd then
return
end
npwd:unloadPlayer(playerId)
end)