猫史档案馆


求助代码大佬

用户:VisualProgramerVisualProgramer查看:2 回复:4 评论:2 创建时间:2022-12-27T10:20:56


var voxselect = 'dirt'
var entityfood = 20
var entitysuit = 0
world.onPlayerJoin(async({entity})=>{
    var playerbag=world.querySelector('#背包')
    playerbag.enableInteract = true
    playerbag.interactHint = ''
    playerbag.interactRadius = 10000
    playerbag.onInteract(async ({entity}) => {
        var bagst = await entity.player.dialog({
            type: Box3DialogType.SELECT,
            title: `背包`,
            titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
            titleBackgroundColor: new Box3RGBAColor(0.062745098039215, 0.51372549019607842,0.8549019607843137, 1),
            content: `坐标:${Math.round(entity.position.x)},${Math.round(entity.position.y)},${Math.round(entity.position.z)}
                    血量:${entity.hp}
                    饥饿值:${entityfood}
                    护甲值:${entitysuit}
                    `,
            contentTextColor:  new Box3RGBAColor(0, 0, 0, 1),
            contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 0.7),
            options: ['主手','工具','喵'],
        })                
        if(!bagst||bagst==null){
            return
        }
        if(bagst.index==0){
            var mhand = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: `主手`,
                titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
                titleBackgroundColor: new Box3RGBAColor(0.062745098039215, 0.51372549019607842,0.8549019607843137, 1),
                contentTextColor:  new Box3RGBAColor(0, 0, 0, 1),
                contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 0.7),
                options: ['泥土','喵方块','石头','树胶','沙子','雪','绿树叶','树叶','枫树叶','木头','深色喵块','深色石头','冰','水','岩浆','松针叶','樱花树叶','橡木树叶','南瓜','蜘蛛网','木板1','木板2','石砖','灯具1','灯具2','窗户','玻璃','彩色花纹玻璃','原木地板1','原木地板2','地毯1','地毯2','地毯3','皇家地毯1','皇家地毯2','皇家地毯3','不锈钢块','花纹石砖','方格石砖','皇家灯具'],
            })
        if(!mhand||mhand==null){
        return
        }
        if(mhand.index==0){
        voxselect = 'dirt'        

        }
        if(mhand.index==1){
        voxselect = 'grass' 

        }
        if(mhand.index==2){
        voxselect = 'stone' 

        }
        if(mhand.index==3){
        voxselect = 'acacia' 


        }
        if(mhand.index==4){
        voxselect = 'sand'       
                


        }
        if(mhand.index==5){
        voxselect = 'snow'

        if(mhand.index==6){
        voxselect = 'green_leaf'


        }
        if(mhand.index==7){
        voxselect = 'leaf_01'

        }
        if(mhand.index==8){
        voxselect = 'leaf_02'

        }
        if(mhand.index==9){
        voxselect = 'wood'

        }
        if(mhand.index==10){
        voxselect = 'dark_grass'

        }
        if(mhand.index==11){
        voxselect = 'dark_stone'

        }
        if(mhand.index==12){
        voxselect = 'ice'

        }
        if(mhand.index==13){
        voxselect = 'water'

        }
        if(mhand.index==14){
        voxselect = 'lava01'

        }
        if(mhand.index==15){
        voxselect = 'winter_leaf'

        }
        if(mhand.index==16){
        voxselect = 'leaf_04'

        }
        if(mhand.index==17){
        voxselect = 'leaf_05'

        }
        if(mhand.index==18){
        voxselect = 'pumpkin'

        }
        if(mhand.index==19){
        voxselect = 'spiderweb'

        }
        if(mhand.index==20){
        voxselect = 'plank_01'

        }
        if(mhand.index==21){
        voxselect = 'plank_02'

        }
        if(mhand.index==22){
        voxselect = 'grey_stone_brick'

        }
        if(mhand.index==23){
        voxselect = 'lantern_01'

        }
        if(mhand.index==24){
        voxselect = 'lantern_02'

        }
        if(mhand.index==25){
        voxselect = 'window'

        }
        if(mhand.index==26){
        voxselect = 'glass'

        }
        if(mhand.index==27){
        voxselect = 'color_glass'

        }
        if(mhand.index==28){
        voxselect = 'board_01'

        }
        if(mhand.index==27){
        voxselect = 'board_02'        

        }
        if(mhand.index==28){
        voxselect = 'carpet_02'

        }
        if(mhand.index==29){
        voxselect = 'carpet_04'

        }

        if(mhand.index==30){
        voxselect = 'carpet_05'

        }
        if(mhand.index==31){
        voxselect = 'board_01'

        }
        if(mhand.index==32){
        voxselect = 'palace_eaves_01'

        }
        if(mhand.index==33){
        voxselect = 'palace_eaves_05'

        }
        if(mhand.index==34){
        voxselect = 'palace_eaves_07'

        }
        if(mhand.index==35){
        voxselect = 'stainless_steel'

        }
        if(mhand.index==36){
        voxselect = 'stone_pillar_03'

        }
        if(mhand.index==37){
        voxselect = 'stone_pillar_05'

        }
        if(mhand.index==38){
        voxselect = 'palace_lamp'

        }
        

            }
                        
        }else if(bagst.index==1){
            var tools = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: `工具`,
                titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
                titleBackgroundColor: new Box3RGBAColor(0.062745098039215, 0.51372549019607842,0.8549019607843137, 1),
                contentTextColor:  new Box3RGBAColor(0, 0, 0, 1),
                contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 0.7),
                options: ['头盔','护甲','护腿','护膝','剑','稿子','锄头','铲子','弓箭','弩'],
            })  
            if(!tools||tools==null){
                return
            }      
        }else if(bagst.index==2){
            entity.hurt(100)
        }
    })
})
const lions = world.querySelectorAll('#3');
world.onTick((tick) => {
    if (tick.tick % 60 == 0) {
        const e = world.createEntity(lions[0]);
        e.position.y = 20
        e.invisible= 0
        e.collides = 1
        e.gravity = 1
        // e.hp = 200
        // e.
        // world.say('a')
        e.enableDamage = 1
        e.position.x-=40
        e.position.z -= 40
        e.addTag('岩浆怪(中)')
        lions.push(e);
    }
})
world.onTick(() => {
    lions.forEach((e) => {
        const sdxz = Math.abs(e.velocity.x) + Math.abs(e.velocity.z);
        if (sdxz > 0.1) {
            const angle = Math.floor(Math.atan2(e.velocity.z, e.velocity.x) / (2. * Math.PI) * 256) * 2. * Math.PI / 256;
            const orientation = new Box3Quaternion(0, 0, 0, 1).rotateY(angle).rotateY(Math.PI);
            e.meshOrientation.copy(orientation);
        } else {
            const randTheta = Math.random() * Math.PI ;
            const mag = Math.random() ;
            e.velocity.x = mag * Math.sin(randTheta);
            e.velocity.z = mag * Math.cos(randTheta);
            if (e.velocity.y < 1) {
                e.velocity.y += 0.5;
            }
        }
    });
});
const lionss = world.querySelectorAll('#4');
world.onTick((tick) => {
    if (tick.tick % 70 == 0) {
        const e1 = world.createEntity(lionss[0]);
        e1.addTag('岩浆怪(中)')
        e1.position.x-=40
        e1.invisible= 0
        e1.collides = 1
        e1.gravity = 1
        e1.position.z -= 40
        e1.enableDamage = 1
        e1.position.y = 20;
        lionss.push(e1);
    }
})
world.onTick(() => {
    lionss.forEach((e1) => {
        const sdxzs = Math.abs(e1.velocity.x) + Math.abs(e1.velocity.z);
        if (sdxzs > 0.1) {
            const angles = Math.floor(Math.atan2(e1.velocity.z, e1.velocity.x) / (2. * Math.PI) * 256) * 2. * Math.PI / 256;
            const orientations = new Box3Quaternion(0, 0, 0, 1).rotateY(angles).rotateY(Math.PI);
            e1.meshOrientation.copy(orientations);
        } else {
            const randThetas = Math.random() * Math.PI ;
            const mags = Math.random() ;
            e1.velocity.x = mags * Math.sin(randThetas);
            e1.velocity.z = mags * Math.cos(randThetas);
            if (e1.velocity.y < 1) {
                e1.velocity.y += 0.5;
            }
        }
    });
});

world.onPlayerJoin(({ entity }) => {
    entity.player.enable3DCursor = true // 开启方块光标
})

world.onPress(({ raycast, button }) => {
    if (button === Box3ButtonType.ACTION1) {
        const pos = raycast.voxelIndex.add(raycast.normal) // 射线指到的方块位置加上被选中的面的法线向量
        voxels.setVoxel(pos.x, pos.y, pos.z, voxselect)
    }
    else if (button === Box3ButtonType.ACTION0) {
        const pos = raycast.voxelIndex // 射线指到的方块位置
        voxels.setVoxel(pos.x, pos.y, pos.z, '')
    }    
})
world.onDie(({ entity }) => {
    world.say(`${entity.player.name}失败了`);
    var dieoptions = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: `系统`,
                titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
                titleBackgroundColor: new Box3RGBAColor(0.062745098039215, 0.51372549019607842,0.8549019607843137, 1),
                contentTextColor:  new Box3RGBAColor(0, 0, 0, 1),
                contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 0.7),
                content:'你失败了',
                options: ['复活'],
            })  
            if(!tools||tools==null){
                return
            } 
            else if(dieoptions == 0){
                world.say(`${entity.player.name}复活了`);
                entity.hp = entity.maxHp
            } 
                
    })

 执行这串代码后报错了,报错SyntaxError:await is only vaild in async function,哪位大佬能帮忙看一下

center_image


回复

上一页1 页 / 共 1下一页
HIM_PETERHIM_PETER

你只要在对的地方加上async(具体是哪我都看出来了(自己找吧

点赞1


评论


伴雪纷飞伴雪纷飞

 

world.onDie(({ entity }) => {

改成

world.onDie(async function (entity) {

点赞0


评论


植物月光花植物月光花

world.ondie(({entity})=>{})
world.ondie(async({entity})=>{})

点赞0


评论


邪恶蛋炫帅邪恶蛋炫帅

c++吗?

点赞0


评论