用户:
SCS_user_u05eNFrbAf查看:0 回复:3 评论:0 创建时间:2024-03-04T20:03:20
OK那么废话不多说()()()
上代码()()(
let participants = [];
function drawLotteryWinner() {
if (participants.length === 0) {
world.querySelectorAll('player').forEach((player) => {
player.player.dialog({
type: GameDialogType.TEXT,
title: "无人参与抽奖",
content: "当前无玩家参与抽奖。",
});
});
world.say('当前无玩家参与抽奖!')
}
else{
let winnerIndex = Math.floor(Math.random() * participants.length);
let winner = participants[winnerIndex];
world.querySelectorAll('player').forEach((player) => {
player.player.dialog({
type: GameDialogType.TEXT,
title: "中奖者",
content: "中奖者揭晓!\n他就是:" + winner,
});
});
world.say("中奖者揭晓!\n他就是:" + winner)
participants = [];
}
}
再附上一段管理员才可以开奖的代码,开奖代码我用的是onChat,如下
const adminkaijiang = ['你水烨君大屑awa']
world.onChat(async ({ entity, message }) => {
if (adminkaijiang.includes(entity.player.name)) {
if (message == '开奖') {
const kj = await entity.player.dialog({
type: GameDialogType.SELECT,
title: `开奖`,
content: `确定开奖吗?`,
options: ['是', '否'],
});
if (!kj || kj === null) {
entity.player.directMessage('取消交互');
return;
}
if (kj.value === '是') {
world.say(`管理员${entity.player.name}执行开奖了!`)
await sleep (3000)
world.say(`让我们看看这位幸运儿到底是谁呢!`)
await sleep (3000)
drawLotteryWinner();
}
}
}
})
不喜勿喷!!!反正这教程帖子是给萌新看的()()()