
Lv.1
()
签名:写代码()()() 玩起床()()() 什(
在 【教程】背包教程(自带SQL) 中回复
constInitCap = 10; db.sql`CREATETABLEIFNOTEXISTSbag( idCHAR(16)NOTNULL, recordTEXTNOTNULL )` world.onPlayerJoin(async ({ entity }) => {
functioninit(){
entity.bag = newBag(en
tity, {}, InitCap);
} if (entity.player.userKey) {
constrows = awaitdb.sql`SELECT*FROMbagWHEREid=${entity.player.userKey}`; if (rows && !rows.length) {
init(); db.sql`IN
ERTINTObagVALUES(${entity.player.userKey},${getRecord.call(entity)})`;
} else {
constnow = JSON.parse(rows[0].record); now entity.bag = newBag(entity, now.thing, now.capacity);
}
} elseinit();
}) world.onPlayerLeave(({ entity }) => { entity.bag.save(); }) classBag{
constructor(owner = newBox3Entity, thing = {}, capacity = 0){
this.owner = owner; this.thin
g = thing; this.capacity = capacity; this.now = 0; for (constiofObject.keys(this.thing)) {
this.now += this.thing[i]; this.saveObject = {
thing: this.thing, capacity: this.cap
acity
}
} save(){
if (!this.owner.player.userKey) return; db.sql`UPDATEbagSETrecord=${JSON.stringify(this.saveObject)}WHEREid=${this.owner.player.userKey}`;
} add(item = '', num = 1){
if (this.now + num > this.capacity) returnundefined; undefined if (!!this.thing[item]) {
this.thing[item] += num; this.saveObject.thing[item] += num
;
} else { this.thing[item] = num; this.saveObject.thing[item] = num; } this.now += num; returnthis.thing[item];
} del(item = '', num = 1){
if (!this.thing[item]) returnNaN;
if (this.thing[item] < num) returnundef
ined; undefuned this.thing[item] -= num; this.saveObject.thing[item] -= num; this.now -= num; returnthis.thing[item];
} setCap(cap = 0){
if (cap < this.now) returnundefined;
this.capacity = cap; returnthis.capacity;
} asyncshow(){
varop = []; for (constiofObject.keys(this.thing)) { op.push(`${i}×${this.thing[i]}`); }
constp = awaitthis.owner.player.dialog({ type: Box3DialogType.SELECT, title: '背包', content: '以下是你的背包', options: op, }); returnthis.thing[Object.keys(t
his.thing)[op.indexOf(p)]];
}
}2022-06-02T20:21:01 点赞:0
在 岛三?创作平台×!摸鱼平台√! 中回复
笑死,能不能仔细想想再发贴,拿火山哥哥来说,人家就和吉吉喵合个作,做个地图走人,你觉得他们会和我们一样一直在代码岛里?
2022-06-10T19:58:57 点赞:4
在 【神岛】把这个乱码放到地图,会怎样? 中回复
真的实用!!!!!!我把这些代码放代码里,一运行,就突然发现地图非常流畅,一点都不卡!再也没有人太多导致很卡的烦恼了!
2022-06-18T12:33:24 点赞:1