猫史档案馆


意见箱教程

用户:好吃的奇异果好吃的奇异果查看:1 回复:2 评论:1 创建时间:2022-11-28T14:45:13


//意见箱
//权限(自己弄)
let admin=['func奇异果徒弟QYG']
// 创建表
async function createTables_Suggestions_Complaints_Box_SQL() {
    await db.sql`CREATE TABLE IF NOT EXISTS Suggestions_Complaints_Box_SQL (
        name VARCHAR(50) NOT NULL,
        opinion VARCHAR(200) NOT NULL
    )`
}
/* 在脚本开始的时候执行 */
(async function () {
    await createTables_Suggestions_Complaints_Box_SQL()
}());
// 插入数据函数
async function insertRecord_Suggestions_Complaints_Box_SQL(name, opinion) {
    try {
        await db.sql`
            INSERT INTO Suggestions_Complaints_Box_SQL VALUES (${name}, ${opinion}) 
        `;
    } catch (e) {
        console.log(`insert sql error: ${e}`);
    }
}
// 将数据输出
async function printRecord_Suggestions_Complaints_Box_SQL(entity) {
    rows = await db.sql`SELECT * FROM Suggestions_Complaints_Box_SQL`
    if (rows && !rows.length) {
        entity.player.dialog({
            type: Box3DialogType.TEXT,
            title: `系统`,
            content: `目前还没有意见哦!`
        })
        return '目前还没有意见哦!';
    }
    for await (const row of db.sql`SELECT * FROM Suggestions_Complaints_Box_SQL`) {
        entity.player.dialog({
            type: Box3DialogType.TEXT,
            title: `系统`,
            content: `姓名:${row.name} : 意见:${row.opinion}`
        })
    }
}
// 清除表格所有数据 (表格结构不变)
async function removeAll_Suggestions_Complaints_Box_SQL() {
    await db.sql`DELETE FROM Suggestions_Complaints_Box_SQL`
}
//意见箱设置
const Suggestions_Complaints_Box = world.querySelector('#意见箱');
Suggestions_Complaints_Box.enableInteract = true;
Suggestions_Complaints_Box.interactHint = Suggestions_Complaints_Box.id;
Suggestions_Complaints_Box.interactRadius = 3
Suggestions_Complaints_Box.onInteract(async ({ entity }) => {
    const result = await entity.player.dialog({
        type: Box3DialogType.SELECT,
        title: `意见箱`,
        content: '请选择需要什么:',
        options: ['提意见', '查看意见(作者)', '删除所有意见(作者)'],
    })
    if (!result || result === null) {
        return '关闭';
    }
    if (result.index == 0) {
        entity.hurt(1)
        const result = await entity.player.dialog({
            type: Box3DialogType.INPUT,
            title: "系统",
            titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
            titleBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98),
            content: `亲爱的玩家${entity.player.name},你有什么建议呢?`,
            confirmText: '确定', // 确定按钮上面的文字。按下确定按钮后,提交回答。
            placeholder: '输入你的建议', // 输入框背景上的提示文字。
            contentTextColor: new Box3RGBAColor(1, 1, 1, 1),
            contentBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98),
            lookEye: entity.position.add(entity.player.facingDirection.scale(5)),
            lookTarget: entity,
        });
        if (!result || result === null) {
            return '关闭';
        } else {
            insertRecord_Suggestions_Complaints_Box_SQL(entity.player.name, String(result))
            entity.player.dialog({
                type: Box3DialogType.TEXT,
                title: Suggestions_Complaints_Box.id,
                content: '提交成功!(SQL上传成功!)'
            })
        }
    }
    if (result.index == 1) {
        if (admin.includes(entity.player.name)) {
            printRecord_Suggestions_Complaints_Box_SQL(entity)
        } else {
            entity.player.dialog({
                type: Box3DialogType.TEXT,
                title: "系统",
                content: `你的权限: ${entity.player.jurisdiction}
                你不是作者哦!`,
            })
        }
    } if (result.index == 2) {
        if (admin.includes(entity.player.name)) {
            removeAll_Suggestions_Complaints_Box_SQL()
            entity.player.dialog({
                type: Box3DialogType.TEXT,
                title: "系统",
                content: '意见箱已清空!',
            })
        } else {
            entity.player.dialog({
                type: Box3DialogType.TEXT,
                title: "系统",
                content: `你的权限: ${entity.player.jurisdiction}
                你不是作者哦!`,
            })
        }
    }
})

如有意见请在评论区回复


回复

上一页1 页 / 共 1下一页
名探酱名探酱

emmm《教程》

点赞2


评论


这是公开代码,不是教程()()不过屑屑你了()()

点赞1


评论