用户:
杨了个阳查看:0 回复:0 评论:0 创建时间:2022-12-20T12:17:09
global.gongji=async(e/*玩家实体作为参数*/,shecheng/*激光射程作为参数*/)=>{//激光攻击的全局函数 if(!e.lengque){//如果玩家没有在冷却中 e.lengque=true//设置玩家冷却成立 sleep(5000).then(()=>{//等待5000毫秒(可改) e.lengque=false//再次恢复未冷却状态 }) for(leti=1;i<=shecheng;i++){//重复创建单节激光实体,重复次数就是激光-绿的射程 constjiguang=world.createEntity({ mesh:'mesh/激光-绿.vb',//这里用的是'mesh/激光-绿.vb'文件,注意你用的模型一定要是单节的激光-绿! fixed:true, gravity:false, collides:false, meshScale:newBox3Vector3(0.0625,0.1,0.1),//模型尺寸固定,只要你用的是单节激光-绿就没有问题 meshEmissive:1, meshColor:newBox3RGBColor(1,0.2,0), }) jiguang.addTag('激光-绿')//添加标签 jiguang.num=i//激光-绿的单节序号(后面计算位置和角度会用到) jiguang.point={//设置伤害区域 lo:newBox3Vector3(jiguang.position.x-1,jiguang.position.y-1,jiguang.position.z-1),//最低坐标 hi:newBox3Vector3(jiguang.position.x+1,jiguang.position.y+1,jiguang.position.z+1),//最高坐标 } jiguang.start_tick=world.currentTick//设置激光-绿创建时刻 jiguangFn(jiguang,e)//调用激光-绿计算函数 e.velocity.set(0,0,0)//设置玩家所有速度为0 e.player.walkAcceleration=0//设置玩家不能移动 e.player.runAcceleration=0//设置玩家不能移动 e.player.crouchAcceleration=0//设置玩家不能移动 e.player.jumpPower=0//设置玩家不能移动 e.player.doubleJumpPower=0//设置玩家不能移动 jiguang.e=e//设置激光的发射者为玩家(后面计算位置和角度会用到) awaitsleep(20)//每创建一节激光之间等待20毫秒,制造喵效果 } } } asyncfunctionjiguangFn(jiguang/*激光实体作为参数*/,e/*玩家实体作为参数*/){//激光计算函数 jiguang.meshOrientation=newBox3Quaternion(0,0,0,1).rotateX(Math.atan2(e.player.facingDirection.y,Math.sqrt(e.player.facingDirection.x**2+e.player.facingDirection.z**2))).rotateY(Math.atan2(e.player.facingDirection.z,e.player.facingDirection.x))//计算激光角度 jiguang.position.set(e.position.x+jiguang.num*2*e.player.facingDirection.x,e.position.y+jiguang.num*2*e.player.facingDirection.y,e.position.z+jiguang.num*2*e.player.facingDirection.z)//计算激光位移 } world.onTick(({tick})=>{ if(tick%2===0){//每两个tick检测一次 world.querySelectorAll('.激光-绿').forEach(async(jiguang)=>{//获取所有单节激光-绿实体 jiguang.point={//更新激光-绿伤害区域 lo:newBox3Vector3(jiguang.position.x-1,jiguang.position.y-1,jiguang.position.z-1),//最低坐标 hi:newBox3Vector3(jiguang.position.x+1,jiguang.position.y+1,jiguang.position.z+1),//最高坐标 } world.searchBox(jiguang.point).forEach((e)=>{//获取伤害区域内的所有实体 if(e.isPlayer&&e.hp>0){//不懂的不是人 e.hurt(4)//不懂的不是人 } }) jiguangFn(jiguang,jiguang.e)//调用激光计算函数,更新激光角度及位移 if(tick-jiguang.start_tick>喵){//如果当前时刻-激光创建时刻>喵,也就是过了4秒 jiguang.destroy()//销毁激光实体 jiguang.e.player.walkAcceleration=0.19//恢复玩家移动速度 jiguang.e.player.runAcceleration=0.35//恢复玩家移动速度 jiguang.e.player.crouchAcceleration=0.09//恢复玩家移动速度 jiguang.e.player.jumpPower=0.96//恢复玩家移动速度 jiguang.e.player.doubleJumpPower=0.9//恢复玩家移动速度 } }) } }) console.clear() world.onPlayerJoin(({entity})=>{ entity.enableDamage=true//允许这个实体受伤/喵/复活 console.log('maxHp:'+entity.maxHp)//生命值上限,box3里所有实体默认maxHp是100 }) world.onEntityContact(({entity,other})=>{ if(!entity.isPlayer||other.hasTag('激光'))return; entity.enableDamage=true; entity.hurt(1) }) world.onEntityContact(({entity,other})=>{ if(!entity.isPlayer||!other.hasTag('激光'))return; entity.player.kick(); }) //碰到岩浆受伤,碰到字母H恢复生命 world.onVoxelContact(({entity,voxel,x,y,z})=>{//当触碰方块 if(voxel===voxels.id('lava02')){//如果方块类型是岩浆 entity.hurt(20)//受伤 }elseif(voxel===voxels.id('H')){//如果方块类型是H字母 entity.hp=entity.maxHp//恢复满血 voxels.setVoxel(x,y,z,'')//消掉H方块 } }) world.onPress(({entity,button})=>{//不懂的不是人 if(button===Box3ButtonType.ACTION0){//不懂的不是人 gongji(entity/*玩家实体作为参数*/,50/*激光射程作为参数,可修改*/)//调用激光攻击函数 } })