【Lv:3】
nf.addLabel(AutoReplace(Tr(pl, "shop.sell.form2.content"),
selData.type, selData.aux, selData.money, getMoney(pl.realName), selData.remark));
nf.addLabel(AutoReplace(Tr(pl, "shop.sell.form2.content"),
selData.type, selData.aux, selData.money, getMoney(pl.realName), selData.remark, hasNum));
// 获取持有数量
let hasNum = 0;
let AllItems = pl.getInventory().getAllItems();
AllItems.forEach((it) => {
if (it.type == selData.type && it.aux == selData.aux) {
hasNum += it.count;
}
});
///////
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")));
}
}
/**
* @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")));
}
}
更改:
1.添加语言项:
shop.sell.fail.count.not.enough,
shop.form.back.last.page
2.修改语言项:
shop.sell.form2.content
【Lv:3】
【Lv:3】
和LLmoney的指令冲突导致money指令无法注册怎么办
(!!!API变动)修复&优化
1.修复经济系统选择玩家时不选择玩家直接提交出现错误
2.规定一些公共变量
3.优化setMoney函数,将type值的join变为sync,为sync时,无法拦截此次事件
4.更改LLMoney同步方式
【Lv:2】
【Lv:1】
1
【Lv:1】
1
【Lv:1】
1