-- 服务器脚本文件 server.lua
-- 读取配置文件,获取授权的武器列表
local authorizedWeapons = {
"weapon_pistol",
"weapon_smg",
-- 在这里添加其他需要授权的武器
}
-- 注册ox_lib菜单项,用于管理武器授权
ox.RegisterMenu("gun_license", "武器授权", {
{
id = "grant",
title = "授权武器",
icon = "fas fa-check",
close = true,
func = function(data)
TriggerEvent('gunlicense:grant', data.player, data.weapon)
end,
},
{
id = "revoke",
title = "取消授权",
icon = "fas fa-times",
close = true,
func = function(data)
TriggerEvent('gunlicense:revoke', data.player, data.weapon)
end,
},
{
id = "check",
title = "检查授权",
icon = "fas fa-search",
close = true,
func = function(data)
TriggerEvent('gunlicense:check', data.player, data.weapon)
end,
},
{
id = "list",
title = "列出授权玩家",
icon = "fas fa-list",
close = true,
func = function(data)
TriggerEvent('gunlicense:list', data.player)
end,
},
})
-- 授权武器给玩家
RegisterServerEvent('gunlicense:grant')
AddEventHandler('gunlicense:grant', function(playerId, weapon)
-- 在数据库中记录玩家获得武器的授权
-- 示例:MySQL.Async.execute('INSERT INTO gun_licenses (player_id, weapon) VALUES (@playerId, @weapon)', {['@playerId'] = playerId, ['@weapon'] = weapon})
end)
-- 取消武器授权
RegisterServerEvent('gunlicense:revoke')
AddEventHandler('gunlicense:revoke', function(playerId, weapon)
-- 从数据库中删除玩家拥有的某项武器授权记录
-- 示例: MySQL.Async.execute('DELETE FROM gun_licenses WHERE player_id = @playerId AND weapon = @weapon', {['@playerId'] = playerId, ['@weapon'] = weapon})
end)
-- 检查玩家是否拥有武器授权
RegisterServerEvent('gunlicense:check')
AddEventHandler('gunlicense:check', function(playerId, weapon)
-- 从数据库中查询玩家是否拥有某项武器的授权记录
-- 示例: MySQL.Async.fetchAll('SELECT * FROM gun_licenses WHERE player_id = @playerId AND weapon = @weapon', {['@playerId'] = playerId, ['@weapon'] = weapon}, function(result)
-- -- 处理查询结果,发送消息给客户端
-- end)
end)
-- 列出玩家的武器授权列表
RegisterServerEvent('gunlicense:list')
AddEventHandler('gunlicense:list', function(playerId)
-- 查询数据库,获取玩家拥有的武器授权列表
-- 示例: MySQL.Async.fetchAll('SELECT weapon FROM gun_licenses WHERE player_id = @playerId', {['@playerId'] = playerId}, function(result)
-- -- 处理查询结果,发送消息给客户端
-- end)
end)
-- 以下为客户端脚本,用于打开ox_lib菜单并触发相应事件
-- 客户端脚本 client.lua
-- 打开ox_lib菜单,选择相应的武器授权操作
function OpenGunLicenseMenu()
ox.CallMenu('gun_license', {})
end
-- 向服务器发送授权武器请求
function GrantWeapon(playerId, weapon)
TriggerServerEvent('gunlicense:grant', playerId, weapon)
end
-- 向服务器发送取消武器授权请求
function RevokeWeapon(playerId, weapon)
TriggerServerEvent('gunlicense:revoke', playerId, weapon)
end
-- 向服务器发送检查武器授权请求
function CheckWeapon(playerId, weapon)
TriggerServerEvent('gunlicense:check', playerId, weapon)
end
-- 向服务器发送列出玩家授权列表请求
function ListAuthorizedWeapons(playerId)
TriggerServerEvent('gunlicense:list', playerId)
end
-- 在fxmanifest.lua中确保正确声明依赖和文件加载顺序
fx_version 'bodacious'
game 'gta5'
dependency 'es_extended' -- 确保依赖ESX Legacy框架
dependency 'ox_lib' -- 确保依赖ox_lib菜单框架
client_script 'client.lua'
server_script 'server.lua'