用户:
J_K_Hermione_build白泽查看:3 回复:9 评论:3 创建时间:2020-10-09T22:38:47
话不多说,直接上代码:
第一个,玩家加入游戏是显示对话框:

// 玩家进入游戏时,弹出一个文本对话框
world.onPlayerJoin(({ entity }) => {
const dialog = entity.player.dialog({
type: Box3DialogType.TEXT,
title: "本地图作者", // 对话框标题。通常对应是讲话人的名字。
titleTextColor: new Box3RGBAColor(0, 0, 0, 1), // 标题字体颜色。
titleBackgroundColor: new Box3RGBAColor(0.968, 0.702, 0.392, 1), // 标题背景颜色。
content: `你好,${entity.player.name},很高兴认识你,快来探索奇妙的东西吧!(有2个彩蛋)`, // 对话框内容。也就是对话正在讲什么。
contentTextColor: new Box3RGBAColor(0, 0, 0, 1), // 对话框字体颜色。
contentBackgroundColor: new Box3RGBAColor(1, 1, 1, 1), // 对话框背景颜色。
lookEye: entity.position.add(entity.player.facingDirection.scale(5)), // 调整相机位置,摆在玩家朝向的前方5格距离。
lookTarget: entity, // 将相机镜头朝向玩家实体。
});
});
J_K_Hermione_build白泽第二个,如何写一个装备代码呢?示例,写一个“写代码”的装备:

world.onPlayerJoin(({ entity }) => {
if (entity.player.name === "J_K_Hermione_build白泽")
entity.player.a喵Wearable({
bodyPart: Box3BodyPart.HEAD,
mesh: 'mesh/写代码.vb',
scale: new Box3Vector3(0.5, 0.5, 0.5),//模型大小长宽高都缩小0.5倍
orientation: new Box3Quaternion(0, 1, 0, 1),//将模型的旋转角度调整
offset: new Box3Vector3(0, 0.8, 1),//装备的位置,向人背后偏移一些
});
});
点赞1
评论
J_K_Hermione_build白泽第三个,如何蹲下回血?想月球大战里面的一样呢?上代码:
world.onPress(({button,entity},) => {
//console.log(button)
if (button == 'crouch') {
if (entity.hp < entity.maxHp) {
back = entity.maxHp+50
//backF(entity,back)
} else {
entity.hp = entity.maxHp
}
}
})点赞1
评论
J_K_Hermione_build白泽第四个,简单的上下车代码,但很实用哦~
(可以把雷电猴换成其他的哦)
world.querySelectorAll('#雷电猴-1').forEach((e)=>{
e.onEntityContact(({entity,other})=>{
if(!other.isPlayer){return}
other.mesh=entity.mesh;
other.meshScale=entity.meshScale;
other.meshOrientation = new Box3Quaternion(0, 0, 0, 0);//这段代码没法左右旋转
other.player.invisible=true;
world.say(other.player.name+' 你带走了雷电猴')
world.say('说我要下车就可以下车了')
})
})
world.onChat(({message,entity})=>{
if(message==='我要下车'){
entity.mesh='';
entity.player.invisible=false;
world.say(entity.player.name+'下了车')
}
})点赞0
评论
J_K_Hermione_build白泽第五个,PVP代码(大佬不喜勿喷)
orld.onPlayerJoin(({ entity }) => {
entity.enableDamage = true;
entity.player.onPress(({ button, raycast:{ hitEntity, direction } }) => {
if (button !== 'action0' || !hitEntity) {
return;
}
if(hitEntity.isPlayer===true){
hitEntity.velocity.y += 0.5;
}
hitEntity.hurt(20 * Math.random() + 5, {
attacker: entity,
});
if(entity.player.name == "J_K_Hermione_build白泽"){//这是外挂
hitEntity.hurt(9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, {
attacker: entity,
});
}
});
});
world.onDie(({ entity, attacker }) => {
if (attacker) {
world.say(attacker.player.name + ' 击杀了 ' + entity.player.name)
}
entity.player.forceRespawn();
});//pvp代码、点赞0
评论
J_K_Hermione_build白泽第六个,一个管理员代码,希望大家喜欢:
world.onChat(({ entity, message }) => {
if (entity && entity.isPlayer) {
if (entity && 'J_K_Hermione_build白泽'.split(' ').indexOf(entity.player.name) != -1 && message.charAt(0) == '$') {
try {
entity.player.directMessage('<~ ' + eval(message.split('$')[1]))
} catch (err) {
entity.player.directMessage('Error:' + err)
}
};
}
})点赞0
评论