用户:Alex79查看:3 回复:17 评论:3 创建时间:2020-05-12T18:28:05
前天我发了一篇帖子,叫做 【Box3超级干货帖】输入玩家姓名将其关监狱功能怎么做!,很多萌新都是顶的,我也觉得我这样写没毛病,结果今天我看到了一个大佬发一篇帖子,帖子链接:https://shequ.codemao.cn/community/281913
这篇帖子详细的讲解了怎么做在聊天区执行代码的方法,看完后,我发现,这个输入玩家姓名将其关监狱功能是有简化空间的,下面我教你们怎么简化,首先需要这些代码
world.onChat(({entity,message})=>{
if(!entity||entity.player.name ==='管喵名称'){
if(message.indexOf('$')==0){
try{
world.say('->'+eval(message.slice(1)));
}catch(err){
world.say('Error:'+err);
}
}}
});
这段代码的意思那位大佬在帖子里详细地讲解了,我就不讲了,这段代码实现的功能就是游戏运行后管喵可以在聊天区执行代码。
然后,咱们定义一个函数,叫做prison,并且传进去一个参数player。
function prision(player){
}
然后就非常简单了,循环遍历玩家,判断名字,执行操作。对了。
world.querySelectorAll('player').forEach((a) => {
if (a.player.name == player) {
a.position.set(x,y,z);
}})
这个x,y,z就填监狱的坐标就行了。
完整代码:
function prision(player){
world.querySelectorAll('player').forEach((a) => {
if (a.player.name == player) {
a.position.set(x,y,z);
}})
}
然后运行程序在评论区打上$再敲prision("要被关的玩家")就OK了
看!就是简化的这么简单了!!!
亿只懒Inkworld.onChat(({entity,message})=>{
if(!entity||entity.player.name ==='管理员名称'){
if(message.indexOf('$')==0){
try{
world.say('->'+eval(message.slice(1)));
}catch(err){
world.say('Error:'+err);
}
}}
});
function prision(player){
world.querySelectorAll('player').forEach((a) => {
if (a.player.name == player) {
a.position.set(x,y,z);
}})
}
点赞0
评论
对了,你后面的应该这样:
function prision(player){
world.querySelectorAll('player').forEach((a) => {
if (a.player.name == player) {
a.position.set(x,y,z);
};
});
};点赞0
评论