创造你的世界
多人游戏
在多人游戏中暂时限制房间访问
4分
您可以使用锁定和解锁功能在您希望的时间限制或允许房间访问。 📘 请参考以下指南。 \[ zepeto multiplay(server) api https //developer zepeto me/docs/multiplay server/classes/zepeto multiplay sandbox#lock ] 锁定 锁定功能是限制房间访问的功能。 await this lock(); 解锁 解锁功能是允许房间访问的功能。 但是,如果当前连接的人数与房间允许的最大人数相同,则房间无法解锁。 await this unlock(); 示例 以下是一个使用锁定和解锁功能的示例代码。 import { sandbox, sandboxoptions, sandboxplayer } from 'zepeto multiplay'; export default class extends sandbox { oncreate(options sandboxoptions) { } async onjoin(client sandboxplayer) { try { if (this clients length > 8) { await this lock(); } } catch(e) { console error(e); } } async onleave(client sandboxplayer, consented? boolean){ try { if (this clients length <= 8) { await this unlock(); } } catch(e) { console error(e); } } } 👍 锁定和私有功能之间的区别 锁定的多人房间在 zepeto 房间列表中不可见,且无法通过邀请进入。 私有多人房间在 zepeto 房间列表中不显示,但可以接受邀请。