Aller au contenu

Photo

Delete Multiple of same item - a better way?


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
 Is their a better way to delete multiple, but not all of the same item on a player?

This is what I'm using now.

object oPC = GetPCSpeaker();
object oItem;   
oItem = GetItemPossessedBy(oPC, "unassignedmana");
       
if (GetIsObjectValid(oItem))       
         DestroyObject(oItem);
       
if (GetIsObjectValid(oItem))       
         DestroyObject(oItem);
       
if (GetIsObjectValid(oItem))       
         DestroyObject(oItem);

edit: to fix the jargon without the [code=auto:0] feature.

Modifié par Buddywarrior, 15 juin 2012 - 03:14 .


#2
Kato -

Kato -
  • Members
  • 392 messages
object oPC = GetPCSpeaker();
int nNth;
for(nNth; nNth < 3; nNth++)
{
    DestroyObject(GetItemPossessedBy(oPC, "unassignedmana"));
}

Change the number(3) according to your needs.

EDIT: If your item can be stacked the code would be somewhat different, however.

Kato

Modifié par Kato_Yang, 15 juin 2012 - 03:18 .


#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
#include "nw_i0_plot"

void main
{

  object oPC = GetPCSpeaker();
  TakeNumItems( oPC,"unassignedmana",3);
}

#4
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
perfect thanks Kato. I wasn't sure if something like DestoryObject(GetItemPossessedBy(oPC,"reref",3)) was around. for loop will work too though =) Thank ya kindly!

#5
Shadooow

Shadooow
  • Members
  • 4 474 messages

Buddywarrior wrote...

 Is their a better way to delete multiple, but not all of the same item on a player?

This is what I'm using now.

object oPC = GetPCSpeaker();
object oItem;   
oItem = GetItemPossessedBy(oPC, "unassignedmana");
       
if (GetIsObjectValid(oItem))       
         DestroyObject(oItem);
oItem = GetItemPossessedBy(oPC, "unassignedmana");       
if (GetIsObjectValid(oItem))       
         DestroyObject(oItem);
oItem = GetItemPossessedBy(oPC, "unassignedmana");       
if (GetIsObjectValid(oItem))       
         DestroyObject(oItem);

code fixed

There is nothing wrong on this approach though, using loop does perform more instructions anyway. Assuming it works actually as the DestroyObject is performed later. Are you sure that it works guys? I was always using loop.

Modifié par ShaDoOoW, 15 juin 2012 - 07:09 .


#6
Kato -

Kato -
  • Members
  • 392 messages
Indeed that's something to consider, ShaDoOoW. Since DestroyObject() is performed at the end and since my example does not work for stacked items I would be eager to use L8 approach since I love short and quick code lol

Kato

Modifié par Kato_Yang, 15 juin 2012 - 08:45 .


#7
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
The DestroyObject() is only removing one at a time, even within a loop or as listed in my original script . I've also tried LightFoot8's idea, and though it runs, it doesn't grab the items.

#8
Kato -

Kato -
  • Members
  • 392 messages
Ahh true, you remind me that TakeNumItems() does not handle stacks correctly. Here is a function which should do it, provided you pass the correct parameters.

void TakeItemFromCreature(object oPC, string sTag, int nNum)
{
   object oItem = GetFirstItemInInventory(oPC);
   int nDestroyed, nStack, nDel;
   while(oItem != OBJECT_INVALID && nDestroyed < nNum)
   {
      if(GetTag(oItem) == sTag)
      {
          nStack = GetItemStackSize(oItem);
          nDel = nNum - nDestroyed;
          if(nStack <= nDel)
          {
              DestroyObject(oItem);
              nDestroyed += nStack;
          }
          else
          {
              SetItemStackSize(oItem, nStack - nDel);
              nDestroyed += nDel;
          }
      }
      oItem = GetNextItemInInventory(oPC);
   }
}

It's from my old arsenal and thus could probably be optimized but it works well nonetheless :)

Kato

Modifié par Kato_Yang, 16 juin 2012 - 03:56 .


#9
Buddywarrior

Buddywarrior
  • Members
  • 256 messages
Tested and that worked like a charm Kato_Yang. Thank you kindly!