Lv.1
大家快快关注吧! 目标:200粉500赞 ! 作品全部开源!(除重要) 预备作品中
签名:在做新的电脑(作品)
在 【求助】《enableDamage》 中回复
中间等待一会就行了)
world.onDie(async({entity})=>{
entity.player.forceRespawn()
await sleep(80)
entity.enableDamage=false
});2023-03-04T12:20:28 点赞:0
在 【神岛五一创作节】校园的多重宇宙!最后一天,冲 中回复
https://box3.codemao.cn/e/88b9964783ce137473fc
有代码吗)
中级级别))
2023-05-02T19:13:23 点赞:0
在 【神岛暑期活动第一弹】全民创作节比赛结束~ 中回复
谁想与我合作)
https://dao3.fun/edit/0a131702410478926671?frombox=1
2023-07-22T17:07:29 点赞:1
在 求助代码问题 中回复
填上开始和结束坐标就行了)
for(var x = 开始的坐标; x <= 结束的坐标; x++){
for(var y = 开始的坐标; y <= 结束的坐标; y++){
for(var z = 开始的坐标; z <= 结束的坐标; z++){
voxels.setVoxel(x,y,z,'rock')
}
}
}2023-08-07T18:23:58 点赞:1
在 【求助代码岛3.0】怎么做排行榜 中回复
该代码转载至build,幸好我吧收藏的贴都存海龟了)
/*
版权所归@build_一只建筑师吖
如需使用,复制粘贴时请勿删除此注释
违者必究!
功能:玩家数据保存和排行榜
*/
// 创建玩家数据表
(async function () {
await db.sql`
CREATE TABLE IF NOT EXISTS players (
money INTEGER NOT NULL,
lv INTEGER NOT NULL,
times INTEGER NOT NULL,
exp INTEGER NOT NULL,
userKey TEXT PRIMARY KEY UNIQUE NOT NULL
)
`
})();
// 保存玩家数据
async function saveData(entity) {
if (entity.player.userKey) {
await db.sql`
INSERT INTO players (
money,
lv,
times,
exp,
userKey
)
VALUES (
${entity.player.money},
${entity.player.lv},
${entity.player.times},
${entity.player.exp},
${entity.player.userKey}
)
ON CONFLICT(userKey)
DO UPDATE SET
money = excluded.money,
lv = excluded.lv,
times = excluded.times,
exp = excluded.exp,
userKey = excluded.userKey
`
}
}
world.onPlayerLeave(async ({ entity }) => { //玩家离开游戏后保存
try {
await saveData(entity);
} catch (error) {
world.say(`SQL ERROR: ${error}`)
console.error(`SQL ERROR: ${error}`);
}
});
// 玩家数据读取
async function loadData(entity) {
const data = (
await (
db.sql`
SELECT * FROM players WHERE userKey = ${entity.player.userKey} limit 1
`
)
)[0];
if (data) {
try {
entity.player.money = data.money;
entity.player.lv = data.lv;
entity.player.times = data.times;
entity.player.exp = data.exp;
entity.player.directMessage('已读取数据');
world.say(entity.player.name + ' 来到了发射场!')
} catch (error) {
world.say(`SQL ERROR: ${error}`)
console.error(`SQL ERROR: ${error}`);
}
} else {
await insertLeaderboard(entity.player.name, entity.player.lv);
entity.player.directMessage('你目前还没有数据,已帮你创建');
world.say(entity.player.name + " 第一次来到地图!")
}
}
// 创建排行榜表
async function createTables() {
await db.sql`CREATE TABLE IF NOT EXISTS leaderboard (
name VARCHAR(50) NOT NULL,
record REAL NOT NULL
)`
}
// 向排行榜添加数据
async function insertLeaderboard(name, lv) {
try {
await db.sql`INSERT INTO leaderboard VALUES (${name}, ${lv})`;
} catch (e) {
console.log(`SQL ERROR: ${e}`);
}
}
// 清空所有数据
async function removeAll() {
await db.sql`DELETE FROM leaderboard`
world.say(`排行榜数据已被清空!`);
}
// 获取排行榜第一名
async function getBestTime() {
const rows = await db.sql`SELECT * FROM leaderboard ORDER BY record 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 record DESC LIMIT 100`;
console.log(`result = ${JSON.stringify(rows)}`);
for await (const row of rows) {
phb[i]=`第${i+1}名:${row.name} ${row.record}级`;
i++;
}
//调试输出
console.log(phb)
}
// 获取玩家最高分数
async function getMyBestTime(player) {
const rows = await db.sql`SELECT * FROM leaderboard WHERE name=${player} ORDER BY record DESC LIMIT 1`;
if (rows && !rows.length) {
console.log('暂无数据');
return null;
}
return rows[0];
}
// 更新玩家排行榜数据
async function updatephb(user) {
await db.sql`DELETE FROM leaderboard WHERE name = ${user.name}`
await insertLeaderboard(user.name, user.lv);
}
// 当程序运行后
(async function () {
console.clear();
await createTables();
getTop100(); //获取排行榜100名
}());
world.onChat(async ({ entity: user, message }) => {
if (message === 'top100') {
await getTop100(); //获取排行榜100名
} else if (message === '清空排行榜') {
await removeAll(); //清空排行榜
}
});
world.onPlayerJoin(async ({ entity }) => {
entity.player.money = 0;
entity.player.lv = 0;
entity.player.times = 0;
entity.player.exp = 0;
// 调试玩家数据
try {
await loadData(entity); // 导入玩家数据
await saveData(entity); // 保存玩家数据
} catch (error) {
world.say(`SQL ERROR: ${error}`) // 聊天区报错
console.error(`SQL ERROR: ${error}`); // 控制台报错
}
try {
await createTables() // 创建排行榜
await getBestTime(); // 获取排行榜第一名
await getMyBestTime(); // 获取玩家最高
}
catch (error) {
world.say(`SQL ERROR: ${error}`) // 聊天区报错
console.error(`SQL ERROR: ${error}`); // 控制台报错
}
// 作者专用
// if(entity.player.name=="build_一只建筑师吖"){
// entity.player.money=Infinity;
// entity.player.lv=100;
// entity.player.exp=Infinity;
// }
updatephb(entity.player) //更新排行榜数据
});
// 右键保存玩家数据
world.onPress(async ({ button, raycast, entity }) => {
//测试代码
entity.player.money+=100;
entity.player.lv+=1;
entity.player.exp+=50;
//保存数据
if (button === 'action1') {
const main = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: entity.player.name,
content: `等级:${entity.player.lv}\n经验:${entity.player.exp}\n金币:${entity.player.money}`,
options: ['保存'],
});
if (!main || main === null) {
return;
}
if (main.index == 0) {
try {
await saveData(entity);
await updatephb(entity.player)
entity.player.directMessage('成功保存所有数据')
} catch (error) {
world.say(`SQL ERROR: ${error}`)
console.error(`SQL ERROR: ${error}`);
}
}
}
})
// 放置一个名为排行榜的模型
const 排行榜 = world.querySelector('#排行榜');
排行榜.enableInteract = true;
排行榜.interactRadius = 3;
排行榜.interactHint = 排行榜.id;
排行榜.interactColor = new Box3RGBColor(1, 1, 1);
// 当与玩家交互时
排行榜.onInteract(async ({ entity }) => {
await getTop100()
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: 排行榜.id,
titleTextColor: new Box3RGBAColor(0, 0, 0, 1),
titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1),
content: `本图前100强排行榜:`,
options: phb,
contentTextColor: new Box3RGBAColor(0, 0, 0, 1),
contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1),
});
});2023-08-29T18:52:53 点赞:0
在 【求助】如何做出只能挖掘指定一些方块的效果?求代码 中回复
//你以这个为参考))
vname = []//破坏方块的名称
world.onPress(({ button,raycast: { voxelIndex,normal,hitVoxel,distance}})=>{;
if(hitVoxel==0)return
if(voxels.name(hitVoxel) in vname && distance<=5){
if (button == Box3ButtonType.ACTION0){
let v = voxelIndex.add(normal);
voxels.setVoxel(v.x,v.y-1,v.z, '');//破坏方块
}
}
});2023-08-30T19:30:26 点赞:1