Jump to content

Add items to inventory when talking to a NPC.


ilsolas

Recommended Posts

I have been trying to figure out what kind of script I need or if it is even possible to do.

 

For the mod I'm creating (adding several grey warden armors after the ritual) I want to cut down on the amount of items the player gets at the beginning of the game and have the armors generate on class choice.

 

I was tempted to try and add it onto the ritual script like the GWOF mod but I would prefer to add it to my custom grey warden outfitter npc I have created. I have tested it with dialogue with this simple script when I click on him:

 

void main()
{
object oPC = GetHero();
CreateItemOnObject (R"gwo_hvychest.uti",oPC);
}
He has ambient dialogue instead of a cutscene and the item is added, But of course you can keep clicking on him to receive multiples and I need to add in for him to give the items over after the ritual. I have tried with addtoinventory scripts and messed around with plot flags but I'm not really sure what I'm doing as I'm combining different tutorials to find the right scripts.
Is there a simple script that could be made when you click on a placable/npc that you receive items based on your class, quest progression and only gives it to you once?
Link to comment
Share on other sites

The way we usually control giving something only once is to use a plot flag that initializes as Not Set, and give the item at the time the flag gets set.

So that would look something like this (also making the specific item given dependent on class):

 

#include "utility_h"
#include "wrappers_h"

object oPC = GetHero();

if(WR_GetPlotFlag(PLT_MY_PLOT,MY_GIVE_ITEM_FLAG) == FALSE) {
WR_SetPlotFlag(PLT_MY_PLOT,MY_GIVE_ITEM_FLAG,1);
if(GetCreatureCoreClass(oPC) == CLASS_WIZARD)) {
UT_AddItemToInventory(R"my_mage_item_resource.uti",1);
}
if(GetCreatureCoreClass(oPC) == CLASS_ROGUE)) {
UT_AddItemToInventory(R"my_rogue_item_resource.uti",1);
}

if(GetCreatureCoreClass(oPC) == CLASS_WARRIOR)) {
UT_AddItemToInventory(R"my_warrior_item_resource.uti",1);
}

}

 

You could also automatically equip the gear if you'd like.


But I'm a little confused about exactly what you're trying to accomplish.

It sounds like your custom outfitter NPC has dialogue, yes? You can make any line of their dialogue conditional, so you could have an entire branch dependent on whether you've completed the joining.

 

It looks like you're trying to give the player only one set of this gear, specifically for the player. If you're interested in making more sets available for followers as you recruit them, you could just make a console runscript or three...

Link to comment
Share on other sites

Thank you so much for the sample code, I had the lines almost correct but in thr wrong places when I tried to follow all the different tutorials.

 

 

I'm basically making a revamp/own version of the grey wardens of Ferelden mod. Going to add different tiers etc. I got almost all the armors made for origins and awakening.

 

I was originally going to put them all in chests but wanted to cut down and not give all armors to the player. So I wanted to get a key to spawn upon completing the ritual (which is plan b)

 

But I liked the idea of putting in an npc who gives the armor when spoken to.

 

I'm still learning about the dialogue tree in the toolset so I didmt know you could make it conditional. I need to look more into it

Link to comment
Share on other sites

Im thinking just ostagar for now as I'm still very new to scripting. Im going to hopefully do just chests for wardens keep which I've tested and seem to work so far. Also will modifying the wardens cache quest from riodan. I might do enemy drops as well.

 

I like my mods quite lore friendly so its quite restricting to where I can put the armors ð¤­

Link to comment
Share on other sites

I have run into a small issue and I can't figure out the error.

 

So this was my attempt at a script that I wrote after I moved/removed some of the lines around to try and match the sample above.

 

 

#include "utility_h"
#include "wrappers_h"
#include "plt_pre100pt_ritual"
object oPC = GetHero();
int flag_value = WR_GetPlotFlag(plt_pre100pt_ritual, PRE_RITUAL_END);
WR_SetPlotFlag(plt_pre100pt_ritual, PRE_RITUAL_END, TRUE);
WR_SetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END,1);
if(GetCreatureCoreClass(oPC) == CLASS_WIZARD)) {
UT_AddItemToInventory(R"gwo_mchest.uti",1);
}
if(GetCreatureCoreClass(oPC) == CLASS_ROGUE)) {
UT_AddItemToInventory(R"gwo_lthchest.uti",1);
}
if(GetCreatureCoreClass(oPC) == CLASS_WARRIOR)) {
UT_AddItemToInventory(R"gwo_hvychest.uti",1);
}
}
The line highlighted shows the error: E: 12:27:14 - gwo_outfitter_giveitems.nss - gwo_outfitter_giveitems.nss(6): Invalid declaration type
So I removed that script and used the new one but I'm still getting the error on the line highlighted:
#include "utility_h"
#include "wrappers_h"
#include "plt_pre100pt_ritual"
object oPC = GetHero();
if(WR_GetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END) == TRUE) {
WR_SetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END,1);
if(GetCreatureCoreClass(oPC) == CLASS_WIZARD)) {
UT_AddItemToInventory(R"gwo_mchest.uti",1);
}
if(GetCreatureCoreClass(oPC) == CLASS_ROGUE)) {
UT_AddItemToInventory(R"gwo_lthchest.uti",1);
}
if(GetCreatureCoreClass(oPC) == CLASS_WARRIOR)) {
UT_AddItemToInventory(R"gwo_hvychest.uti",1);
}
}

 

 

 

E: 12:27:14 - gwo_outfitter_giveitems.nss - gwo_outfitter_giveitems.nss(6): Invalid declaration type
I know it has something to do with the brackets but I can't seem to fix myself.
Link to comment
Share on other sites

A couple of things:

 

plt_pre100pt_ritual needs to be in all caps, like so: PLT_PRE100PT_RITUAL. It's a constant, and case sensitive. Note: the #include line is fine, but the WR_GetPlotFlag lines need the constant in all caps. The #include line tells the compiler to source in the file it knows as plt_pre100pt_ritual, but within that file is the constant PLT_PRE100PT_RITUAL needed by the WR_GetPlotFlag and WR_SetPlotFlag functions.

 

Also, I got a little overzealous with the parentheses in the example I gave you. I included one too many close parentheses in the GetCreatureCoreClass checks I provided, so instead of this:

if(GetCreatureCoreClass(oPC) == CLASS_WIZARD)) {

 

it should be this:

if(GetCreatureCoreClass(oPC) == CLASS_WIZARD) {

 

... and that needs to be changed for all 3 of those lines. Sorry about that.

 

Once you make these changes, that should compile for you.

 

Oh, and I just took a little closer look at what you're doing, so I'll have more to say here in a bit...

Link to comment
Share on other sites

First of all, TRUE is the same as a value of 1 and FALSE is the same as a value of 0. It probably gets a little confusing for folks who haven't done much coding, but... some of us tend to use those values interchangeably.

Plot flags are stored as bits, and have only 2 possible values: 0 (FALSE) or 1 (TRUE).

So this:
if(WR_GetPlotFlag(PLT_PRE100PT_RITUAL, PRE_RITUAL_END) == TRUE)
does exactly the same thing as this:
if(WR_GetPlotFlag(PLT_PRE100PT_RITUAL, PRE_RITUAL_END) == 1)
.. since the if statement would evaluate the same in either of them.

This line:
int flag_value = WR_GetPlotFlag(plt_pre100pt_ritual, PRE_RITUAL_END);
would be corrected to this:
int flag_value = WR_GetPlotFlag(PLT_PRE100PT_RITUAL, PRE_RITUAL_END);
... and it would serve the purpose of declaring an int variable named flag_value and storing that plot flag in it. Sometimes coders use variables like that to avoid repeated function calls. If you were going to check the value of that plot flag repeatedly, then it can be handy to store it in a variable that is easier to type; but if you're only going to look at it once or twice, it's usually not worth it to declare a variable for it.

Basically, declaring and setting that variable would just mean that you could replace this:
if(WR_GetPlotFlag(PLT_PRE100PT_RITUAL, PRE_RITUAL_END) == TRUE)
with this:
if(flag_value)
going forward.

In the first code example you provided, this part:
WR_SetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END, TRUE);
WR_SetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END,1);

once corrected to this:
WR_SetPlotFlag(PLT_PRE100PT_RITUAL,PRE_RITUAL_END, TRUE);
WR_SetPlotFlag(PLT_PRE100PT_RITUAL,PRE_RITUAL_END,1);

... would basically set that plot flag to the same value twice.

In the second code example you provided, this part:
if(WR_GetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END) == TRUE) {
WR_SetPlotFlag(plt_pre100pt_ritual,PRE_RITUAL_END,1);

once corrected to this:
if(WR_GetPlotFlag(PLT_PRE100PT_RITUAL,PRE_RITUAL_END) == TRUE) {
WR_SetPlotFlag(PLT_PRE100PT_RITUAL,PRE_RITUAL_END,1);

... will check the plot flag, and if it's true, set it to true again. In other words, it wouldn't do anything useful.

And I want to strongly suggest that you do not change any vanilla plot flags!

 

In the original example I provided, I checked a custom plot flag that you would define to track whether you'd given the items yet or not, since you had indicated you wanted to give them only once. If that plot flag had not yet been set, I set the flag and gave the items. In order to provide that functionality, you'll need to define a custom plot and flags.

 

Hope I helped.

Link to comment
Share on other sites

Thanks! I will add the corrections. I didn't even realise I had the same lines twice (damn it dyslexia)

 

I will be doing my own plot and main flags. I just wanted to get script layout done before I started on the plot parts as I didn't want to make numerous mistakes and then try to figure what went wrong if I did it all at once.

Link to comment
Share on other sites

I would actually encourage you to do it the other way 'round.

 

You haven't ever said what kind of script this code is going into and how it will be invoked - and the exact lines of code you'll need are entirely dependent on that. The examples I've provided are sort of generic.

 

I would expect that you're going to have a dialogue for your NPC, and the branch that gives the armor would be conditional on having completed the joining. That dialogue would set your custom plot flag, and its plot script is where the work of issuing the armor would occur.

 

Anyway, I'll be around. I would encourage you to develop that NPC dialogue and the plot flags they'll need. Then I could help you put the right code in the right place in the plot script.

 

Happy modding.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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