当前位置 : 145z游戏站 | 热血传奇 | 技术教程 | 

传奇聚灵珠快速购买玩家脚本实现方法

热度:
在传奇中,如果想要实现快速购买玩家聚灵珠的功能,可以使用以下脚本实现:

首先,需要在数据库中创建一个表,用于记录每个账号的聚灵珠购买记录。表结构可以如下:
CREATE TABLE JLZBuy (
Account VARCHAR(50) NOT NULL,
Amount INT NOT NULL,
BuyTime TIMESTAMP NOT NULL,
PRIMARY KEY (Account)
);

在NPC脚本中,添加以下代码:
-- 获取玩家账号
local Account = GetAccountName()

-- 获取玩家输入的购买数量
local Amount = tonumber(GetInput("请输入购买数量:"))

-- 检查购买数量是否合法
if Amount == nil or Amount <= 0 or Amount > 99999 then
-- 提示输入错误
Notice("购买数量必须是大于0且小于100000的整数")
return
end

-- 检查是否已购买超过限制
local stmt = DBQuery("SELECT SUM(Amount) FROM JLZBuy WHERE Account = ? AND BuyTime >= ?", Account, os.time() - 3600)
if stmt ~= false then
local row = DBResultRow(stmt)
if row ~= false then
local TotalAmount = row.SUM
if TotalAmount ~= nil and TotalAmount + Amount > 999999 then
-- 提示购买超过限制
Notice("您今天已购买"..TotalAmount.."个聚灵珠,不能再购买!")
DBFree(stmt)
return
end
end
DBFree(stmt)
end

-- 扣除金币
if CostGold(Amount * 10000) then
-- 记录购买记录
DBQuery("INSERT INTO JLZBuy (Account, Amount, BuyTime) VALUES (?, ?, ?)", Account, Amount, os.time())

-- 添加聚灵珠
AddItem(10100001, Amount)

-- 提示购买成功
Notice("购买成功,共"..Amount.."个聚灵珠!")
else
-- 提示金币不足
Notice("金币不足,购买失败!")
end

在NPC脚本中,添加以下代码,以在每次登录时更新购买记录:
-- 清除超过24小时的购买记录
DBQuery("DELETE FROM JLZBuy WHERE BuyTime < ?", os.time() - 3600 * 24)
[顶部]