猫史档案馆


[蛋蛋代码II] 如何制作一个抽奖机

用户:egg鸡蛋蛋egg鸡蛋蛋查看:1 回复:7 评论:1 创建时间:2022-04-29T20:23:50


众所周知

我们在做大地图的时候

经常用抽奖来坑玩家

((((((

我们首先需要一个随机数的代码(((

Math.random * /*数*/

核理

然后是一个触发交互的npc代码cjj

const cjj = world.querySelector('.抽奖机');
cjj.enableInteract = true;
cjj.interactRadius = 4;
cjj.interactHint = '抽奖机';
cjj.interactColor = new Box3RGBColor(1, 1, 1);
cjj.onInteract(async ({ entity, targetEntity }) => {
})

((((

啊对对对

然后直接完整代码蒜了((

((

const things = [//奖励栏(((
    '空', '空', '自己写', '自', '己', '写', '啊',

]
const cjj = world.querySelector('.抽奖机');
cjj.enableInteract = true;
cjj.interactRadius = 4;
cjj.interactHint = '抽奖机';
cjj.interactColor = new Box3RGBColor(1, 1, 1);
cjj.onInteract(async/*神奇async*/({ entity }) => {
    const cjj_2 = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: '八二年抽奖机',
        content: `抽奖咩?`,
        options: ['抽奖', '蒜了']
    });
    if (cjj_2) {//防止报错²³³
        if (entity.zs == '抽奖券') {
            const cjj_2 = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: '八二年抽奖机',
                content: `真的要抽奖吗\n要一个抽奖券呢\n好贵好贵的~`,
                options: ['抽奖', '蒜了']
            });
            if (cjj_2) {
                entity.zs = ''//清空主手((
                entity.item.splice(entity.item.indexOf('抽奖券'), 1);//删掉抽奖券
                const cjhhh = await things[Math.floor(Math.random() * things.length)];//神奇抽奖代码
                if (cjhhh != "空") {
                    const cjj_2 = await entity.player.dialog({
                        type: Box3DialogType.SELECT,
                        title: '八二年抽奖机',
                        content: `你获得了${cjhhh}\n2333333333333`,
                        options: ['确定']
                    });
                    entity.item.push(cjhhh)
                }
                else {
                    const cjj_2 = await entity.player.dialog({
                        type: Box3DialogType.SELECT,
                        title: '八二年抽奖机',
                        content: `你喵个寂寞`,
                        options: ['确定']
                    });
                }
            }
        }
        else {
            entity.player.directMessage('请先把抽奖券拿在手上~')
            return;
        }
    }
})
world.onPlayerJoin(async ({ entity }) => {
    entity.zs = ''
    entity.item = ['抽奖券']
    entity.player.onPress(async ({ button }) => {//右键显示状态栏
        if (button == Box3ButtonType.ACTION1) {
            const sel = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: '八二年抽奖机',
                content: `你获得了${cjhhh}\n2333333333333`,
                options: entity.item
            });
            if(sel){
                if(sel.value == '抽奖券'){
                    entity.zs = '抽奖券'
                    entity.player.directMessage('已将主手切换为抽奖券--')
                }
            }
        }
    })
})
/*
版权所有:egg-鸡蛋蛋
使用请注明
*/

 


回复

上一页1 页 / 共 1下一页
egg鸡蛋蛋egg鸡蛋蛋

喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵

点赞0


评论


egg鸡蛋蛋egg鸡蛋蛋

不对

正解:

const things = [//奖励栏(((
    '空', '空', '自己写', '自', '己', '写', '啊',

]
const cjj = world.querySelector('.抽奖机');
cjj.enableInteract = true;
cjj.interactRadius = 4;
cjj.interactHint = '抽奖机';
cjj.interactColor = new Box3RGBColor(1, 1, 1);
cjj.onInteract(async/*神奇async*/({ entity }) => {
    const cjj_2 = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: '八二年抽奖机',
        content: `抽奖咩?`,
        options: ['抽奖', '蒜了']
    });
    if (cjj_2) {//防止报错²³³
        if (entity.zs == '抽奖券') {
            const cjj_2 = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: '八二年抽奖机',
                content: `真的要抽奖吗\n要一个抽奖券呢\n好贵好贵的~`,
                options: ['抽奖', '蒜了']
            });
            if (cjj_2) {
                entity.zs = ''//清空主手((
                entity.item.splice(entity.item.indexOf('抽奖券'), 1);//删掉抽奖券
                const cjhhh = await things[Math.floor(Math.random() * things.length)];//神奇抽奖代码
                if (cjhhh != "空") {
                    const cjj_2 = await entity.player.dialog({
                        type: Box3DialogType.SELECT,
                        title: '八二年抽奖机',
                        content: `你获得了${cjhhh}\n2333333333333`,
                        options: ['确定']
                    });
                    entity.item.push(cjhhh)
                }
                else {
                    const cjj_2 = await entity.player.dialog({
                        type: Box3DialogType.SELECT,
                        title: '八二年抽奖机',
                        content: `你喵个寂寞`,
                        options: ['确定']
                    });
                }
            }
        }
        else {
            entity.player.directMessage('请先把抽奖券拿在手上~')
            return;
        }
    }
})
world.onPlayerJoin(async ({ entity }) => {
    entity.zs = ''
    entity.item = ['抽奖券']
    entity.player.onPress(async ({ button }) => {//右键显示状态栏
        if (button == Box3ButtonType.ACTION1) {
            const sel = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: '背包',
                content: `你有这些东西`,
                options: entity.item
            });
            if(sel){
                if(sel.value == '抽奖券'){
                    entity.zs = '抽奖券'
                    entity.player.directMessage('已将主手切换为抽奖券--')
                }
            }
        }
    })
})

差点出逝了

点赞0


评论


yee089yee089

氵贴(确信)

点赞1


评论


永境鹿永境鹿

666,另外: 不喜可删,一定要认真看完imgsr喵najs.cn/t4/appstyle/expression/ext/normal/af/kl_thumb.gif"alt="emotion_可怜": 兴编招人啦 官网h--ttps://xccgw.mysxl.c--n/支持编程or文艺人才进入本室,准备再来个文艺型分室。素材提供、帮助萌新、每周一教。。。向更高级进军!!(注:1、请勿无理由退出;2、某些承诺更新的作品由于一些原因,不便发布,实在抱歉)只要够努力,就能当上副室长哦!!如果想更了解我们,打开https://shequ.codemao.cn/work/142550509吧 我们需要你这样的人才

点赞0


评论


传说之下ULB--sans传说之下ULB--sans

哈农里的抽奖跟这个好像不一样

点赞0


评论


传说之下ULB--sans传说之下ULB--sans

//沙发

点赞0


评论


屑怪盗屑怪盗

保存

点赞0


评论