Lv.1
大家快快关注吧! 目标:200粉500赞 ! 作品全部开源!(除重要) 预备作品中
签名:在做新的电脑(作品)
在 【分队进阶II】完善与添加玩法 中回复
修改后代码:
team=5//队数,可改
team2=["red","blue","yellow","green",'black']//队相对应的队名,可改
world.teams=[]
world.onPlayerJoin(({entity})=>{//初始化
entity.maxHp=100
entity.enableDamage=true
entity.ining=0
entity.randoms=0
entity.mining=0
entity.toye=0
entity.falealow=[]
entity.a=[]
entity.thewords=0
entity.leaf=0
entity.abcdefghijklmnopqrstuvwxyz=0
})
console.clear()
function addd(){ining=1}
function adddd(a,i){abcdefghijklmnopqrstuvwxyz=a[i]}
function random(minNum,maxNum){ //随机数()()()
switch(arguments.length){
case 1:
return parseInt(Math.random()*minNum+1,10);
break;
case 2:
return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10);
break;
default:
return 0;
break;
}
}
var searchInsert = function(nums, target) {//查找该数组值位置
let arr=nums
arr.splice(0,0,target)
return nums.indexOf(target)>0?nums.indexOf(target):arr.sort((a,b)=>a-b).indexOf(target)
};
function toTeams(zhi,entity){
zhi1=[1,0,2,0,0]//颜色R:
zhi2=[0,0,2,1,0]//颜色G:
zhi3=[0,1,0,0,0]//颜色B:
entity.player.color.set(zhi1[zhi],zhi2[zhi],zhi3[zhi])
}
function intag(entity,aa){
for(i in team2)entity.hasTag(team2[i]) ? adddd(team2,i) : null
if(aa.hasTag(abcdefghijklmnopqrstuvwxyz)){
return true
}
return false
}
world.onClick(({ entity, clicker ,attacker,raycast:{distance}}) => {
if(!entity.isPlayer)return
if(intag(clicker,entity))return
if(distance<20){entity.hurt(10, { attacker: clicker }) //伤害
//entity.hurt(10, { attacker: clicker })
entity.player.directMessage('你受到了来自'+clicker.player.name+'的10点伤害,剩余'+entity.hp+'血量')}
})
world.onDie(async({entity,attacker})=>{
if(!attacker||attacker==null)return
world.say(attacker.player.name+'击杀了'+entity.player.name)
entity.player.directMessage('3秒后复活')//复活
await sleep(3000)
entity.player.forceRespawn()
})
world.onPlayerJoin(async({entity})=>{
for(var i=0;i<=team-1;i++)world.teams.push([]);//分配
for(var i=0;i<=team-1;i++)i==0 ? entity.thewords=world.teams[i].lenth : entity.thewords==world.teams[i].lenth ? null : addd();
if(entity.ining){//如果每队长度不相同
for(i in world.teams)entity.a.push(world.teams[i])
entity.mining=Math.min.apply(null, entity.a)
for(i in world.teams) if(world.teams[i].length==entity.mining){entity.toye+=1;entity.falealow.push(team2[i])}
entity.randoms=random(0,toye-1);
world.teams[searchInsert(team2,entity.falealow[entity.randoms])].push(entity.player.name);
entity.addTag(entity.falealow[entity.randoms])//添加标签,以区别相同/不相同队
world.say(entity.player.name+' in...'+entity.falealow[entity.randoms])//宣布队名
toTeams(searchInsert(team2,entity.falealow[entity.randoms]),entity)//调用分队函数
//world.say(entity.hasTag("blue"))
}else if (entity.ining==0){//如果相同
entity.randoms=random(0,team-1);
world.teams[entity.randoms].push(entity.player.name);
world.say(entity.player.name+' in...'+team2[entity.randoms]) ;//宣布队名
entity.addTag(team2[entity.randoms])
toTeams(entity.randoms,entity)
//world.say(entity.hasTag('blue'))
}
//world.say(teams)
})2022-10-01T19:51:51 点赞:0