跳转到内容

如何使用排行榜功能

如何使用排行榜功能

  • 解答:

地图发布后生效,排行榜数据只有在游戏结束后才计入。

创建排行榜

image26(1) 在【地图设置】-【其他设置】-【排行榜设置】中点击”+“添加排行榜。
image27(2) 点击”编辑”按钮。
image28(3) 设置排行榜信息及规则。

排行榜元件

image29(1) 在【玩法】-【功能】中有排行榜元件。
image30(2) 拖入到场景中,点击”编辑”打开详情栏。【基础】-【功能基础】-【数据来源】选择创建的排行榜。
image31(3) 在【外观】-【皮肤】中有多种皮肤可选。
image32(4) 在【功能基础】-【排行榜类型】中可选择显示全局或好友。

如何向排行榜记录玩家数据

功能说明:角色进入信号触发盒时记录玩家排行榜数据。

GameServer.lua

--@description 游戏开始时服务端的操作
function OBTest:OnServerStart()
-- 当角色进入信号触发盒
System:RegisterEvent(
Events.ON_CHARACTER_ENTER_SIGNAL_BOX,
function (playerId, signalBoxId) --playerId = 玩家id, signalBoxId = 信号触发盒id
-- 记录玩家排行榜数据(排行榜数据只有在游戏结束后才计入)
Rank:SetRankById(RankIndex,playerId, 100, nil) -- 排行榜id按创建顺序依次为:1、2、3,如果是首次创建RankIndex填入为1)
end
)
end

如何使用好友排行榜

功能说明:获取玩家超过多少名好友。超过了哪些好友。

GameEntry.lua

-- 网络协议
NetMsg = {
ShowTips = 1005,
}

GameClient.lua

--客户端展示屏幕提示
function GameClient:ShowTips(msgId, msg)
UI:ShowMessageTip(table.unpack(msg))
end

GameServer.lua

-- 屏幕提示输出,方便地图发布后调试
local function ShowTips(...)
-- 将服务端日志发送至客户端
System:SendToAllClients(
NetMsg.ShowTips,
{...}
)
end
--@description 游戏开始时服务端的操作
function GameServer:OnStart()
-- 当角色进入触发盒
System:RegisterEvent(
Events.ON_CHARACTER_ENTER_SIGNAL_BOX,
function (playerId, signalBoxId) --playerId = 玩家id, signalBoxId = 触发盒id
local playerScore = 100
local surpassedCount = 0
local data = {110,100,90,80}
local Id = {110,100,90,80}
-- 遍历排行榜中的所有好友
for i = 1, 100 do -- 假设最多检查前100名好友
local friendData = data[i]--Rank:GetTheFrinedsRankingData(playerId, rankingIndex, i)
-- 如果获取不到数据,说明没有更多好友了
if not friendData then
break
end
-- 如果玩家分数高于或等于好友分数,说明超过了这个好友
if playerScore > friendData then
surpassedCount = surpassedCount + 1
local friendId = Id[i]--Rank:GetTheFrinedsRankingPlayer(playerId, 1, 1)
local name = Chat:GetCustomName(friendId)
ShowTips("超过了", name)
end
end
ShowTips("共计超过了", surpassedCount, "名好友")
end
)
end