会员登录

自动登录   |    忘记密码 新会员注册

SimpleAddItems-用于级别列表和容器的zEdit脚本

作者:tavernfly
发布:LUOHUISHU98
发布日期:2019-11-24 19:14:38
更新时间:2019-11-24 19:14:38
头像
1461
715 人收藏
2698 次下载
7714 次浏览
1.0
上古卷轴5:重置版
本地下载 高速下载 需要优先下载下载器,50%提速

我需要一个像这样的小脚本,在任何地方都找不到,所以我做到了。


您只需通过按住Ctrl键并单击树视图(zEdit的左面板)中的记录节点,然后选择它们即可选择要添加的项目(ARMO,WEAP等)和目标级别的列表或容器(LVLI或CONT)。单击->自动化,然后运行此脚本!


想要将分级列表添加到分级列表中吗?没问题!选择多个LVLI,然后在运行脚本时在脚本标头中写入目标LVLI的FormID。 (直到我找到一种解决方法来绕过此额外步骤。)


安装:

将“ SimpleAddItems.js”放入您的zEdit \ scripts文件夹。


说明:

有关注释的说明,请参见脚本顶部。


错误报告:

请提供遇到错误时尝试执行的操作类型:“将项目和分级列表添加到单个分级列表”,“将项目和分级列表添加到单个分级列表”或“将项目和分级列表添加到一个或多个分级列表中”更多的容器。”确保您正确地遵循注释说明中概述的步骤。如果可能,请包括来自zEdit记录器的[WARN] / [ERROR]消息。


改进之处:

我想改善这个脚本。如果您有想法,我会全力以赴。我是自学Java脚本的人,也是zEdit的新手,因此,我确定有很大的优化空间。


学习制作自己的脚本:

我非常感谢Mator创建zEdit,并在尝试编写此脚本时回答了我的愚蠢问题。如果您有任何JavaScript经验(甚至可能没有),也可以这样做。 zEdit文档非常有用。尤其请参见“开发”>“ API”>“ xelib”和“脚本API”。 Modding Tools Discord对我和我的愚蠢问题都很客气。


剧本:

对于那些不愿下载或想要浏览我的意大利面条代码的用户,此处完整介绍。

</ s> </ s> </ s>


/ * SimpleAddItems.js v1.0-一个zEdit脚本,用于将项目添加到已分级列表和容器。由小蝇(Tavernfly),由麦特(Mator)大力牵制。 * /


//---HEADER---用户输入在这里!


//设置计数。这将适用于添加的所有项目。默认值= 1

让计数='1';


//设置级别。这仅适用于添加到“已列出的列表”中的所有项目。默认值= 1

让等级='1';


//使用分级列表FormID手动设置目标。必须是有效的8位十六进制FormID!

//默认值:保留空白以将所选项目添加到一个选定的已分级列表中,或将所有选定项目和已分级列表添加到所有选定容器中

让destination ='';


//在当前zEdit会话中,使用2位十六进制加载顺序ID手动设置目标文件。

//仅当在上面手动设置了目的地并且您要在特定文件中编辑先前加载的,丢失冲突的记录时才需要。

//默认值:保留空白,以修改最后加载的,赢得冲突的记录。

let file ='';


//---说明---


//将商品添加到单个列表中:


// 1.选择所有所需的项目,类型为ALCH,AMMO,APPA,ARMO,BOOK,INGR,KEYM,LIGH,MISC,SCRL,SLGM,WEAP

// CTRL +单击/ Shift +单击以选择多个项目

// 2.同时使用CTRL +单击选择“一个已分级列表”

// 3.右键单击->自动化,SimpleAddItems.js

// 4.为脚本标题中的所有项目设置所需的计数和级别。默认值为1。无论您设置什么数字,都将其括在单引号中以使其成为字符串。

// 5.在脚本标题中,将目标保留为空白/空单引号。

// 6.运行脚本。


//将商品和清单列表添加到单个清单中:


// 1.选择所有所需的项目,类型为ALCH,AMMO,APPA,ARMO,BOOK,INGR,KEYM,LIGH,LVLI,MISC,SCRL,SLGM,WEAP

// CTRL +单击/ Shift +单击以选择多个项目

// 2.右键单击->自动化,SimpleAddItems.js

// 4.为脚本标题中的所有项目设置所需的计数和级别。默认值为1。无论您设置什么数字,都将其括在单引号中以使其成为字符串。

// 5.用目标级别列表的8位十六进制FormID设置目标。确保将其用单引号引起来。

//此FormID可以在zEdit树视图的最左列中找到。

// 6.可选:在当前zEdit会话中使用2位十六进制加载顺序ID设置文件。

//这是如果您要在特定文件中编辑较早加载的丢失冲突的记录。

// 7.运行脚本。


//将商品和水平列表添加到一个或多个容器中:


// 1.选择所有所需的项目,类型为ALCH,AMMO,APPA,ARMO,BOOK,INGR,KEYM,LIGH,LVLI,MISC,SCRL,SLGM,WEAP

// CTRL +单击/ Shift +单击以选择多个项目

// 2.使用CTRL +单击并选择所有需要放入项目的容器

// 3.右键单击->自动化,SimpleAddItems.js

// 4.为脚本标题中的所有项目设置所需的计数。默认值为1。无论您设置什么数字,都将其括在单引号中以使其成为字符串。

// 5.在脚本标题中,将目标保留为空白/空单引号。

// 6.运行脚本。


/ *---开始脚本---* /

//获取选定的记录并按签名分组

让列表= zedit.GetSelectedRecords('LVLI');

让容器= zedit.GetSelectedRecords('CONT');

let items = zedit.GetSelectedRecords('ALCH');

items = items.concat(zedit.GetSelectedRecords('AMMO'));

items = items.concat(zedit.GetSelectedRecords('APPA'));

items = items.concat(zedit.GetSelectedRecords('ARMO'));

items = items.concat(zedit.GetSelectedRecords('BOOK'));

items = items.concat(zedit.GetSelectedRecords('INGR'));

items = items.concat(zedit.GetSelectedRecords('KEYM'));

items = items.concat(zedit.GetSelectedRecords('LIGH'));

items = items.concat(zedit.GetSelectedRecords('MISC'));

items = items.concat(zedit.GetSelectedRecords('SCRL'));

items = items.concat(zedit.GetSelectedRecords('SLGM'));

items = items.concat(zedit.GetSelectedRecords('WEAP'));


//清理用户输入

if(typeof count!=='字符串'|| typeof级别!=='字符串'|| typeof目标!=='字符串'|| typeof文件!=='字符串'){

zedit.warn('SimpleAddItems.js:用户输入错误!脚本标头中定义的所有变量都必须为字符串!如果您不知道如何解决此问题,请重新安装此脚本!...脚本异常终止');

返回;

}


count = count.replace(/ [^ 0-9] + / g,'');

if(count <1 || count> 34463){

zedit.warn('SimpleAddItems.js:无效计数。必须在脚本头中将count设置为有效数字。默认值:1 ... ...脚本异常终止');

返回;

}

级别= level.replace(/ [^ 0-9] + / g,'');

if(level <1 || level> 999){

zedit.warn('SimpleAddItems.js:无效级别。必须在脚本头中将级别设置为有效数字。默认值:1. ...脚本异常终止');

返回;

}


//将商品添加到列表中

//如果未选择容器

如果(containers.length <1){

//如果设置了手动目的地

如果(目的地){

//清理目标输入

destination = destination.replace(/ [^ A-Fa-f0-9] + / g,'');

//不是8位十六进制?抛出异常

如果(destination.length!== 8){

zedit.warn('SimpleAddItems.js:无效的目的地!必须为8位十六进制FormID,或者为用于自动处理的空字符串。...脚本已中止');

返回;

}

//如果设置了目标文件

如果(文件){

//清理文件输入

文件= file.replace(/ [^ A-Fa-f0-9] + / g,'');

//不是2位数的十六进制?抛出异常

如果(file.length!== 2){

zedit.warn('SimpleAddItems.js:无效的目标文件。必须是当前zEdit会话中的两位数十六进制加载顺序ID,或者留空以修改最后加载的,赢得冲突的记录。...脚本中止');

返回;

}

//将文件从十六进制转换为十进制并进行查找

文件= xelib.FileByLoadOrder(parseInt(file,16));

//从文件中获取目标

destination = xelib.GetElement(file,destination);

//未设置目标FILE,而是获取记录的最后加载实例

}其他{

//将目的地从十六进制转换为十进制并进行查找

destination = xelib.GetRecord(0,parseInt(destination,16));

//获取目的地的最后加载的,屡获殊荣的记录

destination = xelib.GetWinningOverride(destination);

}

//确保目的地是已分级列表

如果(xelib.Signature(destination)=='LVLI'){

//如果选择了目的地,则删除重复项,因此我们不会尝试向其自身添加列表

让重复项= xelib.GetOverrides(destination);

repeats.forEach(duplicate => {

列表= list.filter(i => i!==重复);

});

列表= list.filter(i => i!== xelib.GetMasterRecord(destination));

//将所选项目和已分级列表合并到一个数组中

items = items.concat(列表);

//目的地未分级列表?抛出异常

}其他{

zedit.warn('SimpleAddItems.js:无效的目标!'+ xelib.EditorID(destination)+'['+ xelib.Signature(destination)+':'+ xelib.GetHexFormID(destination)+']不是已分级列表!...脚本中止了');

返回;

}

//没有手动目的地,并且选择了多个列表?抛出异常

} else if(lists.length> 1){

zedit.warn('SimpleAddItems.js:选择多个没有目标的列表!要将列表添加到列表,请在脚本头中手动设置一个目标。要向容器添加列表,请至少选择一个容器。...脚本已中止');

返回;

//没有手动目的地,也没有选择级别列表?抛出异常

}否则,如果(lists.length <1){

zedit.warn('SimpleAddItems.js:无目的地!选择一个或多个容器,或一个分级列表,或在脚本头中手动设置目的地。...脚本中止');

返回;

//自动目的地:选择了一个列表

}其他{

destination =列表[0];

}

//分级列表是否会超过255个条目?抛出异常

if(xelib.GetElements(destination,'Leveled List Entries')。length + items.length> 255){

zedit.warn('SimpleAddItems.js:预测到溢出!在级别列表'+ xelib.EditorID(destination)+'中不能超过255个项目[LVLI:'+ xelib.GetHexFormID(destination)+'] ...脚本已终止') ;

返回;

//很方便,将项目添加到手动或自动目标位置的已分级列表中

}其他{

items.forEach(item => {

xelib.AddLeveledEntry(目的地,xelib.EditorID(item),级别||'1',计数||'1');

});

zedit.info('SimpleAddItems.js:'+ items.length +'项目已添加到'+ xelib.EditorID(destination)+'[LVLI:'+ xelib.GetHexFormID(destination)+']'));

}

//选择容器并设置手动目标位置?抛出异常

} else if(目的地){

zedit.warn('SimpleAddItems.js:无法将容器添加到已分级列表中!要么删除脚本头中的目标位置,要么取消选择所有容器!...脚本异常中止');

返回;

//将项目添加到容器

}其他{

//将所选项目和已分级列表合并到一个数组中

items = items.concat(列表);

//遍历容器

container.forEach(container => {

//这个容器会超过255个条目吗?跳过它,并警告用户它已被跳过

如果(xelib.GetElements(container,'Items')。length + items.length> 255){

zedit.warn('SimpleAddItems.js:预测到溢出!不能超过255个项目!跳过容器'+ xelib.EditorID(container)+'[CONT:'+ xelib.GetHexFormID(container)+']'));

//将项目添加到此容器

}其他{

items.forEach(item => {

xelib.AddItem(容器,xelib.EditorID(item),count ||'1');

});

zedit.info('SimpleAddItems.js:'+ items.length +'项目已添加到'+ xelib.EditorID(container)+'[CONT:'+ xelib.GetHexFormID(container)+']');

}

});

}

//完成

zedit.info('SimpleAddItems.js:脚本完成!')

返回;

————————————————————————————————————————————

I needed a little script like this and couldn't find one anywhere, so I made this.

You just select the items you want to add (ARMO, WEAP, etc.) and the destination leveled list or container (LVLI or CONT) by CTRL+clicking their record nodes in the tree view (left panel of zEdit), and then right click -> Automate, and run this script!

Wanna add leveled lists to leveled lists? No problem! Select multiple LVLI, and write the FormID of the destination LVLI in the script header when you run the script. (Until I find a workaround to bypass this extra step.)

INSTALLATION:
Place "SimpleAddItems.js" into your zEdit\scripts folder.

INSTRUCTIONS:
See top of script for commented instructions.

BUG REPORTS:
Please include what type of operation you were trying to execute when you encountered the bug: "Add items to a single leveled list," "Add items and leveled lists to a single leveled list," or "Add items and leveled lists to one or more containers." Make sure you followed the steps outlined in commented instructions correctly. Include [WARN] / [ERROR] messages from zEdit logger if possible.

IMPROVEMENTS:
I would like to improve this script. If you have ideas, I'm all ears. I'm self-taught in javascript, and a novice when it comes to zEdit, so I'm sure there's plenty of room for optimization.

LEARN TO MAKE YOUR OWN SCRIPT:
I'm extremely grateful to Mator for creating zEdit, and for answering my stupid questions while I tried to write this script. If you have any experience in javascript at all (and probably even if you don't), you can do this. The zEdit Documentation was super helpful. See especially Development > APIs > "xelib" and "Scripting API." The Modding Tools Discord were kind and gracious to me and my dumb-dumb questions.

THE SCRIPT:
Presented here in its entirety for those who can't be bothered to download or want to gawk at my spaghetti code.


/* SimpleAddItems.js v1.0 - A zEdit script to add items to leveled lists and containers. By tavernfly, with extensive hand-holding from Mator. */

//- - - HEADER - - -user input goes here!

// Set the count. This will apply to ALL ITEMS added. Default = 1
let count = '1';

// Set the level. This will apply to ALL ITEMS added to LEVELED LISTS ONLY. Default = 1
let level = '1';

// Set destination manually with a leveled list FormID. Must be a valid, 8-digit hexadecimal FormID!
// Default: Leave blank to add selected items to ONE selected leveled list, or to add all selected items and leveled lists to all selected containers
let destination = '';

// Set destination file manually with 2-digit hexadecimal load order ID within current zEdit session.
// Only needed if destination is set manually above and you want to edit an earlier-loaded, conflict-losing record in a specific file.
// Default: Leave blank for last-loaded, conflict-winning record to be modified.
let file = '';

// - - - INSTRUCTIONS - - -

// TO ADD ITEMS TO A SINGLE LEVELED LIST:

// 1. Select all desired items of type ALCH, AMMO, APPA, ARMO, BOOK, INGR, KEYM, LIGH, MISC, SCRL, SLGM, WEAP
// CTRL + Click / Shift + Click to select multiple items
// 2. Also select ONE Leveled List, using CTRL + Click
// 3. Right-click -> Automate, SimpleAddItems.js
// 4. Set desired count and level for all items in script header. Default is 1. Whatever number you set, surround it in single-quotes to make it a string.
// 5. Leave destination blank / empty single-quotes in script header.
// 6. Run script.

// TO ADD ITEMS AND LEVELED LISTS TO A SINGLE LEVELED LIST:

// 1. Select all desired items of type ALCH, AMMO, APPA, ARMO, BOOK, INGR, KEYM, LIGH, LVLI, MISC, SCRL, SLGM, WEAP
// CTRL + Click / Shift + Click to select multiple items
// 2. Right-click -> Automate, SimpleAddItems.js
// 4. Set desired count and level for all items in script header. Default is 1. Whatever number you set, surround it in single-quotes to make it a string.
// 5. Set destination with 8-digit hexadecimal FormID of target leveled list. Make sure it is surrounded in single-quotes.
// This FormID can be found in the left-most column of the zEdit tree view.
// 6. Optional: Set file with 2-digit hexadecimal load order ID within current zEdit session.
// This is if you want to edit an earlier-loaded, conflict-losing record in a specific file.
// 7. Run script.

// TO ADD ITEMS AND LEVELED LISTS TO ONE OR MORE CONTAINERS:

// 1. Select all desired items of type ALCH, AMMO, APPA, ARMO, BOOK, INGR, KEYM, LIGH, LVLI, MISC, SCRL, SLGM, WEAP
// CTRL + Click / Shift + Click to select multiple items
// 2. Also select all desired containers to put items into, using CTRL + Click
// 3. Right-click -> Automate, SimpleAddItems.js
// 4. Set desired count for all items in script header. Default is 1. Whatever number you set, surround it in single-quotes to make it a string.
// 5. Leave destination blank / empty single-quotes in script header.
// 6. Run script.

/* - - - BEGIN SCRIPT - - - */

// Get selected records and group them by signature
let lists = zedit.GetSelectedRecords('LVLI');
let containers = zedit.GetSelectedRecords('CONT');
let items = zedit.GetSelectedRecords('ALCH');
items = items.concat(zedit.GetSelectedRecords('AMMO'));
items = items.concat(zedit.GetSelectedRecords('APPA'));
items = items.concat(zedit.GetSelectedRecords('ARMO'));
items = items.concat(zedit.GetSelectedRecords('BOOK'));
items = items.concat(zedit.GetSelectedRecords('INGR'));
items = items.concat(zedit.GetSelectedRecords('KEYM'));
items = items.concat(zedit.GetSelectedRecords('LIGH'));
items = items.concat(zedit.GetSelectedRecords('MISC'));
items = items.concat(zedit.GetSelectedRecords('SCRL'));
items = items.concat(zedit.GetSelectedRecords('SLGM'));
items = items.concat(zedit.GetSelectedRecords('WEAP'));

// Sanitize user input
if (typeof count !== 'string' || typeof level !== 'string' || typeof destination !== 'string' || typeof file !== 'string') {
zedit.warn('SimpleAddItems.js: User input error! All variables defined in script header must be strings! If you do not know how to fix this, reinstall this script! ...Script aborted'); 
return;
}

count = count.replace(/[^0-9]+/g,'');
if (count < 1 || count > 34463) {
zedit.warn('SimpleAddItems.js: Invalid count. Must set count to a valid number in script header. Default: 1. ...Script aborted');
return;
}
level = level.replace(/[^0-9]+/g,'');
if (level < 1 || level > 999) {
zedit.warn('SimpleAddItems.js: Invalid level. Must set level to a valid number in script header. Default: 1. ...Script aborted');
return;
}

// ADD ITEMS TO LEVELED LIST
// if no containers selected
if (containers.length < 1) {
// if manual destination is set
if (destination) {
// sanitize input for destination
destination = destination.replace(/[^A-Fa-f0-9]+/g,'');
// not 8-digit hex? throw exception
if (destination.length !== 8) {
zedit.warn('SimpleAddItems.js: Invalid destination! Must be an 8-digit hexadecimal FormID, or empty string for automatic processing. ...Script aborted');
return;
}
// if destination FILE is set
if (file) {
// sanitize input for file
file = file.replace(/[^A-Fa-f0-9]+/g,'');
// not a 2-digit hex? throw exception
if (file.length !== 2) {
zedit.warn('SimpleAddItems.js: Invalid destination FILE. Must be a 2-digit hexadecimal load order ID within current zEdit session, or leave blank to modify last-loaded, conflict-winning record. ...Script aborted');
return;
}
// convert file from hex to decimal and do lookup
file = xelib.FileByLoadOrder(parseInt(file,16));
// get destination from within file
destination = xelib.GetElement(file,destination);
// no destination FILE set, get last loaded instance of record instead
} else {
// convert destination from hex to decimal and do lookup
destination = xelib.GetRecord(0,parseInt(destination,16));
// get last-loaded, conflict-winning record for destination
destination = xelib.GetWinningOverride(destination);
}
// make sure destination is a leveled list
if (xelib.Signature(destination) == 'LVLI') {
// remove duplicates in case destination is in selection, so we don't try to add a list to itself
let duplicates = xelib.GetOverrides(destination);
duplicates.forEach(duplicate => {
lists = lists.filter(i => i !== duplicate);
});
lists = lists.filter(i => i !== xelib.GetMasterRecord(destination));
// consolidate selected items and leveled lists into one array
items = items.concat(lists);
// destination not leveled list? throw exception
} else {
zedit.warn('SimpleAddItems.js: Invalid destination! '+xelib.EditorID(destination)+' ['+xelib.Signature(destination)+': '+xelib.GetHexFormID(destination)+'] is not a leveled list! ...Script aborted');
return;
}
// no manual destination and more than one leveled list selected? throw exception
} else if (lists.length > 1) {
zedit.warn('SimpleAddItems.js: Multiple leveled lists selected with no destination! To add lists to a list, set a destination manually in the script header. To add lists to containers, select at least one container. ...Script aborted');
return;
// no manual destination and no leveled list selected? throw exception
} else if (lists.length < 1) {
zedit.warn('SimpleAddItems.js: No destination! Select one or more containers, or one leveled list, or set destination manually in script header. ...Script aborted');
return;
// automatic destination: one leveled list selected
} else {
destination = lists[0];
}
// is the leveled list gonna exceed 255 entries? throw exception
if (xelib.GetElements(destination, 'Leveled List Entries').length+items.length > 255) {
zedit.warn('SimpleAddItems.js: Overflow predicted! Cannot exceed 255 items in leveled list '+xelib.EditorID(destination)+' [LVLI: '+xelib.GetHexFormID(destination)+'] ...Script aborted');
return;
// good to go, add items to the leveled list at manual or automatic destination
} else {
items.forEach(item => {
xelib.AddLeveledEntry(destination, xelib.EditorID(item), level||'1', count||'1');
});
zedit.info('SimpleAddItems.js: '+items.length+' items added to '+xelib.EditorID(destination)+' [LVLI: '+xelib.GetHexFormID(destination)+']');
}
// containers selected and manual destination set? throw exception
} else if (destination) {
zedit.warn('SimpleAddItems.js: Cannot add containers to leveled list! Either remove destination in script header or deselect all containers! ...Script aborted');
return;
// ADD ITEMS TO CONTAINERS
} else {
// consolidate selected items and leveled lists into one array
items = items.concat(lists);
// iterate through containers
containers.forEach(container => {
// is this container gonna exceed 255 entries? skip it, and warn the user that it was skipped
if (xelib.GetElements(container, 'Items').length+items.length > 255) {
zedit.warn('SimpleAddItems.js: Overflow predicted! Cannot exceed 255 items! Skipping container '+xelib.EditorID(container)+' [CONT: '+xelib.GetHexFormID(container)+']');
// add items to this container
} else {
items.forEach(item => {
xelib.AddItem(container, xelib.EditorID(item), count||'1');
});
zedit.info('SimpleAddItems.js: '+items.length+' items added to '+xelib.EditorID(container)+' [CONT: '+xelib.GetHexFormID(container)+']');
}
});
}
// done
zedit.info('SimpleAddItems.js: Script complete!')
return;

原贴地址
1.版本号: 1.0   更新时间: 2019-11-24 19:40:09

选择快速回复内容:
  • 感谢
  • 支持
  • 疑问
  • 卖萌
  • 关心
  • 傲娇
评论


    ta的精品
    logo

    SimpleAddItems-用于级别列表和容器的zEdit脚本


    Mod大小:2.64 KB
    上传时间:2019-11-24 19:14:39

    Mod简介:

    暂无更多介绍


    选择快速回复类型:
    • 感谢
    • 支持
    • 疑问
    • 卖萌
    • 关心
    • 傲娇
    回复

    closeAD