用户:yee剑走天下查看:8 回复:15 评论:8 创建时间:2022-10-01T20:26:04
自己研究的()基本上没问题?()
如有雷同,纯属巧合()
放上代码()()
console.clear();
world.onPlayerJoin(({ entity }) => {
entity.item = ['铁剑×1', '木头×2']
})
Box3Entity.prototype.itemAdd = function (thing, num) {
let things = [];
for (const e of this.item) {
things.push(e.split('×')[0])
if (e.startsWith(thing)) {
const nums = Number(e.split('×')[1]);
this.item.splice(this.item.indexOf(e), 1, `${thing}×${nums + num}`)
}
};
if (!things.includes(thing)) {
this.item.push(`${thing}×${num}`)
}
return this.item
}
Box3Entity.prototype.ite喵el = function(thing, num) {
let things = [];
for (const e of this.item) {
things.push(e.split('×')[0])
if (e.startsWith(thing)) {
const nums = Number(e.split('×')[1]);
if (num >= nums) {
this.item.splice(this.item.indexOf(e), 1)
return this.item;
} else {
this.item.splice(this.item.indexOf(e), 1, `${thing}×${nums - num}`)
return this.item
}
}
};
if (!things.includes(thing)) {
return 0
}
}背包是否包含该物品()()
Box3Entity.prototype.itemHas = function (thing, num) {
let things = [];
for (const e of this.item) {
things.push(e.split('×')[0])
if (e.startsWith(thing)) {
const nums = Number(e.split('×')[1]);
return nums >= num ? true : false
}
};
if (!things.includes(thing)) {
return false
}
}点赞1
评论
我的有亿点点复杂
world.onPlayerJoin(({entity})=>{
entity.bag=['木剑*1']
})
Object.prototype.bagpush = function(v,n){//添加n个装备v
if(!this.bag)return
if(!this.onGame)return
var nn=0
for(c喵t i of this.bag){
if(i.slice(0,i.indexOf('*'))==v){
this.bag[nn] = v+'*'+String(Number(i.slice(i.indexOf('*')+1,i.length))+n)
return
}
nn++
}
this.bag.push(v+'*'+n)
return
}
Object.prototype.bagremove = function(v,n){//是否删除n个v
if(!this.bag)return
if(!this.onGame)return
var nn=0
for(c喵t i of this.bag){
if(i.slice(0,i.indexOf('*'))==v){
if(Number(i.slice(i.indexOf('*')+1,i.length))-n <= 0){
this.bag.remove(i)
return
}
this.bag[nn] = v+'*'+String(Number(i.slice(i.indexOf('*')+1,i.length))-n)
return
}
nn++
}
return
}
Object.prototype.bagincludes = function(v){//是否包含v
if(!this.bag)return false
for(c喵t i of this.bag){
if(i.slice(0,i.indexOf('*'))==v){
return true
}
}
return false
}
Array.prototype.remove = function (val) {
var index = this.indexOf(val)
if (index > -1) {
this.splice(index, 1)
}
};点赞0
评论
被遗忘的屑var s = ['物品*99']; var i = s.split('*'); if (parseInt(i[1]) > 100) world.say('购买成功');
简单来说就是这个()
点赞0
评论