Jump to content

Toss your semi-useful WeiDU macros here

Recommended Posts

On 8/26/2019 at 12:41 AM, K4thos said:

I remember reading about a function/macro that can assign spells to CLAB files and append new rows if needed (only if there are no free slot in the column left). I was sure that I will find it in this topic but can't see it mentioned in the first post. If anyone knows where to get this function please post a link.

Not sure there's a lot of value in this, since CLAB files are functionally unlimited, there is no benefit to inserting something into existing rows, versus just APPENDing a new row.  In fact there is actually a (minor) advantage in APPENDING, since you can use the first entry to denote what is being added in the new row.  (E.g. when I apply an effect to cleric kits that disables Turn Undead, the first entry in that CLAB row is "NO_TURN" so it is easy to read the CLAB table later and see which spell does that.)

Of course it's always possible I'm missing something, or not considering some use case!

Meantime, I have adapted K4thos fix missing 2da entries function to specifically address missing IDS values in kitlist.2da.  The original function doesn't work great here, since the default filler in that entry is not an integer, and even if it was it would not be "correct" (for the very limited definition of "correct" here).  This function sets the IDS entry to (0x4000 + (kitlist row # - 12)).  This should result in "correct" IDS numbers for any mod-added kits or kits that come after the mages and barbarian.  (E.g. when applied to a kitlist.2da with a missing GRIZZLY_BEAR entry, it sets it to 0x00004027.)

This does NOT add anything to KIT.IDS - I forget what rules would apply.  The use case is limited to creating a well-formed kitlist.2da table for mods (like mine) that perform a lot of reads of that table for various purposes.



DEFINE_ACTION_FUNCTION fix_kitlist_missing_ids BEGIN
	COPY_EXISTING ~kitlist.2da~ ~override~
		PATCH_IF ~%entry%~ STR_EQ ~~ BEGIN
			READ_2DA_ENTRY 1 0 1 "entry"
		COUNT_2DA_COLS "cols"
		SET cnt = 0
			PATCH_IF cnt >= 3 BEGIN
					COUNT_REGEXP_INSTANCES ~ +~ num_matches
					WHILE (num_matches < (cols - 1)) BEGIN
						SET num_matches = num_matches + 1
				SET cnt = cnt + 1
		END ~%MATCH1%~
	COPY_EXISTING ~kitlist.2da~ ~override~
		COUNT_2DA_ROWS 10 rows
		FOR (row = 1; row < rows; ++row) BEGIN
			SET val = (row - 12)
			TEXT_SPRINT new_ids ~000040%val%~
			READ_2DA_ENTRY row 9 10 ids_val
			PATCH_IF !(IS_AN_INT %ids_val%) BEGIN
				SET_2DA_ENTRY row 9 10 ~0x%new_ids%~


No variables, you just call the function with:

LAF fix_kitlist_missing_ids END

EDIT - updated a bit, now it works even if kitlist.2da has already been treated by the k4thos function and has "*" or some other non-integervalue in the KITIDS column.

Edited by subtledoctor

Share this post

Link to post
On 7/29/2018 at 1:23 PM, K4thos said:

REPLACE_MULTILINE: Patch function that replaces set or all occurrences of the given regexp pattern in the file with the given string

Do you perhaps have a function to add something to a certain section of UI.MENU (e.g., adding a button to LEFT_SIDEBAR_BOTTOM...)

Share this post

Link to post
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...