注册网络事件'esx_pawnshop:registerShop',在其中:RegisterNetEvent('esx_pawnshop:registerShop', function()
exports.ox_inventory:RegisterShop('Pawnshop', {
name = 'Pawnshop',
inventory = Config.ItemsSold,
locations = {
vec3(-477.6, 278.55, 82.31),
vec3(133.31, -1776.99, 28.75),
vec3(1705.79, 3783.57, 33.73),
},
})
end)
在服务器脚本文件(server.lua)中放置此代码。
注册网络事件'esx_pawnshop:sellAll',在其中:RegisterNetEvent('esx_pawnshop:sellAll', function(item, price)
local Player = ESX.GetPlayerFromId(source)
local itemData = Player.getInventoryItem(item)
if itemData ~= nil then
Player.removeInventoryItem(item, itemData.count)
Player.addAccountMoney('bank', itemData.count * price)
TriggerClientEvent('ox_lib:notify', source, {title = '支付成功', description = '您已将 $'.. itemData.count * price .. ' 存入银行账户', type = 'success', icon = 'building-columns', position = 'center-right'})
end
end)
注册网络事件'esx_pawnshop:sellSome',在其中:RegisterNetEvent('esx_pawnshop:sellSome', function(item, price, amount)
local Player = ESX.GetPlayerFromId(source)
local itemData = Player.getInventoryItem(item)
if itemData.count >= amount then
Player.removeInventoryItem(item, itemData.count)
Player.addAccountMoney('bank', itemData.count * price)
TriggerClientEvent('ox_lib:notify', source, {title = '支付成功', description = '您已将 $'.. itemData.count * price .. ' 存入银行账户', type = 'success', icon = 'building-columns', position = 'center-right'})
else
TriggerClientEvent('ox_lib:notify', source, {title = '您没有足够的该物品', type = 'error', position = 'center-right'})
end
end)
以上代码需要放置在服务器脚本文件(server.lua)中。 |