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

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #15 on: February 23, 2011, 01:08:17 pm »


               And this item does not stack?
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #16 on: February 23, 2011, 01:20:49 pm »


               This should work for an item that does not stack:



[nwscript]

#include "nw_i0_plot"



const string ONE_ONLY_TAG = "";//put the tag of the one/per item here

const string DENY = "You may only possess one of that item.";



void main()

{

object oContainer = OBJECT_SELF;

object oPC = GetLastDisturbed();

int nType = GetInventoryDisturbType();

object oItem = GetInventoryDisturbItem();

string sTag = GetTag(oItem);

int nNum; string sRes;



if(sTag != ONE_ONLY_TAG)return;

if(nType != INVENTORY_DISTURB_TYPE_REMOVED)return;



nNum = GetNumItems(oPC, ONE_ONLY_TAG);



if(nNum > 1)

{

  sRes = GetResRef(oItem);

  CreateItemOnObject(sRes, oContainer);

  DestroyObject(oItem, 0.1);

  SendMessageToPC(oPC, DENY);

}





}[/nwscript]
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #17 on: February 23, 2011, 01:21:37 pm »


               #include "nw_i0_plot"

const string ONE_ONLY_TAG = "";//put the tag of the one/per item here
const string DENY = "You may only possess one of that item.";

void main()
{
object oContainer = OBJECT_SELF;
object oPC = GetLastDisturbed();
int nType = GetInventoryDisturbType();
object oItem = GetInventoryDisturbItem();
string sTag = GetTag(oItem);
int nNum; string sRes;

if(sTag != ONE_ONLY_TAG)return;
if(nType != INVENTORY_DISTURB_TYPE_REMOVED)return;

nNum = GetNumItems(oPC, ONE_ONLY_TAG);

if(nNum > 1)
{
  sRes = GetResRef(oItem);
  CreateItemOnObject(sRes, oContainer);
  DestroyObject(oItem, 0.1);
  SendMessageToPC(oPC, DENY);
}


}
               
               

               


                     Modifié par Baragg, 23 février 2011 - 01:21 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #18 on: February 23, 2011, 04:25:38 pm »


               Please Note that He wants the PC to only have one item of this kind. The above solution is perfect for use on just a chest.  However since most of the code posted are just script fragments, I am pretty sure he is also adding code for picking the item up from the ground.  Hence the need to use TBS.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Help preventing a PC from taking an item from a container needed
« Reply #19 on: February 24, 2011, 04:47:46 am »


               Sorry bout the double posting.
               
               

               
            

Legacy_Tarot Redhand

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


               Thank you to everyone for thier help. If anyone is interested to see what I was working on, I have now uploaded the project to the vault and the link is in my sig under Micro Maps.



TR