猫史档案馆


救助代码问题

用户:云游de军长渡云游de军长渡查看:3 回复:1 评论:3 创建时间:2022-09-10T20:19:54


world.onPlayerJoin(({ entity }) => {
    Object.assign(entity.player,{
        runSpeed: 0.5,
    })
});

const npc = world.querySelector('#摩托-1');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 4;   // 实体的互动范围
npc.onInteract(async({entity}) => {
    entity.player.directMessage('驾驶了摩托');
    Object.assign(entity.player,{
        runSpeed: 1.5
    })
    entity.player.addWearable({
        bodyPart: Box3BodyPart.HEAD,
        mesh: 'mesh/摩托.vb',            //使用代码时,此处的名称需与地图中的模型名称保持一致
        orientation: new Box3Quaternion(0,2,0,0).rotateY(-Math.PI/2),
        offset: new Box3Vector3(0,2.2,0.1),
        scale: Box3Vector3 = new Box3Vector3(0.3, 0.3, 0.3),
    })
});

world.onPress(async({ entity, button }) => {
    if (button == Box3ButtonType.ACTION1) { //右键查看自己的背包
        const result = await entity.player.dialog({
            type: Box3DialogType.SELECT,
            content: `昵称:${entity.player.name}
            关卡${entity.jq}`,
            options: ['卸下摩托车','重新开始','取消'],
        })
    if(!result || result === null){ 
        return; 
    }
        if (result.value == '卸下摩托车'){
            Object.assign(entity.player,{
                runSpeed: 0.5,
                })
                if (entity.isPlayer) {
                    const allWearables = entity.player.wearables();
                    allWearables.forEach((item) => {
                        item.remove();
                    })
                }
        }
        if (result.value == '重新开始'){
            entity.jq = 1
        }
    }
});
world.onPlayerJoin(async ({ entity }) => {//如果玩家进入地图,将玩家的剧情变量变成1
    entity.jq = 1;//剧情,用来判断剧情的变量
})
    

这个代码,我想让玩家和模型 摩托-1交互时,玩家装备上摩托-1,并且加快速度,但是我试的时候,点一次没问题,第二次就报错。

还有一个问题,我右键点了 卸下摩托车,速度变回来了,头上的摩托-1消除了。但是再去点 摩托-1的时候,报错了不说,还没办法装备摩托-1

 


回复

上一页1 页 / 共 1下一页
飞熊jSrt飞熊jSrt

报错内容发一下,不然没人帮的了你

虽然没人帮你,但兴许gpt可以((

 

注:一下内容皆为国内合法镜像网站调用openai的GPT3.5接口生成内容

出现这种情况通常是因为代码逻辑存在一些问题,需要进行检查和改进。

对于第一个问题,可能是因为玩家已经装备了摩托-1,但是在第二次交互时尝试继续添加摩托-1导致错误。可以在添加饰品之前先检查玩家是否已经装备了摩托-1,如果已经装备了,则不再重复添加。

对于第二个问题,可能是因为在卸下饰品时没有正确地删除头部饰品,导致在后续的交互中尝试装备已经被删除的饰品时出现错误。可以在卸下饰品时先检查是否存在头部饰品,并在删除之前先移除所有的头部饰品。

以下是修改后的代码,供参考:

world.onPlayerJoin(({ entity }) => {
    Object.assign(entity.player,{
        runSpeed: 0.5,
    })
});

const npc = world.querySelector('#摩托-1');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 4;   // 实体的互动范围
npc.onInteract(async({entity}) => {
    if (!entity.player.hasWearable('摩托-1')) {
        entity.player.directMessage('驾驶了摩托');
        Object.assign(entity.player,{
            runSpeed: 1.5
        })
        const headWearable = entity.player.addWearable({
            bodyPart: Box3BodyPart.HEAD,
            mesh: 'mesh/摩托.vb',
            orientation: new Box3Quaternion(0,2,0,0).rotateY(-Math.PI/2),
            offset: new Box3Vector3(0,2.2,0.1),
            scale: new Box3Vector3(0.3, 0.3, 0.3),
        })
        headWearable.name = '摩托-1';
    }
});

world.onPress(async({ entity, button }) => {
    if (button == Box3ButtonType.ACTION1) { //右键查看自己的背包
        const result = await entity.player.dialog({
            type: Box3DialogType.SELECT,
            content: `昵称:${entity.player.name}
            关卡${entity.jq}`,
            options: ['卸下摩托车','重新开始','取消'],
        })
        if(!result || result === null){ 
            return; 
        }
        if (result.value == '卸下摩托车'){
            Object.assign(entity.player,{
                runSpeed: 0.5,
                })
            if (entity.isPlayer) {
                const allWearables = entity.player.wearables();
                allWearables.forEach((item) => {
                    if (item.name === '摩托-1') {
                        item.remove();
                    }
                })
            }
        }
        if (result.value == '重新开始'){
            entity.jq = 1
        }
    }
});

world.onPlayerJoin(async ({ entity }) => {//如果玩家进入地图,将玩家的剧情变量变成1
    entity.jq = 1;//剧情,用来判断剧情的变量
})

请注意,以上代码仅供参考,实际应用中可能需要根据具体需求进行进一步修改和完善。

点赞0


评论