猫史档案馆


Aoken

Aoken

Lv.1

念往昔岁月

获赞:192收藏:83浏览:6516作品收藏:10

签名:dao3 羽岚.龍族[原]:Aoken 是我 2022-05-29 22:55:02 注册此账号 如想知道自己账号注册时间 记得先登录好账号可打开:https://api.codemao.cn/web/users/details 查看create_time的数字 并在 https://tool.lu/timestamp/ 进行时间轴转换

回复帖子评论
上一页第 21 页 / 共 23 页下一页

在 [Box3]pro版私聊代码 中回复

附上测试效果:

center_image

center_image

center_image

 

emotion_雷电猴_围观

2023-08-24T19:40:51 点赞:1

在 【Python作品分享】新的作品 中回复

2023-08-24T21:18:13 点赞:0

在 【box3】【射击子弹代码公布】 中回复

挖)

2023-08-26T15:31:35 点赞:0

在 【岛3活动】搬砖喵看家代码公布:粒子大乱斗! 中回复

挖()

2023-08-26T17:38:40 点赞:0

在 【每日亿个岛3建图小技巧】点击建造或者摧毁方块,创意达人必备! 中回复

挖0

2023-08-26T17:51:35 点赞:0

在 【PRO版编辑器】新版数据库模板(附排行榜+清档) 中回复

怎么做自动云存呢?(狗头保命)emotion_编程猫_谢谢老板

2023-08-26T21:21:16 点赞:0

在 简单的存档模板 中回复

顶)

2023-08-27T10:48:26 点赞:0

在 。。。。。。 中回复

需要一些控件

2023-08-27T21:21:23 点赞:1

在 岛3怎么用 中回复

??

2023-08-29T16:08:41 点赞:0

在 rsa理论原理 中回复

nb caseemotion_编程猫_点赞

2023-08-29T16:10:34 点赞:0

在 岛3怎么用 中回复

center_image

2023-08-29T16:25:04 点赞:0

在 【求助代码岛3.0】怎么做排行榜 中回复

ddd

2023-08-29T17:25:40 点赞:0

在 【最终版】史上最简单易用的SQL模板,点进来就是赚到! 中回复

报错了怎么办?

center_image

代码:

console.clear();
const PlayerData = {
    money: [1, true],
    lv: [0, true],
    exp:[0,true],
    itemList: [['铁剑'], true],
    test: ['yee', false]
};
const CorrespondingName = {// 在此添加排行榜对应的单位和名称(无名称 则表示不显示名称)
    'money': ['枚', '金币'],
    'lv': ['级', '无名称']
};
(async () => {await poll(createTable)})();
async function poll(fn, msg) {
    while (1) {
        try {
            return await fn()
        } catch (e) {
            e.message.includes('timeout') ? world.say(e.message) : world.say(msg || e.stack)
        }
        await sleep(2000)
    }
};
async function createTable() {
    await db.sql`
        CREATE TABLE IF NOT EXISTS "YJZTX" (
            "datas" TEXT NOT NULL,
            "userKey" CHAR(16) PRIMARY KEY UNIQUE NOT NULL
        )
    `
}

/**
 * 初始化玩家数据
 * 
 * @param {Box3Entity} entity
 */
function initPlayer(entity) {
    for (let i in PlayerData) {
        entity[i] = PlayerData[i][0]
    }
};

/**
 * 获取玩家数据
 * 
 * @param {Box3Entity} entity
 */
function getPlayerData(entity) {
    var data = { "name": entity.player.name };
    for (let i in PlayerData) {
        PlayerData[i][1] ? data[i] = entity[i] : null
    };
    return JSON.stringify(data);
};

/**
 * 存档
 * 
 * @param {Box3Entity} entity
 */
async function savePlayer(entity) {
    if (!entity.player.userKey) return;
    await db.sql`
        INSERT INTO "YJZTX" (
            "datas", 
            "userKey"
        ) 
        VALUES (
            ${getPlayerData(entity)}, 
            ${entity.player.userKey}
        )
        ON CONFLICT("userKey")
        DO UPDATE SET
        "datas" = excluded."datas"
    `
};

/**
 * 读档
 * 
 * @param {Box3Entity} entity
 */
async function loadPlayer(entity) {
    const [data] = await db.sql`SELECT * FROM "YJZTX" WHERE "userKey" = ${entity.player.userKey} LIMIT 1`;
    if (data) {
        var Data = JSON.parse(data.datas);
        for (let i in PlayerData) {
            Data[i] ? entity[i] = Data[i] : entity[i] = PlayerData[i][0]
        }
    } else { 
        initPlayer(entity)
    };
};

/**
 * 读取榜单前100
*/
async function getTop100(type) {
    var list = [];
    for await (let row of db.sql`SELECT * FROM "YJZTX"`) {
        list.push([JSON.parse(row.datas).name, JSON.parse(row.datas)[type]])
    };
    return list.sort((a, b) => a[1] - b[1]).map((value, num) => {
        return `第${num + 1}名 | ${value[0]} | ${value[1]}${CorrespondingName[type][0]}${CorrespondingName[type][1] != '无名称' ? CorrespondingName[type][1] : ''}`
    })
}

/**
 * 删档
 * 
 * @param {Box3Entity} entity
 */
async function deletePlayer(entity) {
    await db.sql`DELETE FROM YJZTX WHERE "userKey" = ${entity.player.userKey}`;
};

world.onPlayerJoin(async ({ entity }) => {
    await loadPlayer(entity);
});
world.onPlayerLeave(async ({ entity }) => {
    await savePlayer(entity)
})

world.onPress(async({ entity, button }) => {
    if (button == 'action1') {
        const ask = await entity.player.dialog({
            type: 'select',
            title: '测试',
            content: `你目前[${entity.lv}]级\n[${entity.exp}]点经验\n[${entity.money}]枚金币\n背包:[${entity.itemList}]`,
            options: ['点我加等级', '点我加经验', '点我加金币','排行榜']
        });
        if (!ask) return;
        if (ask) {
            if (ask.index <= 2) {
                entity[['lv', 'exp', 'money'][ask.index]]++;
            }if(ask.index == 3){
                await entity.player.dialog({
                    type: 'select',
                    title: '排行',
                    content: await getTop100('money'),
                    options: ['确认']
                });      
            }
        };
    };
});

2023-08-29T20:11:34 点赞:1

在 【神岛JS萌新教程】BoxJS 从入门到实战 第十四期——神奇的选择器! 中回复

催更)emotion_编程猫_加油

2023-08-29T21:51:57 点赞:0

在 我的世界自创服务器 中回复

哎,我都不知道则呢么才能玩emotion_抓狂

2023-08-29T21:58:15 点赞:0

在 【代码岛3.0】忽然曝光的年兽随机移动代码 中回复

center_image

2023-08-30T09:18:44 点赞:0

在 Box3CameraSettings动画库 中回复

center_image

2023-08-30T09:20:57 点赞:1

在 那位大佬会iframe链接 中回复

https://shequ.codemao.cn/community/514316

2023-08-30T10:38:47 点赞:0

在 【求解】代码有问题吗 中回复

应该是这里:

center_image

应该要改成:x y z

2023-08-31T11:10:05 点赞:0

在 通用画圆公式 中回复

ddd

2023-08-31T16:28:04 点赞:0

在 如何去掉“去CoCo制作”“手机壳”“侧边栏”(不用控件) 中回复

ddd

2023-08-31T16:28:54 点赞:0

在 Minecraft盔甲公式(内涵作品) 中回复

。。

2023-08-31T16:39:38 点赞:0

在 b站求关注 中回复

我在b站叫:Aoken-在线

2023-09-04T20:29:12 点赞:0

在 【岛3活动】搬砖喵看家代码公布:粒子大乱斗! 中回复

收藏

2023-09-06T20:55:30 点赞:2

在 【自研集成电路】GERT-G1 for Test 8060X研发进程 中回复

,,

2023-09-07T21:57:36 点赞:0

在 【教程】如何在pro版地图编辑器中让实体丝滑的切换动作 中回复

addd,

2023-09-08T22:56:33 点赞:0

在 【教程】教你如何把模型从旧编辑器迁移到新编辑器! 中回复

喵d

2023-09-13T21:15:02 点赞:0

在 ???不是不能发帖了吗??? 中回复

但现在还可以再工作室来发帖

2023-09-13T21:17:45 点赞:0

在 [氵][一期]那些你不知道的高级js用法 中回复

喵d

2023-09-13T21:19:23 点赞:0

在 [每日一氵]非常食用的建图小工具 中回复

喵d

2023-09-13T21:27:34 点赞:0