本帖最后由 kissinger 于 2023-3-24 00:53 编辑
我帮你修改好了,但是我没有上机测试,不能保证没有问题
print (">> loading 兑换商人.lua, 修改by牛皮德来")
local baseminus = 180 --在线时长180分钟兑换1个积分
local basesec = baseminus * 60 --在线时间换成秒
local coinEntry = 91000 --兑换币item_template entry
local JiFenNPC = 65000
local npc_vendor = 65100
local PlayerJF = {}
CharDBQuery([[
create table IF NOT EXISTS `characters_jifen` (
`guid` int(10) NOT NULL,
`used_time` int(10) NOT NULL DEFAULT '0',
`jifen` int(10) NOT NULL DEFAULT '0',
PRIMARY KEY (`guid`)
)
COMMENT='version 4.0'
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;
]])
local function VendorOnGossipHello(event, player, object)
local pGUID = player:GetGUIDLow()
PlayerJF[pGUID] = PlayerJF[pGUID] or {}
PlayerJF[pGUID][AllTM] = player:GetTotalPlayedTime() --获取总的时间
local days,hours = math.modf(PlayerJF[pGUID][AllTM]/86400)
local hours,mins = math.modf(hours*24)
local mins = math.modf(mins*60)
PlayerJF[pGUID][TotalTM] = days.."天"..hours.."时"..mins.."分"
PlayerJF[pGUID][NowJF] = PlayerJF[pGUID][NowJF] or 0
PlayerJF[pGUID][CanTryTM] = PlayerJF[pGUID][AllTM]
local curRecordTime = CharDBQuery("SELECT * FROM characters_jifen WHERE guid="..player:GetGUIDLow()..";")
if curRecordTime then
PlayerJF[pGUID][CanTryTM] = PlayerJF[pGUID][AllTM] - JFQuery:GetUInt32(1)
PlayerJF[pGUID][NowJF] = curRecordTime:GetUInt32(2)
else
CharDBExecute("insert into characters_jifen (guid,used_time,jifen) VALUES ("..player:GetGUIDLow()..",0,0);")
end
PlayerJF[pGUID][CanGetJF] = math.modf(PlayerJF[pGUID][CanTryTM] / basesec)
player:GossipClearMenu()
player:GossipMenuAddItem(1, "我的在线时长:"..PlayerJF[pGUID][TotalTM] ,1, 10)
player:GossipMenuAddItem(1, "积分账户余额"..PlayerJF[pGUID][NowJF] ,1, 100)
player:GossipMenuAddItem(1, "自动兑换积分:可兑换积分-"..PlayerJF[pGUID][CanGetJF], 1, 200)
player:GossipMenuAddItem(1, "兑换币账户", 1, 300)
player:GossipMenuAddItem(1, "兑换币商场", 1, 400)
player:GossipSendMenu(1, object)
end
local function VendorOnGossipSelect(event, player, object, sender, intid, code, menu_id)
local pGUID = player:GetGUIDLow()
if(intid == 200) then
if (PlayerJF[pGUID][CanGetJF] > 0) then
player:SendBroadcastMessage("成功兑换"..PlayerJF[pGUID][CanGetJF].."个积分")
PlayerJF[pGUID][NowJF] = PlayerJF[pGUID][NowJF] + PlayerJF[pGUID][CanGetJF]
local CheckTM = PlayerJF[pGUID][AllTM] - (PlayerJF[pGUID][AllTM] % basesec) --可兑换积分精确时间戳,用总时间去掉不能兑换的余数时间
PlayerJF[pGUID][CanGetJF] = 0 --必须要,防止菜单不关闭情况下,快速点数据库反应不过来多加分数
PlayerJF[pGUID][CanTryTM] = 0 --可写可不写,如果不关闭菜单直接操作其他菜单情况下,建议写入
CharDBExecute(string.format("update characters_jifen set used_time = '%s',jifen='%s' where guid = '%s';",CheckTM,PlayerJF[pGUID][NowJF],player:GetGUIDLow()))
else
player:SendBroadcastMessage("没有足够的在线时间可兑换")
end
player:GossipSendMenu(1, object)
elseif (intid == 300) then --这里改为积分换游戏币部分,其实游戏币可以在多个地方使用,所以这里最好不做什么,其他LUA用上述数据库直接进行积分兑换物品
if PlayerJF[pGUID][NowJF] > 0 then
player:AddItem(coinEntry,PlayerJF[pGUID][NowJF])
PlayerJF[pGUID][NowJF] = 0
CharDBExecute(string.format("update characters_jifen set jifen='0' where guid = '%s';" ,player:GetGUIDLow()))
player:SendBroadcastMessage("积分已兑换为购物币")
else
player:SendBroadcastMessage("积分已经全兑换为购物币了,你可以打开兑换币市场看看")
end
player:GossipSendMenu(1, object)
elseif(intid == 400)then
player:SendBroadcastMessage("打开兑换币商场")
player:SendListInventory(object,npc_vendor) --打开npc_vendor中对应的售卖列表
player:GossipComplete()
else --其他菜单只刷新不干活
player:GossipSendMenu(1, object)
end
end
RegisterCreatureGossipEvent(JiFenNPC, 1, VendorOnGossipHello)
RegisterCreatureGossipEvent(JiFenNPC, 2, VendorOnGossipSelect) 复制代码