Intelligent Item Creation Problem

Hi, fellas. Been trying to create a new intelligent item (it’s a book) in a new module I’m working on. I followed this tutorial very carefully (https://nwnlexicon.com/index.php?title=Creating_An_Intelligent_Item). Tested the item in my module. Everything went fine, except for a problem: when my PC talked to the item, the game kept showing that it was Enserric the Sword I was talking to and not the book. The conversation always showed the name ‘Enserric the Sword’ and the portrait of a large black sword, even though the spoken contents of the conversation were what I had put in. What gives? How do I make the game show the name and portrait I gave the book? Any help will be appreciated, thanks. (Dunno if the recent installation and use of the latest CEP might have had something to do with it; before then I once tried the same in a different module and there seemed no problem at all.)

Did you follow this step:

  1. In the standard placeable objects list, find the ‘Enserric the sword’ invisible object under the ‘Secret Object’ heading. Edit a copy of the item giving it a new name and portrait. Set the blueprint ResRef of the placeable to be the same as the tag of the Item you created.

?

The “Enserric the sword” object that the PC is actually talking to is an invisible placeable, and it’s name and portrait are what shows during the dialogue. If you modify your new blueprint’s name and portrait, that should do it.

Just double-checked; yeah, I did all that. :slightly_frowning_face:

Good to hear from you again by the way, Barbie. Hope all’s been well. :wink:

1 Like

:thinking: OK, I’ve followed the tutorial, and it’s working on my end.

I’ve got one more suspect for what could be wrong:

  1. Open x2_s3_intitemtlk, put a single space anywhere in the file, and then delete it again. This will signal to the toolset that this file needs to be recompiled. Save the file.

By the end of it, you should have overriding versions of two scripts in your module; x2_s3_intitemtlk, and x2_inc_intweapon. x2_inc_intweapon is a library; the edit made to it, which makes the alteration that the tag of the used item will be used to find the placeble blueprint to spawn, will only take effect in scripts that get compiled again after the change to the library has been made.

Check and make sure that you got the right line altered in x2_inc_intweapon, and then open x2_s3_intitemtlk again, add a space to it, and save+compile. Try to run the module, see if that fixed it.

If it didn’t, click up here:

image

… and compile all scripts:

Click Build button, with Compile → Scripts active.


Small talk!

Life as usual on my end. Thank you, and same to you! :slight_smile:

::throws hissy fit:: :grin:

1 Like

I guess I should have told you that, when I went to step 6 of the tutorial where I was told to add a line, remove it and save/compile the thing, the script editor suddenly opened the script file ‘nw_i0_generic’, and furthermore showed this error message:

Error. ‘x2_s3_intitemtlk’ did not compile.
nw_i0_generic.nss(147): ERROR: FUNCTION DEFINITION MISSING NAME

The offending line in ‘nw_i0_generic’ was:

int NW_TALENT_PROTECT = 1; (this is line 147 in the script)

I originally decided to ignore all this and try out my item. That was when I found that it worked in every respect except for the name and portrait.

Perhaps I should also have told you that I created this item and found it to be without any problems at all in a much earlier module I did. With this new module I’m working on I wanted the same item in it and decided to try importing it from the earlier module, conversation files and all. Didn’t work. So I decided to try and remake the item in the new module from the ground up. The result is what I told you above. Perhaps I should never have imported anything from the earlier module in the first place? Certainly when I went to step 5 of the tutorial, I found that, hey, the line I needed to change in the script ‘x2_inc_intweapon’ was already changed…

Wish everything could be a little less complicated… C’est la vie:slightly_frowning_face: :wink:

1 Like

That’s been happening for me a lot recently, too. :thinking: I’m just kind of mentally filtering it out at this point. Compiling all the scripts again fixes things when it does. I haven’t the faintest idea what’s causing this, but it doesn’t seem to be an user error kind of thing. Sometimes it happens, sometimes it doesn’t.

Watch out in case all your custom scripts mysteriously stop working at all, in one go, too; same solution - recompile all scripts again. Non-“false alarm”-errors will happen every time, false alarm ones won’t.

1 Like

Good to know I’m at least not the only one encountering this sort of problem.

Guess we’ll just have to keep exploring until we ‘find’ something… :neutral_face:

This is the first time I’ve seen a dagger being called ‘huggy’ by the way. :woozy_face:

1 Like

When the compiler suddenly opens an include like nw_i0_generic with some spurious message, it is a known compiler bug.

The workaround is to save the script, close the script editor, reopen the script and recompile.

Your script has not recompiled until you do that.

2 Likes

Thanks! Didn’t seem to help, though… :neutral_face: Upon recompiling the same compiler bug appeared, and when I tested the item in the module the same problem was there…

Wonder if the installation of the latest CEP (2.65) might have got something to do with it all. In a much earlier module I did (which didn’t use any CEP content) the intelligent items I made showed no problems at all.

Am going to bed now (it’s past midnight over at my side :wink: ). Will be back in 7 ~ 8 hours!

Okay, I decided to try all over again, but this time using tag-based scripting and steering clear of Enserric the Sword. :slightly_smiling_face: Been going through the contents of Grimlar’s page and trying to absorb them to the best of my ability. The following is what I did:

  1. I made sure the .nss files required for tag-based scripting were in my new module.

  2. I created a new item from scratch. It’s a book (which I want the PC to be able to start a conversation with). I named it ‘Crazy Book’ and set its tag to ‘crazybook123’. I gave it the property ‘Unique Power Self Only: Unlimited Uses a Day’.

  3. I wrote a short conversation file named ‘crazybook123’.

  4. I copied the script “x2_it_example” from Grimlar’s page, dumped it in my new module, renamed it ‘crazybook123’ and made the following alteration:

case X2_ITEM_EVENT_ACTIVATE:
// * This code runs when the Unique Power property of the item is used or the item
// * is activated. Note that this event fires for PCs only

        oPC   = GetItemActivator();             // The player who activated the item
        oItem = GetItemActivated();             // The item that was activated

        // Your code goes here
        ActionStartConversation( oPC, "CrazyBook123");
        //break;
  1. I created from scratch a secret object placeable, also named ‘Crazy Book’, with the tag set to ‘crazybook123’ (I couldn’t change the Blueprint ResRef). I made it an invisible object. I made it ‘Useable’. I set its OnUsed script slot to run the script ‘crazybook123’. I also set the conversation (under the ‘advanced’ tab) to ‘crazybook123’.

  2. I dumped both the book and the placeable in the same map in my module.

I then tested the thing. It worked…

…not. :expressionless:

What gives this time and how do I rectify it? Help, please? Thanks!

One trip-up I could see at a glance here is that the caller (OBJECT_SELF) of tagbased item scripts is usually the module, so if this is all that’s happening when the item is being activated right now, then the command to start a conversation with the PC is currently being assigned to the module itself - and it can’t do that.

Try spawning the secret object placeable within your “item activated” event, and assign the PC the command to speak to the placeable.

        object oPlaceable = CreateObject(OBJECT_TYPE_PLACEABLE, "crazybook123", GetLocation(oPC));
        AssignCommand(oPC, ActionStartConversation(oPlaceable));

If that doesn’t work right off the bat, it might be that the placeable is still spawning in at the time when the PC is trying to start a conversation with it, so you could try delaying the conversation-starting attempt.

        object oPlaceable = CreateObject(OBJECT_TYPE_PLACEABLE, "crazybook123", GetLocation(oPC));
        DelayCommand(1.0, AssignCommand(oPC, ActionStartConversation(oPlaceable)));

Note: If the conversation “crazybook123” is already the placeable’s default conversation, then you don’t need to pass it as a parameter for ActionStartConversation, as without a conversation file specified, it will default to using the conversation linked to the creature/placeable.

1 Like

Tried both suggestions. Still didn’t work… (But thanks all the same.)

Tried the following also. Since the placeable was already placed in the module, I figured it shouldn’t be necessary to spawn a new copy of it every time I use the item. So I changed the script to:

object oPlaceable = GetObjectByTag(“crazybook123”, OBJECT_TYPE_PLACEABLE);
AssignCommand(oPC, ActionStartConversation(oPlaceable));

Still didn’t work… :pensive:

(I actually tried some other effects under ‘case X2_ITEM_EVENT_ACTIVATE’, and they worked fine. So it’s not the script ‘crazybook123’ itself that’s the issue.)

Are the tags of items, placeables etc case-sensitive, by the way? Or is ‘crazybook123’ different from ‘CrazyBook123’?

1 Like

Hey, guess what: I finally got the thing to work!!! :joy:

(Want me to tell you how? :wink: )

1 Like

Always. What’d the problem turn out to be? :smiley:

Testing it, yeah - tags seem to be case sensitive. GetStringUpperCase() and GetStringLowerCase() can make it irrelevant in a bunch of places, but it’s something to watch out for when using GetObjectByTag, for sure.

1 Like

The Blueprint ResRef of the placeable must be identical to the item’s tag. That’s the key that finally unlocked the whole thing!! Once this was achieved, the scripts you provided worked like a breeze!

Trouble is, once the placeable is made, its ResRef can no longer be altered. What to do? Scrape it and create a new placeable named ‘crazybook123’. Then its tag and ResRef would all be ‘crazybook123’ as well. The name itself can be changed.

Glad this &U^^$$@#!! problem’s finally solved. Now to work on my off-limits-to-bards magic item… :wink:

1 Like

Ahhhhh. OK. :smiley:

Brain-storing-misinformation-abort! Tag and resref don’t need to be identical. CreateObject uses the blueprint resref to spawn the object, not it’s tag, is all. Tags aren’t unique to the blueprint, so they couldn’t be reliably used to spawn an instance of a specific blueprint even if there was a spawn-object-by-tag function.

1 Like

Right click on its blueprint. Select Edit Copy. Change resref. Make slight (i.e. maybe add an ‘x’ to the end) change to its name. Click OK. Delete/remove original. Edit name to remove additional character. Voila! Done.

TR

2 Likes

Thanks for the additional hint!

1 Like