For those NOT interested in this scripting fix,
jump to the bottom of this post for Other Module News.
This week I had reason to visit that old problem of split stacks losing their variables. Basically, the official version of the XML code that allows players to split stacks of items is broken: When a player splits a stack of items, if the builder has any variables associated with the stack, then they are lost on one stack when the stack is split into two. This can be a problem if the variables are needed, which is the whole point of them being there in the first place!
I addressed this problem with a fix back in February 2013 with this post, but even back then I mentioned the fix may need to be looked at again. And with my latest work on applying poison to stacked items I found that a more robust version of my fix was required to ensure all items kept any newly added temporary properties as well. This latest version makes use of the CopyItem function (which I mentioned back in 2013), while implementing a temporary storage location as the stack is split.
Fix Basic Outline
1) The official splitstack.xml has been edited to call an edited home function with fixed scripting.
2) The new gui_splitfix creates a temporary inventory placeable to help handle item splitting using CopyItem function (which can be used to maintain variables).
3) The same script tidies the temporary environment after finishing the split.
The XML Changes
Note, the default splitstack.xml already has scriptloadable=true, and so the only change comes at the point when the player clicks on the "split button" and the piece of code that operates there. (See image below and the circled part.) Note the following: The original OnleftClick call has been removed, and two new OnLeftClick calls have been added.
UPDATE: Please note that I have added another line in this XML code, which I have not highlighted in the image. It is the part of code within the "inbox" section:
|This is a newer (changed) version of my previous XML alteration.|
My earlier version of this fix was based upon recreating a copy of the item from an original template, which was fine if the builder considered the need prior to module release. However, this version did not consider alterations to stack conditions after build time, like in the example of poison being added to a stack of arrows. This new script takes such situations into account by basing all splits on the original item rather than referring to a template of it that now potentially differs. Here is the new script:-
NB: Remove the #include line and use the official
"Random" function rather than my own version.
|The more robust script, which uses the CopyItem function.|
For this system to work, the builder must create a placeable object that the script temporarily uses to help the script to work. This is necessary because the new stack items cannot be placed on the PC during time of splitting as they would be destroyed along with those we don't need once the script has completed. Basically, this placeable is a very small invisible object with an inventory where the stacked items can be "worked with" before returning them to the PC in question. Here is an outline of the placeable object properties the builder will need to have in their module:-
|Note: Appearance, Scale, ResRef, Dynamic Collisions, Has Inventory, Plot, Useable and Walkable.|
Other Module News
I continue to work at the module, finding and fixing any other issues as I encounter them. For instance, I did a quick test run of an area the other day, and noticed the following:-
GOOD: Encounters and environment all worked as they should.
GOOD: AI worked really well, with creatures intelligently summoning creatures, using missile weapons where appropriate and generally healing and fighting well.
GOOD: New interfaces all worked well, including the new inventory system.
BAD (NOW FIXED): A sound file did not fire. Now also has improved method of working for reliable results.
BAD: (NOW FIXED): A visual effect was not working after I had edited the script to work from a conversation as well. I simply separated the two scripts and now both work as they should.
BAD: (NOW FIXED): Dead body removal effect. I have incorporated my own visual effect for when a body "fades" on death (rather than simply disappear after looting). It was failing if the creature only carried gold rather than any other item. I have now fixed the script to recognise gold as well, which turned out more complicated than I first thought, as I needed to make "gold" a standard item rather than use the "gold" as it stands.