猫史档案馆


跑酷SQL教程

用户:今天终于尽力了今天终于尽力了查看:0 回复:1 评论:0 创建时间:2023-03-15T19:24:41


有些不是

 

const INIT = {     sx:0,     lv:0,     x: 0,     y: 0,     z: 0,     qx: 0,     qy: 0,     qz: 0,     tg:3,     win:0,     jsq:0,     js:0,     leve:0,     zhuxianjsq:0,     zhuxiancd:0,     zhixianjsq:0,     zhixiancd:0,     kzmb:1

 

} db.sql`CREATE TABLE IF NOT EXISTS wuyu(     id CHAR(16) NOT NULL,     record TEXT NOT NULL )` world.onPlayerJoin(async ({ entity }) => {     function init() {         Object.assign(entity, INIT);     }     if (entity.player.userKey) {         const rows = await db.sql`SELECT * FROM wuyu WHERE id = ${entity.player.userKey}`;         if (rows && !rows.length) {             init();             db.sql`INSERT INTO wuyu VALUES(${entity.player.userKey},${getRecord.call(entity)})`;         } else {7             Object.assign(entity, JSON.parse(rows[0].record));         }     } else init();             if (entity.x && entity.y && entity.z         && entity.qx && entity.qy && entity.qz     ) {         entity.position.set(entity.x, entity.y, entity.z);         entity.player.spawnPoint.set(entity.qx, entity.qy, entity.qz);     }     if(entity.win==1){         if(entity.kzmb==2)return;         entity.enableDamage=false         entity.player.canFly=true     }     if(entity.sx==0){         entity.sx='没有记录'     }      }) function getRecord() {     const result = {};     Object.keys(INIT).forEach((e) => {         result[e] = this[e];     })     return JSON.stringify(result); } function update() {     if (!this.player.userKey) return;     this.lv = this.lv     this.x = this.position.x;     this.y = this.position.y;     this.z = this.position.z;     this.qx = this.player.spawnPoint.x;     this.qy = this.player.spawnPoint.y;     this.qz = this.player.spawnPoint.z;     this.tg = this.tg;     this.win= this.win;     this.jsq = this.jsq;     this.sx = this.sx;     this.zhuxianjsq = this.zhuxianjsq;     this.zhuxiancd = this.zhuxiancd;     this.js = this.js;     this.leve = this.leve;     this.kzmb = this.kzmb;     this.zhixianjsq = this.zhixianjsq;     this.zhixiancd = this.zhixiancd;     db.sql`UPDATE wuyu SET record = ${getRecord.call(this)} WHERE id = ${this.player.userKey}`; } world.onPlayerLeave(({ entity }) => {     update.call(entity); })

 

async function createTable() {     await db.sql`CREATE TABLE IF NOT EXISTS leaderboard (         name VARCHAR(50) PRIMARY KEY UNIQUE NOT NULL,         r INTEGER NOT NULL     )`; }

 

createTable();

 

// 插入数据 async function insertLeaderboard(name, sx) {     try {         await db.sql`INSERT INTO leaderboard VALUES (${name}, ${sx})`;     } catch (e) {         console.log(`SQL ERROR: ${e}`);     } }



// 获取排行榜第一名 async function getBestTime() {     const rows = await db.sql`SELECT * FROM leaderboard ORDER BY r DESC LIMIT 1`;     if (rows && !rows.length) {         console.log('暂无数据');     }     return rows[0]; } // 获取排行榜前100名 async function getTop100() {     // 向排行榜插入数据     let i = 0;     phb = ['',];     const rows = await db.sql`SELECT * FROM leaderboard ORDER BY r ASC LIMIT 100`;     console.log(`result = ${JSON.stringify(rows)}`);     for await (const row of rows) {         phb[i]=`第${i+1}名:${row.name} ${row.r}秒`;         i++;     }

 

    //调试输出     console.log(phb) } async function updatePlayersRecord(name, value) {     try {         await db.sql`UPDATE leaderboard SET r = ${value} WHERE name = ${name}`;      } catch (e) {         console.log(`update sql error: ${e}`) ;     } }


回复

上一页1 页 / 共 1下一页
yyds二营长yyds二营长

az

点赞0


评论