猫史档案馆


交互代码,记得加上SQL哦

用户:双鱼冬寒双鱼冬寒查看:0 回复:1 评论:0 创建时间:2022-11-13T18:51:43


world.onPlayerJoin(async ({ entity }) => {
    entity.enableInteract = true;
    entity.interactRadius = 32;
    entity.call = "是否交互?";
    entity.interactHint = entity.call;
    entity.onInteract(async ({ entity , targetEntity }) => {
        entity.player.directMessage(`你盯着${targetEntity.player.name}`)
        const p = await entity.player.dialog({
            type: Box3DialogType.SELECT,
            title: `与[${targetEntity.player.name}]互动`,
            content: '操作',
            options: ['私聊','交易']
        })
        if (p) {
            if(p.value == '私聊') {
                const sl = await entity.player.dialog({
                    type: Box3DialogType.INPUT,
                    title: `与[${targetEntity.player.name}]私喵天内容:',
                })
                entity.player.directMessage(`你对${targetEntity.player.name}说了[${sl}]`)
                targetEntity.player.dialog({
                    type: Box3DialogType.TEXT,
                    title: `来自`+`[`+entity.player.name+`]`+`的私聊`,
                    content: sl,
                    hasArrow: true,
                })
            } else if (p.value == '交易') {
                const j = await targetEntity.player.dialog({
                    type:Box3DialogType.SELECT,
                    title:'交易',
                    content:`${entity.player.name}向你发起了交易`,
                    options:['同意','拒绝']
                }) 
                if (j) {
                    if (j.value == '同意') {
                        const jy = await entity.player.dialog({
                            type: Box3DialogType.SELECT,
                            title: `与[${targetEntity.player.name}]交易`,
                            content: '你要交易:',
                            options: ['金币']
                        })
                        if (jy) {
                            const tjy = await targetEntity.player.dialog({
                                type: Box3DialogType.SELECT,
                                title: `与[${entity.player.name}]交易`,
                                content: '你要交易:',
                                options: ['金币']
                            }) 
                            if (tjy && jy) {
                                const amount = await entity.player.dialog({
                                    type: Box3DialogType.INPUT,
                                    title: '商店',
                                    content: `你有[${entity.coin}]个‘金币’,你要给[${targetEntity.player.name}]几个?`
                                })
                                if (amount > 0 && amount <= entity.coin) {
                                    entity.coin = entity.coin - amount * 1;
                                    const gain = amount * 1;
                                    targetEntity.coin = targetEntity.coin + gain;
                                    entity.player.transaction = amount;
                                    entity.player.dialog({
                                        type: Box3DialogType.TEXT,
                                        content:`你给:[${targetEntity.player.name}]:
                                        [${amount}]枚金币
                                        --------------------
                                        [${targetEntity.player.name}]给你:
                                        [${targetEntity.player.transaction}]枚金币
                                        --------------------
                                        你现在有[${entity.coin}]枚金币`,
                                        title: '系统',
                                        //options: ['确定','取消'],
                                    })
                                    
                                    /*if (main_player) {
                                        if (main_player.value == '确定') {
                                            entity.player.transaction_two = 1;
                                            await sleep (500);
                                            if (entity.player.transaction_two = 1 && targetEntity.player.transaction_two) {
                                                textDialog(entity, `交易成功!\n你现在有[${entity.coin}]枚金币!`, '系统');
                                                textDialogTarget(entity, `交易成功!\n你现在有[${targetEntity.coin}]枚金币!`, '系统');
                                            } else {
                                                entity.coin = entity.coin + amount * 1;
                                                targetEntity.coin = targetEntity.coin - gain;
                                                textDialog(entity, `交易结束!\n原因:因一方不同意导致`, '系统')
                                                textDialogTarget(entity, `交易结束!\n原因:因一方不同意导致`, '系统')
                                            }
                                        } else if (main_player.value == '取消') {
                                            textDialog(entity, `交易结束!\n原因:因一方不同意导致`, '系统')
                                            textDialogTarget(entity, `交易结束!\n原因:因一方不同意导致`, '系统')
                                        }
                                    }*/
                                } else if (!tjy || tjy === null) {
                                    textDialog(entity, `交易结束!\n原因:因一方退出从而导致`, '系统')
                                    textDialogTarget(entity, `交易结束!\n原因:因一方退出从而导致`, '系统')
                                }



                                const amountTarget = await targetEntity.player.dialog({
                                    type: Box3DialogType.INPUT,
                                    title: '系统',
                                    content: `你有[${targetEntity.coin}]个‘金币’,你要给[${entity.player.name}]几个?`
                                })
                                if (amountTarget > 0 && amountTarget <= targetEntity.coin) {
                                    targetEntity.coin = targetEntity.coin - amountTarget * 1;
                                    const targetGain = amountTarget * 1;
                                    entity.coin = entity.coin + targetGain;
                                    targetEntity.transaction = amountTarget;
                                    targetEntity.player.dialog({
                                        type: Box3DialogType.TEXT,
                                        content:`你给:[${entity.player.name}]:
                                        [${amountTarget}]枚金币
                                        --------------------
                                        [${entity.player.name}]给你:
                                        [${entity.player.transaction}]枚金币
                                        --------------------
                                        你现在有[${targetEntity.coin}]枚金币`,
                                        title: '系统',
                                    })
                                    
                                    

                                    /*if (inferior_player) {
                                        if (inferior_player.value == '确定') {
                                            targetEntity.player.transaction_two = 1;
                                            await sleep (500);
                                            if (entity.player.transaction_two = 1 && targetEntity.player.transaction_two) {
                                                textDialog(entity, `交易成功!\n你现在有[${entity.coin}]枚金币!`, '系统');
                                                textDialogTarget(entity, `交易成功!\n你现在有[${targetEntity.coin}]枚金币!`, '系统');
                                            } else {
                                                targetEntity.coin = targetEntity.coin + amountTarget * 1;
                                                entity.coin = entity.coin - targetGain;
                                                textDialog(entity, `交易结束!\n原因:因一方不同意导致`, '系统');
                                                textDialogTarget(entity, `交易结束!\n原因:因一方不同意导致`, '系统');
                                            }
                                        } else if (inferior_player.value == '取消') {
                                            textDialog(entity, `交易结束!\n原因:因一方不同意导致`, '系统');
                                            textDialogTarget(entity, `交易结束!\n原因:因一方不同意导致`, '系统');
                                        }
                                    }*/
                                } else if (!jy || jy === null) {
                                    textDialog(entity, `交易结束!\n原因:因一方退出导致`, '系统')
                                    textDialogTarget(entity, `交易结束!\n原因:因一方退出导致`, '系统')
                                }
                            } else {
                                entity.player.directMessage('已取消交易')
                                targetEntity.player.directMessage('已取消交易') 
                            } 
                        }
                    } else {
                        entity.player.dialog({
                            type: Box3DialogType.TEXT,
                            title:'交易',
                            content: '对方拒绝了你的请求',
                            hasArrow: true,
                        })
                    }
                } else {
                    entity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: '交易',
                        content: '对方忽略了你的请求',
                        hasArrow: true,
                    })
                }
            }
        } else {
            textDialog(entity, '你取消了互动', '系统')
        }
    })
});

 


回复

上一页1 页 / 共 1下一页
电鼠——光速族族长电鼠——光速族族长

再来个背包的就全了

点赞0


评论