猫史档案馆


[求助]神奇代码岛之存档代码

用户:龙皇斗罗士兵连连长龙皇斗罗士兵连连长查看:3 回复:5 评论:3 创建时间:2023-01-30T13:07:59


不是存档点,就是sol玩家离开地图再进来还在那个位置,像凤凰塔跑酷


回复

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

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

点赞0


评论


望柒望柒

用SQL保存玩家的位置喽

点赞0


评论


一勺小汤_纪念号一勺小汤_纪念号

c喵t SpawnPoint = new Box3Vector3(29,8,60);
c喵t points = world.querySelectorAll('.存档点');
c喵t INIT = {
    hp: 100,
    maxHp: 100,
    enableDamage: true,
    x: SpawnPoint.x,
    y: SpawnPoint.y,
    z: SpawnPoint.z,
    qx: SpawnPoint.x,
    qy: SpawnPoint.y,
    qz: SpawnPoint.z,
    jumpcounttime: 2,
    level: 0,
}
db.sql`CREATE TABLE IF NOT EXISTS leaderboard(
    id CHAR(16) NOT NULL,
    record TEXT NOT NULL
)`
world.addCollisionFilter('player','player');
world.onPlayerJoin(async({entity})=>{
    function init(){
        Object.assign(entity,INIT);
    }
    if(entity.player.userKey){
        c喵t rows = await db.sql`SELECT * FROM leaderboard WHERE id = ${entity.player.userKey}`;
        if(rows && !rows.length){
            init();
            db.sql`INSERT INTO leaderboard VALUES(${entity.player.userKey},${getRecord.call(entity)})`;
        }else{
            Object.assign(entity,JSON.parse(rows[0].record));
        }
    }else init();
    entity.position.set(entity.x,entity.y,entity.z);
    entity.player.spawnPoint.set(entity.qx,entity.qy,entity.qz);
    Object.assign(entity.player,{
        scale: 0.7,
        jumpPower: 0.5,
        doubleJumpPower: 0.4,
        runSpeed: 0.3,
    })
    entity.player.onPress(async({button})=>{
        if(button === Box3ButtonType.ACTION0){
            entity.hurt(100);
        }else if(button === Box3ButtonType.ACTION1){
            c喵t result = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: '控制面板',
                content: '加油',
                opti喵: ['重新开始','切换视角',`可跳关次数:${entity.jumpcounttime}`,'取消'],
            })
            if(!result)return;
            switch(result.index){
                case 0:
                    Object.assign(entity,INIT);
                    entity.position.set(entity.x,entity.y,entity.z);
                    entity.player.spawnPoint.set(entity.qx,entity.qy,entity.qz);
                    update.call(entity);
                    break;
                case 1:
                    if(entity.player.cameraMode === 'follow'){
                        entity.player.cameraMode = 'fps';
                    }else{
                        entity.player.cameraMode = 'follow';
                    }
                    break;
                case 2:
                    entity.player.cancelDialogs();
                    if(entity.jumpcounttime){
                        let found = false;
                        points.forEach((e)=>{
                            if(found)return;
                            if(e.level === entity.level + 1){
                                found = true;
                                entity.position = e.position.add({x: 0,y: 3,z: 0});
                                entity.player.spawnPoint.copy(entity.position);
                                entity.level = e.level;
                                entity.jumpcounttime--;
                            }
                        })
                        if(!found){
                            entity.player.dialog({
                                type: Box3DialogType.TEXT,
                                title: '跳关失败',
                                content: '没有可跳过的关卡',
                            })
                        }
                    }else{
                        entity.player.dialog({
                            type: Box3DialogType.TEXT,
                            title: '跳关失败',
                            content: '你已没有了跳关次数',
                        })
                    }
                    break;
                default:
                    return;
            }
        }
    })
})
world.onDie(({entity})=>{
    if(entity.isPlayer){
        entity.player.forceRespawn();
    }
})
points.forEach((e)=>{
    e.level = Number(e.tags()[0]);
    e.onEntityContact(({other})=>{
        c喵t spawnPoint = e.position.add({x: 0,y: 2.5,z: 0});
        if(spawnPoint.equals(other.player.spawnPoint))return;
        other.player.spawnPoint = spawnPoint;
        other.player.directMessage('存档成功!');
        other.level = e.level;
        update.call(other);
    })
})
function getRecord(){
    c喵t result = {};
    Object.keys(INIT).forEach((e)=>{
        result[e] = this[e];
    })  
    return JSON.stringify(result);
}
function update(){
    if(!this.player.userKey)return;
    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;
    db.sql`UPDATE leaderboard SET record = ${getRecord.call(this)} WHERE id = ${this.player.userKey}`;
}
world.onPlayerLeave(({entity})=>{
    update.call(entity);
})

点赞0


评论


望柒望柒

龙皇,你家的熊猫把我贡献者职位撤了改成建筑师,内家伙无法无天了啊啊啊,你去管一下啊啊啊啊

点赞0


评论


龙皇斗罗士兵连连长龙皇斗罗士兵连连长

迷惑的阿珂好的

点赞0


评论