Author Topic: Help preventing a PC from taking an item from a container needed  (Read 565 times)

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« on: February 21, 2011, 10:43:56 am »


               Is there an easy way of preventing a PC from taking an item from a container if they already have an identical one in their inventory? Stopping them from picking one up off the floor is easy, but containers have me stumped. If not I'll just have to make it so they immediately drop the item, but that just seems a bit messy.

Thanks in advance.

TR
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #1 on: February 21, 2011, 11:58:47 am »


               have you tryied setting the item cursed flag OnOpen of the chest?
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #2 on: February 21, 2011, 05:15:36 pm »


               Why not simply create the item in the chest only if they don't already have it?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #3 on: February 21, 2011, 07:15:38 pm »


               

kalbaern wrote...

Why not simply create the item in the chest only if they don't already have it?

exploitable
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #4 on: February 21, 2011, 07:49:06 pm »


               I really need more information on what is tring to be done here. 
Is this going to be for every item in the chest ?
Or just a single item that you can only  have one of?

if it is the single item just take care of it through TBS the same way you are most likely taking care of it when picked up from the ground.   Just put it back in the chest instead of dropping it.  There is a GetModuleItemAcquiredFrom function in the module event after all.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #5 on: February 21, 2011, 08:27:47 pm »


               

ShaDoOoW wrote...

kalbaern wrote...

Why not simply create the item in the chest only if they don't already have it?

exploitable


If it's a one time ever issue, you can make it non exploitable by storing a variable on an item in the PC's inventory that is undroppable. Then check the item for the variable before creating it. If it's a do once per reset thing, store it as a local variable on the PC.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #6 on: February 21, 2011, 08:34:16 pm »


               exploitable because one player could open the chest and another player come by and take the item while the chest is still open.  Assuming it is a multiplayer game.

               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #7 on: February 21, 2011, 10:27:21 pm »


               Thanks for all the responses. As I've never actually written for multiplayer, I don't know if the feeble solution that I came up with is exploitable. After I wrote my request Ithought I better see if there was some work-around that I could come up with just in case there is no way of stopping a player from aquiring more than 1 of a particular item, So I thought what if instead of trying to stop them getting it, I immediately put it back? If nwn is fast enough it might give the illusion, if not the reality, of only being to take 1 item at any one time. So I put the following code in the X2_ITEM_EVENT_ACQUIRE part of my tag based script for it.

oPC = GetModuleItemAcquiredBy();
oItem = GetModuleItemAcquired();
if(oItem != OBJECT_INVALID)
{
   if(GetNumItems(oPC, GetTag(oItem)) > 1)
   {
       oContainer = GetModuleItemAcquiredFrom();
       if(oContainer != OBJECT_INVALID)
       {
           oNewMap = CreateItemOnObject("mapofrohan", oContainer);
           DestroyObject(oItem);
       }
   }
}

And it does indeed give that illusion. So thanks for the input. One question, is this code exploitable?

TR
               
               

               


                     Modifié par Tarot Redhand, 21 février 2011 - 10:28 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #8 on: February 22, 2011, 12:07:23 am »


               I dont see any exploit. 

I do think I would do it more like this though.

  object oPC = GetModuleItemAcquiredBy();
  object oItem = GetModuleItemAcquired();
  if(oItem != OBJECT_INVALID)
  {
    if(GetNumItems(oPC, GetTag(oItem)) > 1)
    {
      object oContainer = GetModuleItemAcquiredFrom();
      if(GetHasInventory(oContainer))
      {
        CopyItem(oItem, oContainer,TRUE);
        DestroyObject(oItem);
      }
    }
  }
               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #9 on: February 22, 2011, 01:07:45 am »


               I did - if(oContainer != OBJECT_INVALID) - because the item can be aquired off the ground and GetModuleItemAcquiredFrom returns OBJECT_INVALID if the place the item is aquired from is not a container. Never occurred to me to use CopyItem - must make a note for future reference 'cos don't need the resref. Thanks for that one.



TR

               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #10 on: February 22, 2011, 01:28:52 am »


               Yes,  I am just not sure what happens when the event fires from the item being created into the inventory of the chest.  At that point the event fires again, Does the function the return the item being aquired form the module a Valid object or OBJECT_INVALID ??  I just thought it safer to limit it a bit more without having to do the research.



Keep in mind that If they buy the item from a store they will lose the item and there gold.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #11 on: February 22, 2011, 10:49:19 am »


               

GetLastDisturbed() returns the object that last disturbed OBJECT_SELF.
GetInventoryDisturbType() returns one of the INVENTORY_DISTURB_TYPE_* constants to determine what occured.
GetInventoryDisturbItem() returns the item that was either added or removed to the inventory of OBJECT_SELF.



Would these functions not be more useful?



Allows you to determine if your individual placeables inventory, had an item taken away, by whom, and then you can script specifically for whether or not the action should occur.



eg -  

if item was not allowed to be taken by item taker, then give item back to chest.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #12 on: February 22, 2011, 11:11:07 am »


               Yes, OnDisturbed is probably the only way of doing something like this in multiplayer.

If thats SP however, it would be maybe better, if you would set the item in placeable's OnOpen to cursed so no "if take then destroy" workaround is needed at all

btw: LightFoot8 thanks for that undroppable(cursed) suggestion, I didn't know about this, it allowed me to remake my view only items, so I dont have to mess with my module events.
               
               

               


                     Modifié par ShaDoOoW, 22 février 2011 - 11:12 .
                     
                  


            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #13 on: February 22, 2011, 02:00:16 pm »


               I think you going to need to do a few tweeks to get this to work.

First the mod on acquire Item script be the place to do what your looking for? If player has X in inventory, then another instance of X can not be picked up.

Second, create a Database value when the PC gets the item the first time, so

Third, have the container check for the database value to see if it will spawn the item.



As far as another player opening the chest, and another PC then gets the item, well the first part takes care of that.



good luck.

               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #14 on: February 22, 2011, 11:42:33 pm »


               Thanks guys. Having read what shova wrote I think I better clear one thing up. There can be many instances of this item in the game but no one player can own more than one copy of it. So if player a opens a chest and player a already has a copy of this item but player b who does not have a copy comes along and takes the item in the chest, it doesn't really matter.



TR