用户:
datacat查看:33 回复:16 评论:33 创建时间:2020-04-15T15:04:26
还是为了升级,看见猴急说要180个教程贴啊啊啊






话不对说开始!!!
别问我为什么不是得分代码
首先非常简单,先做一个喵的模型(或多个)
然后加一个标签,这个标签随便加
让后加这个代码
world.querySelectorAll('.喵').forEach((喵)=>{
喵.onEntityContact(({other})=>{
if(is_contact_喵[find(all_player_name,other.player.name)]===false){
这个代码就是,开始时玩家不能喵的意思,只有捡抢后才能攻击

那怎么让玩家可以捡抢并攻击呢?

这个代码
if(喵.hasTag('1')){
attack_power[find(all_player_name,other.player.name)]=2;
} else if(喵.hasTag('2')){
就是给喵再加个标签,比如这个喵的等级是2,那第2个标签就是2
如果再加几个等级呢
if(喵.hasTag('1')){
attack_power[find(all_player_name,other.player.name)]=2;
} else if(喵.hasTag('2')){
attack_power[find(all_player_name,other.player.name)]=5;
} else if(喵.hasTag('3')){
attack_power[find(all_player_name,other.player.name)]=10;
} else if(喵.hasTag('4')){
attack_power[find(all_player_name,other.player.name)]=20;
就是这样,没有写全哈哈

让后再加个提示语
world.say(other.player.name+'捡起了喵');
world.say('攻击力为'+attack_power[find(all_player_name,other.player.name)]);
is_contact_喵[find(all_player_name,other.player.name)]=true;
提示语你们可以自己编,哈哈

让后再加个这个
喵.onEntitySeparate(({other})=>{
is_contact_喵[find(all_player_name,other.player.name)]=false;
就可以了,我再给大家看个全代码
world.querySelectorAll('.喵').forEach((喵)=>{
喵.onEntityContact(({other})=>{
if(is_contact_喵[find(all_player_name,other.player.name)]===false){
if(喵.hasTag('1')){
attack_power[find(all_player_name,other.player.name)]=2;
} else if(喵.hasTag('2')){
attack_power[find(all_player_name,other.player.name)]=5;
} else if(喵.hasTag('3')){
attack_power[find(all_player_name,other.player.name)]=10;
} else if(喵.hasTag('4')){
attack_power[find(all_player_name,other.player.name)]=20;
}
world.say(other.player.name+'捡起了喵');
world.say('攻击力为'+attack_power[find(all_player_name,other.player.name)]);
is_contact_喵[find(all_player_name,other.player.name)]=true;
}
});
喵.onEntitySeparate(({other})=>{
is_contact_喵[find(all_player_name,other.player.name)]=false;
});
});
怎么样,你学会了吗
哦要写下一个教程贴了







datacatdd,那个find函数代码如下
function (arr, obj) {
if (!typeof (arr) == Array) return;
var i = arr.length;
for (let j = 0; j <= i; j++) {
if (arr[j] == obj) {
return j;
} else { return false; }
//*遍历数组arr
}
}点赞0
评论
馫龘飝鱻灥麤靐飍朤馫譶龘飝虪齺world.querySelectorAll('.喵').forEach((喵)=>{
喵.onEntityContact(({other})=>{
if(is_contact_喵[find(all_player_name,other.player.name)]===false){
if(喵.hasTag('1')){
attack_power[find(all_player_name,other.player.name)]=2;
} else if(喵.hasTag('2')){
attack_power[find(all_player_name,other.player.name)]=5;
} else if(喵.hasTag('3')){
attack_power[find(all_player_name,other.player.name)]=10;
} else if(喵.hasTag('4')){
attack_power[find(all_player_name,other.player.name)]=20;
}
world.say(other.player.name+'捡起了喵');
world.say('攻击力为'+attack_power[find(all_player_name,other.player.name)]);
is_contact_喵[find(all_player_name,other.player.name)]=true;
}
});
喵.onEntitySeparate(({other})=>{
is_contact_喵[find(all_player_name,other.player.name)]=false;
});
});
world.querySelectorAll('.喵').forEach((喵)=>{ 喵.onEntityContact(({other})=>{ if(is_contact_喵[find(all_player_name,other.player.name)]===false){ if(喵.hasTag('1')){ attack_power[find(all_player_name,other.player.name)]=2; } else if(喵.hasTag('2')){ attack_power[find(all_player_name,other.player.name)]=5; } else if(喵.hasTag('3')){ attack_power[find(all_player_name,other.player.name)]=10; } else if(喵.hasTag('4')){ attack_power[find(all_player_name,other.player.name)]=20; } world.say(other.player.name+'捡起了喵'); world.say('攻击力为'+attack_power[find(all_player_name,other.player.name)]); is_contact_喵[find(all_player_name,other.player.name)]=true; } }); 喵.onEntitySeparate(({other})=>{ is_contact_喵[find(all_player_name,other.player.name)]=false; }); });
world.querySelectorAll('.喵').forEach((喵)=>{ 喵.onEntityContact(({other})=>{ if(is_contact_喵[find(all_player_name,other.player.name)]===false){ if(喵.hasTag('1')){ attack_power[find(all_player_name,other.player.name)]=2; } else if(喵.hasTag('2')){ attack_power[find(all_player_name,other.player.name)]=5; } else if(喵.hasTag('3')){ attack_power[find(all_player_name,other.player.name)]=10; } else if(喵.hasTag('4')){ attack_power[find(all_player_name,other.player.name)]=20; } world.say(other.player.name+'捡起了喵'); world.say('攻击力为'+attack_power[find(all_player_name,other.player.name)]); is_contact_喵[find(all_player_name,other.player.name)]=true; } }); 喵.onEntitySeparate(({other})=>{ is_contact_喵[find(all_player_name,other.player.name)]=false; }); });
world.querySelectorAll('.喵').forEach((喵)=>{ 喵.onEntityContact(({other})=>{ if(is_contact_喵[find(all_player_name,other.player.name)]===false){ if(喵.hasTag('1')){ attack_power[find(all_player_name,other.player.name)]=2; } else if(喵.hasTag('2')){ attack_power[find(all_player_name,other.player.name)]=5; } else if(喵.hasTag('3')){ attack_power[find(all_player_name,other.player.name)]=10; } else if(喵.hasTag('4')){ attack_power[find(all_player_name,other.player.name)]=20; } world.say(other.player.name+'捡起了喵'); world.say('攻击力为'+attack_power[find(all_player_name,other.player.name)]); is_contact_喵[find(all_player_name,other.player.name)]=true; } }); 喵.onEntitySeparate(({other})=>{ is_contact_喵[find(all_player_name,other.player.name)]=false; }); });点赞0
评论