Aller au contenu

Photo

Removing specific items by TAG


  • Veuillez vous connecter pour rĂ©pondre
9 réponses à ce sujet

#1
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
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 .


#2
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
Fixed it. Changes in green.

FP!

#3
Failed.Bard

Failed.Bard
  • Members
  • 774 messages

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 .


#4
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.

#5
Failed.Bard

Failed.Bard
  • Members
  • 774 messages

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.

#6
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
 

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.

#7
Vivienne L

Vivienne L
  • Members
  • 80 messages
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?

#8
Vivienne L

Vivienne L
  • Members
  • 80 messages
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!

#9
Failed.Bard

Failed.Bard
  • Members
  • 774 messages

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 .


#10
Vivienne L

Vivienne L
  • Members
  • 80 messages
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!