example
example

已解决√ 求助 插件出bug

状态
此线程已解决! 转到解决方案...

ClieeR

新用户
认证用户
client
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
-- 绑定OX_TARGET给银行和ATM
Citizen.CreateThread(function()
for _, bank in pairs(Config.Banks) do
exports.ox_target:addSphereZone(bank.name, bank.coords, 1.0, {
name = bank.name,
debug = false,
useZ = true
}, {
options = {
{
event = "bank:eek:penMenu",
icon = "fas fa-university",
label = "打开银行菜单"
}
},
distance = 2.5
})
end

for _, atmModel in ipairs(Config.ATMs) do
exports.ox_target:addTargetModel(atmModel, {
options = {
{
event = "atm:eek:penMenu",
icon = "fas fa-credit-card",
label = "打开ATM菜单"
}
},
distance = 2.5
})
end
end)
RegisterNetEvent('bank:eek:penMenu')
AddEventHandler('bank:eek:penMenu', function()
OpenBankMenu()
end)
RegisterNetEvent('atm:eek:penMenu')
AddEventHandler('atm:eek:penMenu', function()
OpenATMMenu()
end)
function OpenBankMenu()
if HasItem(Config.BankCardItem) then
-- 显示银行菜单
-- 使用ox_lib生成UI
TriggerEvent('ox_lib:menu', {
title = '银行菜单',
options = {
{title = '转账', description = '转账给他人', onSelect = function() OpenTransferMenu() end},
{title = '收款', description = '从他人处收款', onSelect = function() OpenReceiveMenu() end},
{title = '贷款', description = '申请贷款', onSelect = function() OpenLoanMenu() end},
{title = '查询贷款信息', description = '查看当前贷款信息', onSelect = function() GetLoanInfo() end},
}
})
else
exports.ox_lib:notify({type = 'error', text = '你没有银行卡'})
end
end
function OpenATMMenu()
if HasItem(Config.BankCardItem) then
-- 显示ATM菜单
-- 使用ox_lib生成UI
TriggerEvent('ox_lib:menu', {
title = 'ATM菜单',
options = {
{title = '转账', description = '转账给他人', onSelect = function() OpenTransferMenu() end},
{title = '收款', description = '从他人处收款', onSelect = function() OpenReceiveMenu() end},
}
})
else
exports.ox_lib:notify({type = 'error', text = '你没有银行卡'})
end
end
function OpenTransferMenu()
-- 打开转账菜单
end
function OpenReceiveMenu()
-- 打开收款菜单
end
function OpenLoanMenu()
-- 打开贷款菜单
end
function GetLoanInfo()
ESX.TriggerServerCallback('bank:getLoanInfo', function(data)
if data then
-- 显示贷款信息
local info = string.format("你的贷款金额: %s\n利息: %s\n期限: %s天", data.loanAmount, data.interest, data.daysLeft)
exports.ox_lib:notify({type = 'info', text = info})
else
exports.ox_lib:notify({type = 'error', text = '你没有贷款'})
end
end)
end
function HasItem(item)
-- 检查玩家是否有指定物品
local xPlayer = ESX.GetPlayerData()
for i=1, #xPlayer.inventory, 1 do
if xPlayer.inventory.name == item and xPlayer.inventory.count > 0 then
return true
end
end
return false
end

server
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
local PlayerLoans = {} -- 用于存储玩家的贷款信息
-- 处理转账请求
RegisterNetEvent('bank:transfer')
AddEventHandler('bank:transfer', function(targetId, amount)
local xPlayer = ESX.GetPlayerFromId(source)
local tPlayer = ESX.GetPlayerFromId(targetId)

if tPlayer then
if xPlayer.getAccount('bank').money >= amount then
xPlayer.removeAccountMoney('bank', amount)
tPlayer.addAccountMoney('bank', amount)
TriggerClientEvent('ox_lib:notify', source, {type = 'success', text = '转账成功'})
TriggerClientEvent('ox_lib:notify', targetId, {type = 'success', text = '你收到了一笔转账'})
else
TriggerClientEvent('ox_lib:notify', source, {type = 'error', text = '你的银行余额不足'})
end
else
TriggerClientEvent('ox_lib:notify', source, {type = 'error', text = '目标玩家不存在'})
end
end)
-- 查询玩家贷款信息
ESX.RegisterServerCallback('bank:getLoanInfo', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
if PlayerLoans[xPlayer.identifier] then
cb(PlayerLoans[xPlayer.identifier])
else
cb(nil)
end
end)
-- 处理贷款请求
RegisterNetEvent('bank:loan')
AddEventHandler('bank:loan', function(amount, months)
local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.identifier
local interestRate = Config.InterestRates[months]
local totalAmount = amount * (1 + interestRate)
local dueDate = os.time() + (months * 30 * 86400) -- 计算还款期限

PlayerLoans[identifier] = {
loanAmount = amount,
interest = interestRate * 100 .. '%',
totalAmount = totalAmount,
dueDate = dueDate,
daysLeft = months * 30
}
xPlayer.addAccountMoney('bank', amount)
TriggerClientEvent('ox_lib:notify', source, {type = 'success', text = '贷款成功'})
end)
-- 定期检查贷款到期情况并强制还款
Citizen.CreateThread(function()
while true do
Citizen.Wait(60000) -- 每分钟检查一次
local currentTime = os.time()
for identifier, loan in pairs(PlayerLoans) do
if loan.dueDate <= currentTime then
local xPlayer = ESX.GetPlayerFromIdentifier(identifier)
if xPlayer then
if xPlayer.getAccount('bank').money >= loan.totalAmount then
xPlayer.removeAccountMoney('bank', loan.totalAmount)
TriggerClientEvent('ox_lib:notify', xPlayer.source, {type = 'success', text = '贷款已自动还款'})
else
local remainingAmount = loan.totalAmount - xPlayer.getAccount('bank').money
xPlayer.setAccountMoney('bank', 0)
if xPlayer.getMoney() >= remainingAmount then
xPlayer.removeMoney(remainingAmount)
TriggerClientEvent('ox_lib:notify', xPlayer.source, {type = 'warning', text = '贷款已部分还款,余额不足部分已从现金中扣除'})
else
-- 采取其他措施,例如冻结资产
TriggerClientEvent('ox_lib:notify', xPlayer.source, {type = 'error', text = '贷款超期未还,资产已被冻结'})
end
end
end
PlayerLoans[identifier] = nil -- 清除已还款的贷款信息
end
end
end
end)

config
Config = {}
-- 银行坐标,可以在此修改
Config.Banks = {
{name = "Bank1", coords = vector3(-1212.98, -330.84, 37.78)},
{name = "Bank2", coords = vector3(149.46, -1040.34, 29.37)},
-- 添加更多银行坐标
}
-- ATM模型,可以在此修改
Config.ATMs = {
'prop_atm_01',
'prop_atm_02',
'prop_atm_03'
}
-- 银行卡物品名称
Config.BankCardItem = "bank_card"
-- 可修改的转账金额选项
Config.TransferAmounts = {1000, 2000, 3000, 4000, 5000}
-- 可修改的贷款金额选项
Config.LoanAmounts = {1000, 2000, 3000, 4000, 5000}
-- 利率配置
Config.InterestRates = {
[1] = 0.02,
[2] = 0.04,
[3] = 0.06,
[4] = 0.08,
[5] = 0.10,
[6] = 0.12,
[7] = 0.14,
[8] = 0.16,
[9] = 0.18,
[10] = 0.20,
[11] = 0.22,
[12] = 0.24
}
 

附件

  • 20240817084020_1.jpg
    20240817084020_1.jpg
    1 MB · 查看: 14
最后编辑:

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
本 月 名 人 榜 最 佳
你先把你这个代码整理一下,不然没语法高亮没缩进的这谁能看懂。。。。
 

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
本 月 名 人 榜 最 佳
1723862780469.png
这里出的问题,你去这里看看什么情况
 

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
本 月 名 人 榜 最 佳
ox target报错的文件
我只能教你怎么做,不会帮你去做。具体怎么解决得你自己探索
 

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
本 月 名 人 榜 最 佳
没有基础就学基础,lua,html,js,css
 

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
本 月 名 人 榜 最 佳
lua:
function api.addPolyZone(data)
    if data.debug then utils.warn('Creating new PolyZone with debug enabled.') end

    data.resource = GetInvokingResource()
    data.options = checkOptions(data.options)
    return lib.zones.poly(data).id
end
人家的输入的data是一个table,你输入的是一个字符串,这不报错谁报错

要看手册写啊!
:mad:
 
状态
此线程已解决! 转到解决方案...
顶部