猫史档案馆


[Box3]pro版私聊代码

用户:AokenAoken查看:7 回复:9 评论:7 创建时间:2023-08-24T19:30:07


console.clear()
function Input_dialog(entity,title,text,input_text){
    return entity.player.dialog({
        type: 'input',// 输入框类型
        title: title,// 标题
        titleTextColor: new GameRGBAColor(0, 0, 0, 1),
        titleBackgroundColor: new GameRGBAColor(0.968, 0.702, 0.392, 1),
        content: text, // 文本
        placeholder: input_text// 输入框背景上的提示文字。
    })  
}

async function Target_msg(entity,targetEntity,text){/*entity发起消息的玩家,targetEntity收到消息的玩家,text内容*/
    if(!text||text===0)return;//消息为空直接退出函数
    const tar_msg=await Input_dialog(
        entity, 
        targetEntity.player.name, 
        `[${targetEntity.player.name}]说:${text}`, 
        `请输入你要对[${targetEntity.player.name}]说的话`
    );if(!tar_msg||tar_msg===0)return;//消息为空直接退出函数
    await Target_msg(targetEntity,entity,tar_msg)//反复调用私聊函数,实现无限互动,不需要在新开
}

world.onPlayerJoin(({entity}) =>{
    entity.enableInteract = true; //互动开关
    entity.interactRadius = 3;  //互动范围
    entity.onInteract(async({entity,targetEntity}) =>{
        const other = await entity.player.dialog({
            type: 'select', //对话框类型为选择框
            content: `Ta的个人信息:\n\n昵称:${targetEntity.player.name}`,//提示框内容
            options: ['私聊'], //选项
        })
        if (!other || other === 0)return; //确保对话框不是点击x关闭
        else if (other.value === '私聊') { //被点击的是私聊按钮
            const msg=await Input_dialog(
                entity, 
                '私聊', 
                `你要对TA说什么?`, 
                `请输入你要对[${targetEntity.player.name}]说的话`
            )
            if(!msg||msg===0)return;//消息为空直接退出函数
            await Target_msg(targetEntity,entity,msg)     
        }
    })
})

本代码基础来自 阳光猫的:https://shequ.codemao.cn/community/419980

不喜勿喷


回复

上一页1 页 / 共 1下一页
AokenAoken

dddemotion_编程猫_搓头

点赞0


评论


虚伪_der_面具虚伪_der_面具

666

点赞1


评论


AokenAoken

喵demotion_编程猫_搓头

点赞0


评论


AokenAoken

附上测试效果:

center_image

center_image

center_image

 

emotion_雷电猴_围观

点赞1


评论


一勺小汤_纪念号一勺小汤_纪念号

收藏emotion_编程猫_点赞

点赞0


评论


肝佬肝佬

好诶!

点赞0


评论


AK亨利佐加DanJamesThomasAK亨利佐加DanJamesThomas

吃灰吧

点赞1


评论


不知道该叫啥的一只萌新不知道该叫啥的一只萌新

只能说有待完善吧 

点赞0


评论


SCS_user_rbxaHQh5aOSCS_user_rbxaHQh5aO

右键点击呢

点赞0


评论