Author Topic: Removing specific items by TAG  (Read 150 times)

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Removing specific items by TAG
« on: September 07, 2011, 06:14:49 am »


               The TAG of the items start with GP_blahblah and I'm trying to take those away from the player when entering a trigger - single player - but I can't figure out what I've done wrong. The script compiles fine, the items are available on the player with the GP_ TAG of items and a holding container that the items are copied over to.

Yet, the items remain in the inventory of the character. The container also remains empty after the script fires.

void main()
{
  string sTag;

  object oTo = GetObjectByTag(sTag);
  object oPC = GetEnteringObject();
  object oItem = GetFirstItemInInventory(oPC);

  if (!GetIsPC(oPC)) return;

  while(GetIsObjectValid(oItem))
  {
    if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "GP_")
      {
      sTag = "STOLENPC_ITEMS";
      oTo = GetObjectByTag(sTag);
      CopyItem(oItem, oTo, TRUE);
      DestroyObject(oItem);
      }
    oItem = GetNextItemInInventory(oPC);
  }
}


Thanks,

FP!
               
               

               


                     Modifié par Fester Pot, 07 septembre 2011 - 05:22 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Removing specific items by TAG
« Reply #1 on: September 07, 2011, 06:21:10 am »


               Fixed it. Changes in green.

FP!
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Removing specific items by TAG
« Reply #2 on: September 07, 2011, 07:39:04 am »


               

Fester Pot wrote...

The TAG of the items start with GP_blahblah and I'm trying to take those away from the player when entering a trigger - single player - but I can't figure out what I've done wrong. The script compiles fine, the items are available on the player with the GP_ TAG of items and a holding container that the items are copied over to.

Yet, the items remain in the inventory of the character. The container also remains empty after the script fires.

void main()
{
  string sTag;

  object oTo = GetObjectByTag(sTag);
  object oPC = GetEnteringObject();
  object oItem = GetFirstItemInInventory(oPC);

  if (!GetIsPC(oPC)) return;

  while(GetIsObjectValid(oItem))
  {
    if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "GP_")
      {
      sTag = "STOLENPC_ITEMS";
      oTo = GetObjectByTag(sTag);
      CopyItem(oItem, oTo, TRUE);
      DestroyObject(oItem);
      }
    oItem = GetNextItemInInventory(oPC);
  }
}


Thanks,

FP!


  For efficiencies sake, though it won't make any noticeable difference, likely these four lines should simply be combined:
string sTag;
object oTo = GetObjectByTag(sTag);
sTag = "STOLENPC_ITEMS";
oTo = GetObjectByTag(sTag);

into:
object oTo = GetObjectByTag("STOLENPC_ITEMS");

Leaving you with:

void main()
{

object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oTo = GetObjectByTag("STOLENPC_ITEMS");

object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
  {
   if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "GP_")
     {
      CopyItem(oItem, oTo, TRUE);
      DestroyObject(oItem);
     }
   oItem = GetNextItemInInventory(oPC);
  }
}


Edit:  If you might be removing more than one item from the characters inventory, you'll want to delay destroying the items by 0.1, since without the delay it can cause items to be skipped.
               
               

               


                     Modifié par Failed.Bard, 07 septembre 2011 - 06:41 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Removing specific items by TAG
« Reply #3 on: September 07, 2011, 04:35:43 pm »


               

Failed.Bard wrote...

Edit:  If you might be removing more than one item from the characters inventory, you'll want to delay destroying the items by 0.1, since without the delay it can cause items to be skipped.



This is incorrect.   The item will not be destroyed from the inventory untill after the script is finished running, reguradless of the delay being there or not.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Removing specific items by TAG
« Reply #4 on: September 07, 2011, 08:19:48 pm »


               

Lightfoot8 wrote...

Failed.Bard wrote...

Edit:  If you might be removing more than one item from the characters inventory, you'll want to delay destroying the items by 0.1, since without the delay it can cause items to be skipped.



This is incorrect.   The item will not be destroyed from the inventory untill after the script is finished running, reguradless of the delay being there or not.


  Hmmm...  I'd had a problem with not delaying the destroy object in a script before, but testing right now shows that Lightfoot is right about me being mistaken on how the system handles it..
  Now I just have to figure out what other thing it was that had created the issue that I'd been blaming on the DestroyObject portion of my script.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Removing specific items by TAG
« Reply #5 on: September 07, 2011, 10:09:03 pm »


                

Failed.Bard wrote...
   Hmmm...  I'd had a problem with not delaying the destroy object in a script before, but testing right now shows that Lightfoot is right about me being mistaken on how the system handles it..
  Now I just have to figure out what other thing it was that had created the issue that I'd been blaming on the DestroyObject portion of my script.


You may have ran into your problem when creating objects.   I know I have had some interesting results when adding objects to a list I was searching through.
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
Removing specific items by TAG
« Reply #6 on: March 13, 2012, 05:33:14 pm »


               Thank you everybody; I was working on a similar script and couldn't get it working until I searched and found this!!! But I do have a question. How do i confiscate equipped items with a similar tag?
               
               

               
            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
Removing specific items by TAG
« Reply #7 on: March 15, 2012, 12:39:59 pm »


               This what my script looks like:

void main()
{

object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oTo = GetObjectByTag("TH_WEAPONRACK");

object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
 {
  if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "TH_")
    {
     CopyItem(oItem, oTo, TRUE);
     DestroyObject(oItem);
    }
  oItem = GetNextItemInInventory(oPC);
 }
int nSlot;
for (nSlot = 0; nSlot < INVENTORY_SLOT_BOLTS; nSlot++)
  {
  if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "TH_")
    {
         oItem = GetItemInSlot(nSlot, oPC);
         CopyItem(oItem, oTo, TRUE);
         DestroyObject(oItem);
    }



}
   }


The first part of the script  that searches and removes objects from the inventory to the weapon rack are working but the equipped objects are not being being removed at all!
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Removing specific items by TAG
« Reply #8 on: March 15, 2012, 01:29:59 pm »


               

vivienne.l wrote...

This what my script looks like:

void main()
{

object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oTo = GetObjectByTag("TH_WEAPONRACK");

object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
 {
  if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "TH_")
    {
     CopyItem(oItem, oTo, TRUE);
     DestroyObject(oItem);
    }
  oItem = GetNextItemInInventory(oPC);
 }
int nSlot;
for (nSlot = 0; nSlot < INVENTORY_SLOT_BOLTS; nSlot++)
  {
  if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "TH_")
    {
         oItem = GetItemInSlot(nSlot, oPC);
         CopyItem(oItem, oTo, TRUE);
         DestroyObject(oItem);
    }



}
   }


The first part of the script  that searches and removes objects from the inventory to the weapon rack are working but the equipped objects are not being being removed at all!



void main()
{

object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;

object oTo = GetObjectByTag("TH_WEAPONRACK");

object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
 {
  if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "TH_")
    {
     CopyItem(oItem, oTo, TRUE);
     DestroyObject(oItem);
    }
  oItem = GetNextItemInInventory(oPC);
 }
int nSlot;
for (nSlot = 0; nSlot < INVENTORY_SLOT_BOLTS; nSlot++)
  {
 
oItem = GetItemInSlot(nSlot, oPC);
if(GetStringUpperCase(GetStringLeft(GetTag(oItem),3)) == "TH_")
    {
                    CopyItem(oItem, oTo, TRUE);
         DestroyObject(oItem);
     }
}
   }


You had the item defined inside the if statement to check it.
edit:  Why can't I ever get the colours to stick?
               
               

               


                     Modifié par Failed.Bard, 15 mars 2012 - 01:32 .
                     
                  


            

Legacy_Vivienne L

  • Full Member
  • ***
  • Posts: 130
  • Karma: +0/-0
Removing specific items by TAG
« Reply #9 on: March 16, 2012, 06:25:22 am »


               Thank you very much! I just find scripting so confusing but when anyone of you kind helpful people point out my mistakes, it seems so obvious that I wonder why I didn't see it myself!