用户:
好吃的奇异果查看: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}
你不是作者哦!`,
})
}
}
})
如有意见请在评论区回复