Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.


Dark Dreams of Furiae - a new module for NWN:EE! Buy now
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Preventing PC from getting duplicate item (Inventory)

xypherxypher Member Posts: 10
Hi all,

I am having trouble checking and preventing the PC from getting a duplicate item into their inventory.

For my example, the PC checks a notice board with an inventory and you can take a contract item from the board. Then, currently I have it create another of the same object as this will be a PW. Therefore, other players can grab it as well. However, I am now stuck on trying to figure out how to stop the PC from getting another of that same contract item if they already have it in their inventory.

I figured it would be a similar process to how I am checking the notice board in order to create another of the same item with GetItemPossessedBy. As I started scripting it out I realized I can check to see if the PC has it, but then I am at a loss as to how to actually stop it from going into the PC inventory. Also, I'm not quite sure where that scripting would go - in the OnDisturbed script I created for the notice board? Or somewhere else? I am new to the scripting and learning so thank you for any guidance / tips.


  • WilliamDracoWilliamDraco Member Posts: 156
    edited May 2020
    In native you can't directly preventing it from going into their inventory, although you do have some other options. (nwnx has this option, but being as you're new we'll ignore that for now)

    You could generate the items only during OnOpen of the notice board, and do a check to generate only if the PC doesn't already have one (And destroy them all OnClose so nothing is leftover for the next person).

    A bit more complicated would be to scan the players inventory, determine if they have two, and then either Destroy one of them or make the container "take" it back (ActionTakeItem). Maybe OnClose.

  • xypherxypher Member Posts: 10
    Thanks for the tips Draco. I have gone with the first one you mentioned, and have it setup to create the object OnOpen and then it destroys any items OnClose (thus preventing the inventory from having any leftovers or duplicates). Works great with that method.

  • ProlericProleric Member Posts: 875
    In the module's OnAcquireItem event, if the player has had the item already, put it back in the box, with a message to the PC explaining why.

  • xypherxypher Member Posts: 10
    Hello again! I wanted to followup on my original question as I am stuck again. When the PC takes the item from the board I want it to set a local variable (SetLocalInt) on the PC as a counter to keep track of certain kills made. Once that variable is a certain number they go to an NPC character with a simple TAW script, but it does not appear to work so I can only guess that the counter variable isn't being set on the PC.

    Am I able to simply put this in the module's OnAcquire script? I thought that is where it should go so I made a custom one, but kept it as it was (Save As) and just added a simple piece (circled in red):


    Does my logic look OK, or does this script not fire as I think it does (literally acquiring any item in the game)?

    Just in case that script does look OK, here is my TAW on the NPC.


    Finally, I'm trying to figure out the best way to debug to help make it quicker / easier for me to do so. I was reading on the Lexicon, but couldn't seem to get it to work with a SpeakString or debugging to log file. I might have been doing it wrong, but what is a good way to handle it? Specifically, if I was certain a script was to fire how could I insert a debug string / line to confirm if a variable has a certain value without having to play through more chunk of the game to see if whole thing works?

  • mlkent22mlkent22 Member Posts: 41
    before you give the item via resref in the script, add:
    if (GetItemPossessedBy(oPC, "tagofitem")!= OBJECT_INVALID)

  • xypherxypher Member Posts: 10
    Hi kent, thanks for the feedback, but I have that whole gameplay loop working the way it should now. I forgot to check another place I had forgot about while toiling over those other scripts I posted. My custom death script on the enemies... lol.

    Thanks for all the feedback!

  • xypherxypher Member Posts: 10
    edited May 2020
    OK, small debug question. I'm now using the following as a simple debugging tool for the variable:

    int nValue = GetLocalInt(oPC, "nWolfCount");
    SendMessageToPC(oPC, "nWolfCount: " + IntToString(nValue));

    I'm just sending a server message to myself and it works in the OnDeath script for the creatures. When I kill them it sends a message and I see the variable count. However, it doesn't work in the OnAcquired module script. Any ideas why? I'd just like to confirm so I can test future variables and make sure they are set = 0 to start.

    This is the OnAcquire script that sets the variable fine, but doesn't send the PC a server message like it does when I kill the creatures.

    if (oItem == GetObjectByTag("HUNTWOLF") && GetIsPC(oPC)) {
    SetLocalInt(oPC, "nWolfCount", 0);
    int nValue = GetLocalInt(oPC, "nWolfCount");
    SendMessageToPC(oPC, "nWolfCount: " + IntToString(nValue));

    EDIT: I have this working now. Thanks all!

    Post edited by xypher on
Sign In or Register to comment.