猫史档案馆


SQL的跑酷啊啊啊

用户:祸津御建鸣神命_祸津御建鸣神命_查看:2 回复:3 评论:2 创建时间:2024-01-09T20:44:22


有没有人知道pro版跑酷的sql怎么写aaa 给个帖子链接也行aaa imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E4%BC%A4%E5%BF%83.gif"alt="emotion_编程猫_伤心"


回复

上一页1 页 / 共 1下一页
祸津御建鸣神命_祸津御建鸣神命_

为什么没人回a 整个岛没一个人知道是吧imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%86%B7%E6%BC%A0.gif"alt="emotion_编程猫_冷漠"

点赞1


评论


Mecat⁧~喵呜⁧Mecat⁧~喵呜⁧

center_image

点赞0


评论


ZhaiQianYiZhaiQianYi

拿去  这是记录xyz的

console.clear()
async function initTable() {
    return await db.sql`
        CREATE TABLE IF NOT EXISTS "player" (
            "x" INT NOT NULL,
            "y" INT NOT NULL,
            "z" INT NOT NULL,
            "userKey" CHAR(16) PRIMARY KEY UNIQUE NOT NULL
        )
    `;
}
console.clear()
async function saveUser(user) {
    await db.sql`
        INSERT INTO "player" (
            "x",
            "y",
            "z",
            "userKey"
        ) VALUES (
            ${user.x},
            ${user.y},
            ${user.z},
            ${user.player.userKey}
        )
        ON CONFLICT("userKey")
        DO UPDATE SET
            "x"=excluded."x",
            "y"=excluded."y",
            "z"=excluded."z"
    `
}
console.clear()
async function loadUser(user) {
    const [data] = await db.sql`SELECT * FROM "player" WHERE "userKey"=${user.player.userKey} LIMIT 1`
    if (data) {
        user.x = data.x
        user.y = data.y
        user.z = data.z
        user.position = [user.x,user.y,user.z]
    }
    else {
        saveUser(user)
    }
}
console.clear()
async function poll(fn, msg) {
    while (true) {
        try {
            return await fn()
        } catch (e) {
            const m = e.message
            if (m.includes('timeout')) {
                world.say('数据库出错 检查结果 :启动超时,请联系官方进行修复 &&&&& timeout')
            }
        }
        await sleep(2000) 
    }
}
console.clear()
poll(initTable, '等待主数据库启动...')
world.onPlayerJoin(({ entity }) => {
    loadUser(entity)
})
console.clear()
for (const e of world.querySelectorAll('*')) {
    if (e.id.startsWith('存档点')) {
        e.collides = true 
        e.fixed = true 
        e.onEntityContact(({ other }) => {
            if (other.isPlayer) { 
                if (e.position !== other.player.spawnPoint) {
                    other.player.directMessage('到达新的重生点') 
                    other.player.spawnPoint = e.position 
                    other.x = Math.ceil(other.position.x)
                    other.y = Math.ceil(other.position.y)
                    other.z = Math.ceil(other.position.z)
                    saveUser(other)
                }
            }
        })
    }
}

点赞1


评论