• 周年纪念勋章活动已圆满结束,如有已购买但仍未申请的用户,可以通过对应勋章的下载链接申请~
TMEssential - 新时代基础插件

资源 TMEssential - 新时代基础插件 v1.5.9

您好,我没什么经验,请问这个如何解决?
 
建议在卖出物品时显示持有数量,将会大大节省手动计算的时间,提高游戏体验。只需要修改如下代码片段:

1. 语言字符串
"shop.sell.form2.content" 的值改为 "§l§b详情信息:\n物品:§a{1}§b,\n特殊值:§a{2}§b,\n金额:§a{3}/一个§b,\n你的剩余金额:§a{4}§b,\n备注:{5},\n你的持有数量:§a{6}§b\nTips:请输入正数"

2. 计算
JavaScript:
nf.addLabel(AutoReplace(Tr(pl, "shop.sell.form2.content"),
                                selData.type, selData.aux, selData.money, getMoney(pl.realName), selData.remark));
改为:
JavaScript:
nf.addLabel(AutoReplace(Tr(pl, "shop.sell.form2.content"),
                                selData.type, selData.aux, selData.money, getMoney(pl.realName), selData.remark, hasNum));
并在其上方插入:
JavaScript:
// 获取持有数量
let hasNum = 0;
let AllItems = pl.getInventory().getAllItems();
AllItems.forEach((it) => {
    if (it.type == selData.type && it.aux == selData.aux) {
        hasNum += it.count;
    }
});

此外,建议把商店的类型名省略或者换个颜色,因为大多数情况下靠名字就能知道是分类还是商品了。
 
建议加入“返回上一页”的功能,只需添加语言字符串:

"shop.display.lastpage.group": "上一页"

并加入如下代码(改的地方有点多,就不一个个描述位置了,后面放了修改后的整个函数 QWQ):
对于ShopSellGui
JavaScript:
///////

function ShopSellGui(pl, commInfo, IndexStr, parentData=null)

///////

// 添加返回上一页按钮
if(parentData != null){
    nf.addButton(Tr(pl, "shop.display.lastpage.group"));
}

///////

let selInfo;
if(parentData != null){
    if(id == 0){
        ShopBuyGui(pl, parentData.Info, parentData.IndexStr, parentData.parentData);
        return;
    }
    selInfo = commInfo[id - 1];
}
else{
    selInfo = commInfo[id];
}

// 删去了 selInfo = commInfo[id]

///////

if (selInfo.type == "group") {
    ShopSellGui(pl, selInfo.data, `${IndexStr}=>${selInfo.name}`, {"Info":commInfo, "IndexStr":IndexStr, parentData:parentData});
    return;
}

///////
修改后的函数为:
代码:
/**
 * @param {Player} pl
 * @param {Array<{"name":string,"type":("group"|"exam"),"image":string,"data":([]|{"type":string,"aux":string,"remark":string,"money":number})}>} commInfo
 * @param {string} IndexStr
 * @param {object} parentData
 */
function ShopSellGui(pl, commInfo, IndexStr, parentData=null) {
    try {
        if (!isRightStore(commInfo, IndexStr)) {
            ST(pl, addLogo(Tr(pl, "shop.config.error")));
            return;
        }
        let nf = mc.newSimpleForm();
        nf.setTitle("§l§dShopSell");
        nf.setContent(Tr(pl, "shop.sell.form.content"));
        let LangTmp = Tr(pl, "shop.sell.form.buttons"),
            ExamD = Tr(pl, "shop.display.exam"),
            GroupD = Tr(pl, "shop.display.group");
       
        // 添加返回上一页按钮
        if(parentData != null){
            nf.addButton(Tr(pl, "shop.display.lastpage.group"));
        }
       
        commInfo.forEach((obj) => {
            nf.addButton(AutoReplace(LangTmp, String(obj.name), (obj.type == "exam" ? ExamD : GroupD)), (obj.image || ""));
        });
        pl.sendForm(nf, (pl, id) => {
            if (id == null) {
                ST(pl, addLogo(Tr(pl, "form.give.up")));
                return;
            }
           
            // 返回上一页
            let selInfo;
            if(parentData != null){
                if(id == 0){
                    ShopBuyGui(pl, parentData.Info, parentData.IndexStr, parentData.parentData);
                    return;
                }
                selInfo = commInfo[id - 1];
            }
            else{
                selInfo = commInfo[id];
            }
           
            // 删去了 selInfo = commInfo[id]

            if (selInfo.type == "group") {
                ShopSellGui(pl, selInfo.data, `${IndexStr}=>${selInfo.name}`, {"Info":commInfo, "IndexStr":IndexStr, parentData:parentData});
                return;
            } else if (selInfo.type == "exam") {
                let getMoney = Modules.getApi("getMoney");
                /**
                 * @type {(realName:string,val:number,type:?("join"|"init"|"set"),isTarn:?boolean,note:?string)=>(boolean|null)}
                 */
                let setMoney = Modules.getApi("setMoney");
                let selData = selInfo.data;
                let nf = mc.newCustomForm();
                nf.setTitle("§l§dShopSelling");

                // 获取持有数量
                let hasNum = 0;
                let AllItems = pl.getInventory().getAllItems();
                AllItems.forEach((it) => {
                    if (it.type == selData.type && it.aux == selData.aux) {
                        hasNum += it.count;
                    }
                });
               
                // 字符
                nf.addLabel(AutoReplace(Tr(pl, "shop.sell.form2.content"),
                    selData.type, selData.aux, selData.money, getMoney(pl.realName), selData.remark, hasNum));

                nf.addInput(Tr(pl, "shop.sell.form2.input.title"), "(+Number)");
                pl.sendForm(nf, (pl, args) => {
                    if (args == null) {
                        ST(pl, addLogo(Tr(pl, "form.give.up")));
                        return;
                    }
                    let num = args[1];
                    if (!(/(^[1-9]\d*$)/).test(num)) {
                        ST(pl, addLogo(Tr(pl, "shop.sell.form2.res.input.error")));
                        return;
                    } else { num = +num; }
                    let giveMoney = (selData.money * num);
                    let hasMoney = getMoney(pl.realName);
                    if (!Event_BeforeShopSellExample(pl.xuid, `${IndexStr}[${id}]=>${selInfo.name}`, selData, num)) {
                        return;
                    }
                    let cmdRes = TryClearItem(pl, selData.type, selData.aux, num);
                    if (cmdRes.success) {
                        if (!Event_ShopSellExample(pl.xuid, `${IndexStr}[${id}]=>${selInfo.name}`, selData, num)) {
                            return;
                        }
                        setMoney(pl.realName, (hasMoney + giveMoney), "set", false, "ShopSell");
                        ST(pl, addLogo(Tr(pl, "shop.sell.success")));
                        WriteUseLog("Shop-Sell", pl, `${IndexStr}[${id}]=>${selInfo.name}*${num}`);
                    } else {
                        ST(pl, addLogo(AutoReplace(Tr(pl, "shop.sell.fail.rea"), (cmdRes.output || "None"))));
                    }
                });
            }
        });
    } catch (e) {
        ErrorMsg(e);
        ST(pl, addLogo(Tr(pl, "shop.sell.error")));
    }
}

对于ShopBuyGui,修改是类似的:
代码:
/**
 * @param {Player} pl
 * @param {Array<{"name":string,"type":("group"|"exam"),"image":string,"data":([]|{"type":string,"aux":string,"remark":string,"money":number})}>} commInfo
 * @param {string} IndexStr
 * @param {object} parentData
 */
function ShopBuyGui(pl, commInfo, IndexStr, parentData=null) {
    try {
        if (!isRightStore(commInfo, IndexStr)) {
            ST(pl, addLogo(Tr(pl, "shop.config.error")));
            return;
        }
        let nf = mc.newSimpleForm();
        nf.setTitle("§l§dShopBuy");
        nf.setContent(Tr(pl, "shop.buy.form.content"));
        let LangTmp = Tr(pl, "shop.buy.form.buttons"),
            ExamD = Tr(pl, "shop.display.exam"),
            GroupD = Tr(pl, "shop.display.group");

        // 添加返回上一页按钮
        if(parentData != null){
            nf.addButton(Tr(pl, "shop.display.lastpage.group"));
        }

        commInfo.forEach((obj) => {
            nf.addButton(AutoReplace(LangTmp, String(obj.name), (obj.type == "exam" ? ExamD : GroupD)), (obj.image || ""));
        });
        pl.sendForm(nf, (pl, id) => {
            if (id == null) {
                ST(pl, addLogo(Tr(pl, "form.give.up")));
                return;
            }
           
            // 返回上一页
            let selInfo;
            if(parentData != null){
                if(id == 0){
                    ShopBuyGui(pl, parentData.Info, parentData.IndexStr, parentData.parentData);
                    return;
                }
                selInfo = commInfo[id - 1];
            }
            else{
                selInfo = commInfo[id];
            }

            if (selInfo.type == "group") {
                ShopBuyGui(pl, selInfo.data, `${IndexStr}=>${selInfo.name}`, {"Info":commInfo, "IndexStr":IndexStr, parentData:parentData});
                return;
            } else if (selInfo.type == "exam") {
                let getMoney = Modules.getApi("getMoney");
                /**
                 * @type {(realName:string,val:number,type:?("join"|"init"|"set"),isTarn:?boolean,note:?string)=>(boolean|null)}
                 */
                let setMoney = Modules.getApi("setMoney");
                let selData = selInfo.data;
                let nf = mc.newCustomForm();
                nf.setTitle("§l§dShopBuying");
                nf.addLabel(AutoReplace(Tr(pl, "shop.buy.form2.content"),
                    selData.type, selData.aux, selData.money, getMoney(pl.realName), selData.remark));
                nf.addInput(Tr(pl, "shop.buy.form2.input.title"), "(+Number)");
                pl.sendForm(nf, (pl, args) => {
                    if (args == null) {
                        ST(pl, addLogo(Tr(pl, "form.give.up")));
                        return;
                    }
                    let num = args[1];
                    if (!(/(^[1-9]\d*$)/).test(num)) {
                        ST(pl, addLogo(Tr(pl, "shop.buy.form2.res.input.error")));
                        return;
                    } else { num = +num; }
                    let needMoney = (selData.money * num);
                    let hasMoney = getMoney(pl.realName);
                    if (hasMoney < needMoney) {
                        ST(pl, addLogo(Tr(pl, "shop.buy.fail.money")));
                        return;
                    }
                    if (!Event_BeforeShopBuyExample(pl.xuid, `${IndexStr}[${id}]=>${selInfo.name}`, selData, num)) {
                        return;
                    }
                    let cmdRes = mc.runcmdEx(`give "${pl.realName}" ${selData.type} ${num} ${selData.aux}`);
                    if (cmdRes.success) {
                        if (!Event_ShopBuyExample(pl.xuid, `${IndexStr}[${id}]=>${selInfo.name}`, selData, num)) {
                            return;
                        }
                        setMoney(pl.realName, (hasMoney - needMoney), "set", false, "ShopBuy");
                        ST(pl, addLogo(Tr(pl, "shop.buy.success")));
                        WriteUseLog("Shop-Buy", pl, `${IndexStr}[${id}]=>${selInfo.name}*${num}`);
                    } else {
                        ST(pl, addLogo(AutoReplace(Tr(pl, "shop.buy.fail.rea"), (cmdRes.output || "None"))));
                    }
                });
            }
        });
    } catch (e) {
        ErrorMsg(e);
        ST(pl, addLogo(Tr(pl, "shop.buy.error")));
    }
}
 
当有人输入/money gui时会报错

22:34:48 INFO [Command] <dofu9487> /money gui
22:34:49 ERROR [LiteLoader] Fail in form callback!

22:34:49 ERROR [LiteLoader] script::Exception: cannot read property 'loss' of undefined
at <anonymous> (TMEssential.js:2077)
at <anonymous> (TMEssential.js:1105)


22:34:49 ERROR [LiteLoader] In Plugin: TMEssential.js
 
gui菜单怎么添加子任务栏,加了任务插件,想通过GUI菜单直接找到
 
有玩家反馈说在使用传送功能(返回死亡点、tpa、home)时会自动把玩家抬升三格,在区块未加载时会把玩家卡在墙里面闷死。希望作者可以修复一下,谢谢。
 
游戏内使用编辑公告的删除功能保存后,游戏聊天框显示成功但公告并未改变
控制台输出内容
ERROR [LiteLoader] Fail in form callback!

11:17:15 ERROR [LiteLoader] script::Exception: 'pl2' is not defined
at <anonymous> (TMEssential.js:4206)
at <anonymous> (TMEssential.js:495)
at <anonymous> (TMEssential.js:4208)


11:17:15 ERROR [LiteLoader] In Plugin: TMEssential.js
 
Screenshot_2023-08-20-13-29-53-561_com.microsoft.emmx-edit.jpg
这里启用了计分板经济但是在游戏内无法使用经济功能,注册指令冲突,希望能llmoney和score共存双经济
 

在线会员

  • DaBin
  • Green
  • 午夜_Midnight
  • RT_XinRain_mc
  • lzy2633
  • chengyanZz
  • liubo520
  • 慕晚
  • 离川
  • luchen5066
  • Sh1roCu
  • SpikedGull1871
  • Burnight
  • 界限
  • littleduan
  • lucksheep
  • 2871275669
  • white0228
  • 爱莉希雅qwq
  • sssjiu
...和 63 更多。
后退
顶部 底部