Script help: Moving equipped items to container

Post » Fri Sep 11, 2009 2:07 pm

I'm new to script writing, but I've been going through tutorials and reading documents such as Morrowind Scripting for Dummies, Morrowind Mod Maker Manual, and Morrowind Script Library.

Anyway, I have an idea for a simple mod I want to try, but there are some aspects of how containers and RemoveItem / AddItem work that I'm still trying to understand.

Could someone explain how I might write a script to accomplish this:

* Move all equipped items (and ONLY equipped items) from player to a container
I'm assuming this involves RemoveItem - which deletes the item, but I don't understand how to create duplicate items inside the container if I can't use a specific object_ID. After all, the items currently equipped on player can change. I don't know beforehand exactly what the player has equipped. So, I'd need some way of detecting exactly which items are equipped and then store the object_ID in a variable... right?

* Move all items from a container to player's inventory and then force equip them.
(I'm assuming that all objects in container are equipable.) I know that as long as the script is run with Tribunal, the "equip" function should work properly. But I have the same problem as above where the equipable contents of the container are not static. Therefore, I won't have the specific object_ID without detecting it first, right?

Any help is appreciated. And if this ever turns into a finished mod, I'll be sure to mention your name in the credits.
User avatar
Alba Casas
 
Posts: 3478
Joined: Tue Dec 12, 2006 2:31 pm

Post » Fri Sep 11, 2009 7:17 pm

Actually you'll need to use MWSE to make this work. There's no other way that you can get a list of all items in the player's inventory, let alone those that are equipped.

The functions you'll need to read up on are xAddItem, xRemoveItem, xHasItemEquipped, and xContentList. There's a sample script that comes with the download that shows you how to transfer the entire inventory to a container; just add a check with xHasItemEquipped to find out if it is something that is equipped.
User avatar
Eddie Howe
 
Posts: 3448
Joined: Sat Jun 30, 2007 6:06 am

Post » Fri Sep 11, 2009 11:55 pm

Hey, thanks! I was beginning to wonder if this was impossible to do in the Morrowind engine without something like MWSE. Now I've got my answer.

BTW: I was confused at first by which "MWSE" to use (as I've not tried either before). But I'm sure you are referring to the http://sourceforge.net/projects/mwse/files/ here, as this adds script fuctionality:
An external program that adds extra script functions to the game of Morrowind. This allows for the creation of plugins that are impossible or at least very difficult while running the game alone.

This is not to be confused with http://planetelderscrolls.gamespy.com/View.php?view=Mods.Detail&id=655, which (while it is handy) is merely a script writing editor:
MWSE allows you to open and edit multiple Morrowind scripts from existing plugin (*.esp) or master (*.esm) files. You can also create new scripts, or just play around to learn the language.

Thanks again!
User avatar
Kim Kay
 
Posts: 3427
Joined: Fri Oct 13, 2006 10:45 am

Post » Sat Sep 12, 2009 3:27 am

MWSE is the program that "runs" your mod, MWEdit is the program you use to create the scripts Fligg mentioned. A word of caution: do not edit dialog in MWEdit; the program is bugged and will corrupt your dialog. If you need to add dialog, write your scripts in MWEdit, then load it like normal into the CS. When you load it in the later, you'll need to select the Morrowind.esm file and Tribunal and/or Bloodmoon if you need either of those for dialog.
User avatar
Amber Hubbard
 
Posts: 3537
Joined: Tue Dec 05, 2006 6:59 pm

Post » Fri Sep 11, 2009 9:05 pm

Something that was pointed out in the take_player_items example script mentioned that comes with MWSE:

When you make copies of the player's items (such as using AddItem to put copies in a container and then using RemoveItem to remove the originals in the player's inventory), these are merely copies and this can have consequences for certain types of items. Weapons and armour will have damage reset, and charged enchanted items will have their charges reset.

I think it goes without saying that, in addition to the above, the "Condition" of alchemical apparatus, lockpick, probe, and repair tool items would also be rest by making a copy.

Also, I have to wonder if there might ever be a case where the maximum charges (i.e., "MaxCharge") of an enchanted item would be changed from the default created by AddItem? Further, might there be a case where an object's Value and/or Weight might be changed from the default created by AddItem? Perhaps some unusual mod scripts might do such things?

I'm just wondering how many different kinds of checks I will need to add to my swap equipment script in order to be on the safe side. The safe thing might be to include every check possible, but that slows down a script. And the easy way out would be to merely go simple and fix such bugs later, at the cost of annoying play-testers and/or players.

Finally, I worry about using RemoveItem on an equipped item that might have a script running. Won't deleting an object with a running script cause the game to crash? Or does that problem only apply to scripts on NPC corpses that would vanish automatically without the "corpses persist" property?

A word of caution: do not edit dialog in MWEdit; the program is bugged and will corrupt your dialog. If you need to add dialog, write your scripts in MWEdit, then load it like normal into the CS...


Ah, thanks for the warning!
User avatar
Darren Chandler
 
Posts: 3361
Joined: Mon Jun 25, 2007 9:03 am

Post » Fri Sep 11, 2009 8:55 pm

Also, I have to wonder if there might ever be a case where the maximum charges (i.e., "MaxCharge") of an enchanted item would be changed from the default created by AddItem? Further, might there be a case where an object's Value and/or Weight might be changed from the default created by AddItem? Perhaps some unusual mod scripts might do such things?


This is not a concern. The base stats of an item will never be modified by AddItem or RemoveItem, and the MWSE equivalents are only variable wrappers.

Finally, I worry about using RemoveItem on an equipped item that might have a script running. Won't deleting an object with a running script cause the game to crash? Or does that problem only apply to scripts on NPC corpses that would vanish automatically without the "corpses persist" property?


No need to worry about this either. RemoveItem properly stops the script before the item is removed. The only time this is a problem is if the script on an item is causing that same item to be removed.


Also, don't edit NPCs in MWEdit. The AI can get screwed up and it will afterwards crash the CS if you try to edit that NPC.
User avatar
TRIsha FEnnesse
 
Posts: 3369
Joined: Sun Feb 04, 2007 5:59 am


Return to III - Morrowind