Jump to content

Scripting to spawn multiple items


Ossir

Recommended Posts

Hi, I have a small problem with adding items, I hope this hasn't been asked before but it only really needs a quick answer.

 

I have no idea really about scripting, but I have been using an example script from:

 

http://dragonagemodding.wordpress.com/2009/11/11/a-start-creating-a-module-to-give-your-player-an-item/

 

and it works fine for single items.

 

My problem is, I have no idea how to build a longer script that checks for say, every piece of an armour set and then spawns each one. I tried copying and pasting the little script several times but I get "invalid command" errors and it only runs for the first item.

 

I also tried making a different script for each item but this failed when I realized you can only attach one core script to the module properties.

 

if someone can please write a quick example script that they use to add a bunch of different items rather than just one I would be very grateful

 

Thanks

Link to comment
Share on other sites

From the sounds of it, it sounds like you've got an error in your code.

probably a missing, or incorrect character. Or a line break that the code doesnt recognize or something like that. Scripting is very easy to screw up with that kinds of stuff.

 

That, and that example is a MESS. They've got so much commenting going on that its really difficult to seperate out what is needed, and whats part of the comments.

 

Here's a working code that is MUCH simpler to read and sort thru. Taken from one of the mods that adds some books to the inventory-

 

#include "utility_h"

#include "plt_talent_book_plot"

 

void main()

{

if ( WR_GetPlotFlag( PLT_TALENT_BOOK_PLOT, TALENT_BOOK_FLAG ) == TRUE )

return;

 

event ev = GetCurrentEvent();

int nEventType = GetEventType(ev);

 

switch ( nEventType )

{

case EVENT_TYPE_MODULE_LOAD:

{

UT_AddItemToInventory(R"gen_im_misc_ptalent.uti", 99);

UT_AddItemToInventory(R"gen_im_misc_pskill.uti", 50);

UT_AddItemToInventory(R"gen_im_misc_patt.uti", 99);

 

WR_SetPlotFlag( PLT_TALENT_BOOK_PLOT, TALENT_BOOK_FLAG, TRUE );

 

break;

}

default:

break;

}

}

 

The parts that I've got highlighted in Red is where you would substitute your own names. The names that you have made for your flags, and plots.

The parts that I've got higlighted in Green is where you would substitute your own item names. The names that you created for you item.uti.

The parts that I've got highlighted in Yellow is the item count. Meaning how many of that particular item the script is to create. In this script it creates 99 of one item, 50 of the next, and 99 of the final item. Changing those numbers to say.... 1 would make it so that it only spawn one set of gloves. or setting it to 3 would spawn 3 swords. Or whatever you set that number for for whichever item.

 

IF you need to add more items than that, MAKE SURE that you have the Semi-Colon ( ; ) at the end of the line, to designate a line break, (tells the code to start the next line) or else you'll have errors.

So basically, include this entire line-

UT_AddItemToInventory(R"gen_im_misc_patt.uti", 99);

 

Hope that this helps! :)

Good luck! :)

Link to comment
Share on other sites

Thanks for the reply Darke

 

I haven't had a chance to try it out yet but it seems to be what I need. Before I give it a go, just a couple of questions:

 

1) I don't use flags, I just want the module to import items to my main campaign inventory when I load a save, can I just ignore the stuff in red in your example?

 

2) At what point does your script check if the player already has the item?

Link to comment
Share on other sites

Ok, well, I'm afraid that I dont know much about how the game actually handles that. I can guess that its handled by flags. It only loads them once. After that if you want more of them you had to use them up, then reinstall the mod, doing a clean save. :dry:

 

If you are looking for one that checks for the item, then if you dont have it, it will automatically reload another one at game load, here's one that will work for you.

 

#include "utility_h"
#include "wrappers_h"
#include "events_h"

void main()
{

   event   ev = GetCurrentEvent();
   int     nEventType = GetEventType(ev);


   object  oPC = GetHero();

   int     nDoOnce = GetLocalInt(OBJECT_SELF, "ANDRASTE_GS_GIVEN");

   if ( nDoOnce != 1 )
   {
       switch(nEventType)
       {

           case EVENT_TYPE_MODULE_LOAD:
           {
               // If Have
               int nHas = CountItemsByTag(oPC, "andraste_weapon");
               int nHas2 = CountItemsByTag(oPC, "andraste_armor");
               int nHas3 = CountItemsByTag(oPC, "andraste_amulet");
               int nHas4 = CountItemsByTag(oPC, "andraste_belt");
               int nHas5 = CountItemsByTag(oPC, "andraste_feet");
               int nHas6 = CountItemsByTag(oPC, "andraste_glove");
               int nHas7 = CountItemsByTag(oPC, "andraste_helm");
               int nHas8 = CountItemsByTag(oPC, "andraste_ring");

               // If Not
               if ( nHas == 0 )
                   UT_AddItemToInventory(R"andraste_weapon.uti");
               if ( nHas2 == 0 )
                   UT_AddItemToInventory(R"andraste_armor.uti");
               if ( nHas3 == 0 )
                   UT_AddItemToInventory(R"andraste_amulet.uti");
               if ( nHas4 == 0 )
                   UT_AddItemToInventory(R"andraste_belt.uti");
               if ( nHas5 == 0 )
                   UT_AddItemToInventory(R"andraste_feet.uti");
               if ( nHas6 == 0 )
                   UT_AddItemToInventory(R"andraste_glove.uti");
               if ( nHas7 == 0 )
                   UT_AddItemToInventory(R"andraste_helm.uti");
               if ( nHas8 == 0 )
                   UT_AddItemToInventory(R"andraste_ring.uti");

                   break;
           }
       }
       SetLocalInt(OBJECT_SELF,"ANDRASTE_GS_GIVEN", 1);
   }




   // Once we are done with all our stuff, we pass the stuff back to the
   // original script, so it can deal with the rest of the core functions.
   // FIX: Commented out the HandleEvent line. It seems that this refers to
   // this script itself - not the module script of the single player     // campaign - causing issues with doubling stuff later on.
   // HandleEvent(ev, RESOURCE_SCRIPT_MODULE_CORE);
}
// ---------- Script Ends Here ----------

 

Used code tags this time to preserve the lines format. I did not add the colors, the code tags do that :dry:

 

Now this one I like, because you can sell the items off to a merchant and still get new ones to spawn. But after 1.03, if you add it to a party member, they dont spawn that item anymore. So, if you're wanting to be able to "stock up" on them, you can either use a storage mod to stuff them in, OR use HDHD's additem script (after modding your new items into his script) to load the items to your character via the console. storage in the mods section search will bring up mods for that, and doing a search for hdhd in the AUTHOR'S NAME CONTAINS search field will bring up hdhd's script mod.

 

Now, to get rid of any lines there that you dont need (like say you have three spots that you wouldnt be using, I recommend commenting them out, rather than deleting them. just use // in front of the line. Just make sure that you also comment out the corresponding line in the next section of the script ;)

Link to comment
Share on other sites

Not a problem Ossir, I am glad that I could help you out. :)

And I do apologize for pasting you somebody ele's scripts. I am more of a script EDITOR than actual Scripter, so thats kinda where my knowledge is limited to, lol.

 

But, I am glad that you got it working, and that your items are spawning. :thumbsup:

I will go ahead and mention that you should probably zip your files up, and install them via damodder or damodmanager. That way you can deactivate them when needed. You will most likely need to deactivate your mods that add items to player inventory, prior to starting new characters in the game, to avoid the nasty "items dont load" bug.

Essentially, when you start a new character... go thru and deactivate those kinds of mods first. Start the character til you get to a save point. Create your save, then exit. Reactivate your mods, then start your save game again. That will greatly decrease the chances of the scripts not loading correctly to spawn these kinds of items ;)

 

Glad to help out, and happy gaming :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...