Preventing PC from getting duplicate item (Inventory)
xypher
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.
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.
0
Comments
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.
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?
if (GetItemPossessedBy(oPC, "tagofitem")!= OBJECT_INVALID)
return;
Thanks for all the feedback!
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!