翻译
ESX = exports["es_extended"]:getSharedObject()
local WebhookLink = 'https://discord.com/api/webhooks/1196121917275504690/Gcd1vtICRyNhUCiRnx7aPyMTMZB87dZ86JMDRvEDQ7ODQYPgXV7jS6wgL8WoeFYDv4RL' -- WEBHOOK链接
function Webhook()
return WebhookLink
end
function ESXf()
local ESXf = nil
ESXf = exports["es_extended"]:getSharedObject()
return ESXf
end
function MySQLexecute(query, values, func)
return MySQL.Async.execute(query, values, func)
end
function MySQLfetchAll(query, values, func)
return MySQL.Async.fetchAll(query, values, func)
end
function MySQLinsert(query, values, func)
return MySQL.Async.insert(query, values, func)
end
function getMoney(xPlayer, type)
local amount = 0
if type == "money" then
amount = xPlayer.getAccount(type).money
else
amount = xPlayer.getAccount(type).money
end
return amount
end
ESX.RegisterServerCallback(Config.EventPrefix..":isAdmin", function(source, cb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local playerGroup = xPlayer.getGroup()
local isAdmin = false
for k,v in ipairs(Config.AdminGroups) do
if playerGroup == v then
isAdmin = true
break
end
end
cb(isAdmin)
end)
RegisterServerEvent(Config.EventPrefix..':setVehicleOwned')
AddEventHandler(Config.EventPrefix..':setVehicleOwned', function (vehicleProps, model, id)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
MySQLexecute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
{
['@owner'] = xPlayer.identifier,
['@plate'] = vehicleProps.plate,
['@vehicle'] = json.encode(vehicleProps)
}, function (rowsChanged)
end)
end)
ESX.RegisterServerCallback(Config.EventPrefix..":HasLicense", function(source, cb, license)
local hasLicense = false
if license == "" then
hasLicense = true
elseif license == "boat" then
-- Add the checks to see if the player has the license
hasLicense = true
end
cb(hasLicense)
end)
ESX.RegisterServerCallback(Config.EventPrefix..":canOpenMenu", function(source, cb, shop_id)
local canOpenShop = true
-- Here you can make the verifications you want,
-- For example check if a no VIP person is trying to open a VIP shop, if so change canOpenShop to false
cb(canOpenShop)
end)
ESX.RegisterServerCallback(Config.EventPrefix..':retrieveJobVehicles', function(source, cb, type)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.query('SELECT * FROM owned_vehicles WHERE owner = ? AND type = ? AND job = ?', {xPlayer.identifier, type, xPlayer.job.name},
function(result)
cb(result)
end)
end)
RegisterNetEvent(Config.EventPrefix..':setJobVehicleState')
AddEventHandler(Config.EventPrefix..':setJobVehicleState', function(plate, state)
local xPlayer = ESX.GetPlayerFromId(source)
MySQL.update('UPDATE owned_vehicles SET `stored` = ? WHERE plate = ? AND job = ?', {state, plate, xPlayer.job.name},
function(rowsChanged)
if rowsChanged == 0 then
print(('[^3WARNING^7] Player ^5%s^7 Attempted To Exploit the Garage!'):format(source, plate))
end
end)
end)
以下是您提供的代码的中文翻译和注释:
ESX = exports["es_extended"]:getSharedObject() -- 获取ESX共享对象
local WebhookLink = 'https://discord.com/api/webhooks/1196121917275504690/Gcd1vtICRyNhUCiRnx7aPyMTMZB87dZ86JMDRvEDQ7ODQYPgXV7jS6wgL8WoeFYDv4RL' -- WEBHOOK链接
function Webhook()
return WebhookLink -- 返回Webhook链接
end
function ESXf()
local ESXf = nil
ESXf = exports["es_extended"]:getSharedObject() -- 获取ESX共享对象
return ESXf
end
function MySQLexecute(query, values, func)
return MySQL.Async.execute(query, values, func) -- 异步执行MySQL查询
end
function MySQLfetchAll(query, values, func)
return MySQL.Async.fetchAll(query, values, func) -- 异步获取所有MySQL查询结果
end
function MySQLinsert(query, values, func)
return MySQL.Async.insert(query, values, func) -- 异步插入MySQL数据
end
function getMoney(xPlayer, type)
local amount = 0
if type == "money" then
amount = xPlayer.getAccount(type).money -- 获取玩家的金钱
else
amount = xPlayer.getAccount(type).money -- 获取玩家的其他账户金额
end
return amount -- 返回金额
end
ESX.RegisterServerCallback(Config.EventPrefix..":isAdmin", function(source, cb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source) -- 获取玩家对象
local playerGroup = xPlayer.getGroup() -- 获取玩家组别
local isAdmin = false
for k,v in ipairs(Config.AdminGroups) do
if playerGroup == v then
isAdmin = true -- 如果玩家是管理员
break
end
end
cb(isAdmin) -- 回调返回是否是管理员
end)
RegisterServerEvent(Config.EventPrefix..':setVehicleOwned')
AddEventHandler(Config.EventPrefix..':setVehicleOwned', function (vehicleProps, model, id)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source) -- 获取玩家对象
MySQLexecute('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (@owner, @plate, @vehicle)',
{
['@owner'] = xPlayer.identifier, -- 玩家标识符
['@plate'] = vehicleProps.plate, -- 车辆牌照
['@vehicle'] = json.encode(vehicleProps) -- 车辆属性
}, function (rowsChanged)
end)
end)
ESX.RegisterServerCallback(Config.EventPrefix..":HasLicense", function(source, cb, license)
local hasLicense = false
if license == "" then
hasLicense = true -- 如果没有指定执照,默认有执照
elseif license == "boat" then
-- 添加检查玩家是否拥有船只执照的逻辑
hasLicense = true
end
cb(hasLicense) -- 回调返回是否拥有执照
end)
ESX.RegisterServerCallback(Config.EventPrefix..":canOpenMenu", function(source, cb, shop_id)
local canOpenShop = true
-- 在这里可以进行验证,
-- 例如检查非VIP玩家是否尝试打开VIP商店,如果是,则将canOpenShop设置为false
cb(canOpenShop) -- 回调返回是否可以打开商店
end)
ESX.RegisterServerCallback(Config.EventPrefix..':retrieveJobVehicles', function(source, cb, type)
local xPlayer = ESX.GetPlayerFromId(source) -- 获取玩家对象
MySQL.query('SELECT * FROM owned_vehicles WHERE owner = ? AND type = ? AND job = ?', {xPlayer.identifier, type, xPlayer.job.name},
function(result)
cb(result) -- 回调返回查询结果
end)
end)
RegisterNetEvent(Config.EventPrefix..':setJobVehicleState')
AddEventHandler(Config.EventPrefix..':setJobVehicleState', function(plate, state)
local xPlayer = ESX.GetPlayerFromId(source) -- 获取玩家对象
MySQL.update('UPDATE owned_vehicles SET `stored` = ? WHERE plate = ? AND job = ?', {state, plate, xPlayer.job.name},
function(rowsChanged)
if rowsChanged == 0 then
print((' 玩家 ^5%s^7 尝试利用车库!'):format(source, plate)) -- 打印尝试利用车库的玩家信息
end
end)
end)
这段代码主要涉及到FiveM的ESX框架,处理玩家的车辆、执照和权限等功能。代码中的注释已翻译为中文,帮助理解每个部分的功能。
页:
[1]