Author Topic: Item losing undroppable flag on use dye  (Read 772 times)

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Item losing undroppable flag on use dye
« on: February 05, 2015, 05:52:48 am »


               

I set an item as plot and undroppable and it lost undroppable flag when being painted (when use Dye Leather / Dye Cloth).


 


There is how to block use dye on undroppable itens?



               
               

               
            

Legacy_dunahan_schwerterkueste_de

  • Jr. Member
  • **
  • Posts: 66
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #1 on: February 08, 2015, 08:17:06 pm »


               Hi,

don't know which dye script you use, but what I would add to your script is (if it doesn't exist):

Check if there is a our more of these flags, and if they exist on the original, set them to the copy too.


Don't have any code snippets around, but I could add them next morning (it's around nine a clock, and I'm right at home from a trip from north to south)...
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #2 on: February 08, 2015, 10:14:42 pm »


               

Conversely, if the item is supposed to be undroppable, why not just set it as plot as well so that it cannot even be dyed/altered to begin with?



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #3 on: February 09, 2015, 01:32:06 am »


               

1)I have no custom script of dye.


 


2) Very well. I forget to say, my item is marked as PLOT ITEM and UNDROPPABLE ITEM. Dye is allowing players give or drop my plot itens to others players (like an armor, helmet, etc).



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #4 on: February 09, 2015, 01:38:30 am »


               

The default scripts delete local variables when copying the object.  This might also affect flags.  Try putting a third parameter of TRUE into CopyObject().  If this does not work use GetItemCursedFlag() and SetItemCursedFlag() to transfer the droppable status.


 


Just to clarify, you are marking an item undroppable (cursed)  from the properties tab in the Toolset when creating/modifying the item, and not from the NPCs inventory in the Toolset (this droppable flag causes the item not to be dropped by the creature when it dies and has no impact on whether or not players can drop the item on the ground).



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #5 on: February 09, 2015, 01:45:37 am »


               

Hi,

don't know which dye script you use, but what I would add to your script is (if it doesn't exist):

Check if there is a our more of these flags, and if they exist on the original, set them to the copy too.


Don't have any code snippets around, but I could add them next morning (it's around nine a clock, and I'm right at home from a trip from north to south)...



 

I found the script used on 'UseDye' in nwn wikia (http://nwn.wikia.com/wiki/Dye_kit). This is intersting:


 



(script: x2_s2_dyearmor) dyeing an item causes it to lose its local variables. This can be changed by editing x2_s2_dyearmor, looking for "CopyItem", and adding TRUE as an additional parameter.



 

I added the bellow code to fix (on start of void main):

 



  if ((GetPlotFlag(oTarget) == TRUE) || (GetDroppableFlag(oTarget) == FALSE))
  {
    FloatingTextStringOnCreature("Invalid Target, must select a droppable and non plot item",oPC);
    return;
  }

 

Thank you WhiZard, kalbaern and dunahans.



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #6 on: February 09, 2015, 01:56:07 am »


               

The default scripts delete local variables when copying the object.  This might also affect flags.  Try putting a third parameter of TRUE into CopyObject().  If this does not work use GetItemCursedFlag() and SetItemCursedFlag() to transfer the droppable status.



 

 

Are you refering to change



object oNew = CopyItem(oTarget, IPGetIPWorkContainer(), TRUE);

to



object oNew = CopyObject(oTarget, GetLocation(oPC), oPC, GetTag(oTarget));

 or



  object oNew = CopyItem(oTarget, IPGetIPWorkContainer(), TRUE);
  SetPlotFlag(oNew, GetPlotFlag(oTarget));
  SetDroppableFlag(oNew, GetDroppableFlag(oTarget));
  DestroyObject(oTarget);

or is better do this



  if ((GetPlotFlag(oTarget) == TRUE) || (GetDroppableFlag(oTarget) == FALSE))
  {
    FloatingTextStringOnCreature("Invalid Target, must select a droppable and non plot item",oPC);
    return;
  }

?



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #7 on: February 09, 2015, 01:58:49 am »


               


 

 

Are you refering to change



object oNew = CopyItem(oTarget, IPGetIPWorkContainer(), TRUE);

to



object oNew = CopyObject(oTarget, GetLocation(oPC), oPC, GetTag(oTarget));

 or



  object oNew = CopyItem(oTarget, IPGetIPWorkContainer(), TRUE);
  SetPlotFlag(oNew, GetPlotFlag(oTarget));
  SetDroppableFlag(oNew, GetDroppableFlag(oTarget));
  DestroyObject(oTarget);

or is better do this



  if ((GetPlotFlag(oTarget) == TRUE) || (GetDroppableFlag(oTarget) == FALSE))
  {
    FloatingTextStringOnCreature("Invalid Target, must select a droppable and non plot item",oPC);
    return;
  }

?




 


This is the format, but GetDroppableFlag()/SetDroppableFlag() are not the functions you are looking for.  They determine if an NPC will drop the item when it dies.  You specifically need GetItemCursedFlag()/SetItemCursedFlag().


               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #8 on: February 09, 2015, 02:00:42 am »


               


This is the format, but GetDroppableFlag()/SetDroppableFlag() are not the functions you are looking for.  They determine if an NPC will drop the item when it dies.  You specifically need GetItemCursedFlag()/SetItemCursedFlag().




 


Thank you very much remembering. Quickly response. Is that I was missing here! I'll fix it right now! Again, many thanks.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #9 on: February 09, 2015, 02:03:46 am »


               

object oNew = CopyItem(oTarget, IPGetIPWorkContainer(), TRUE);
SetPlotFlag(oNew, GetPlotFlag(oTarget));
SetItemCursedFlag(oNew, GetItemCursedFlag(oTarget));
DestroyObject(oTarget);


 


This option is the one is the one that should do it.  Note that there is another CopyItem() toward the beginning of the script which also needs fixing.


 


EDIT: changing droppable to cursed function



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #10 on: February 09, 2015, 03:00:59 am »


               

Looks like CopyItem does not copy undroppable (Cursed in script editor) flag. It does copy plot flag though.


 


And btw the local variable issue was fixed in 1.70 already. Thats 4 years ago.


 


The code from Whizard will not fix the issue (not that he is wrong, just that there are three copies created), this code will fix it. I underlined and marked changes and new lines.


 


 


 


 


//::///////////////////////////////////////////////

//:: Dye Item Spellscript

//:: x2_s2_dyearmor

//:: Copyright © 2003 Bioware Corp.

//:://////////////////////////////////////////////

/*

    Spellscript for all Dye: Material Spells


    Some Notes:


    The color of the dye is taken from the

    last two letters of the item's tag


    The colortype which to change (cloth1, cloth2,

    leather1, ...) is determined by the spell ID


    Restrictions:

    - you cannot dye armor in combat

    - you can only dye armor && helmets

    - you can only dye items in your inventory

    - you can now dye cloaks as well


    - the IPWork container (see x2_inc_itemprop)

      must be set up for this to work properly


*/

//:://////////////////////////////////////////////

//:: Modified: Georg Zoeller, 24/03/2006 - Cloaks

//:: Created By: Georg Zoeller

//:: Created On: 2003-05-10

//:://////////////////////////////////////////////

/*

Patch 1.72


- fixed not copying local variables when dyeing an item

- fixed losing undroppable flag when dyeing an item

*/


#include "x2_inc_itemprop"

const int DYE_MAX_COLOR_INDEX = 175;


// Maps the Spell ID to the appropriate ITEM_APPR_ARMOR_COLOR_* constant

int GetApprArmorColorFromSpellID(int nID)

{

    switch (nID)

    {

        case 648 : return ITEM_APPR_ARMOR_COLOR_CLOTH1;

        case 649 : return ITEM_APPR_ARMOR_COLOR_CLOTH2;

        case 650 : return ITEM_APPR_ARMOR_COLOR_LEATHER1;

        case 651 : return ITEM_APPR_ARMOR_COLOR_LEATHER2;

        case 652 : return ITEM_APPR_ARMOR_COLOR_METAL1;

        case 653 : return ITEM_APPR_ARMOR_COLOR_METAL2;

    }

    return 0;

}



void FinishDyeScript(object oPC, object oTarget, int bEquipped, int nSlot)

{

  // Move the armor back from the IP Container

  object oNew = CopyItem(oTarget, oPC, TRUE);

  SetItemCursedFlag(oNew, GetItemCursedFlag(oTarget));

  DestroyObject(oTarget);

  //----------------------------------------------------------------------------

  // We need to remove all temporary item properties here

  //----------------------------------------------------------------------------


  IPRemoveAllItemProperties(oNew,DURATION_TYPE_TEMPORARY);

  // Reequip armor if it was equipped before

  if (bEquipped)

  {

    AssignCommand(oPC,ClearAllActions(TRUE));

    AssignCommand(oPC,ActionEquipItem(oNew,nSlot));

  }

}


void main()

{


  // declare major variables

  object oItem   = GetSpellCastItem();                  // The "dye" item that cast the spell

  object oPC     = OBJECT_SELF;                         // the user of the item

  object oTarget = GetSpellTargetObject();

  string sTag    = GetStringLowerCase(GetTag(oItem));

  // Determine the color to edit from the spell ID

  int nColorType =  GetApprArmorColorFromSpellID(GetSpellId());


  if (GetIsInCombat(oPC)) // abort if in combat

  {

        FloatingTextStrRefOnCreature(83352,oPC);         //"This item cannot be used in combat"

        return;

  }


  if ( GetObjectType(oTarget) != OBJECT_TYPE_ITEM || oTarget == OBJECT_INVALID)

  {

    FloatingTextStrRefOnCreature(83353,oPC);         //"Invalid Target, must select armor or helmet"

    return;

  }


  int nBase = GetBaseItemType(oTarget);


  // GZ@2006/03/26: Added cloak support

  if (  nBase != BASE_ITEM_ARMOR  && nBase != BASE_ITEM_HELMET && nBase != BASE_ITEM_CLOAK  )

  {

    FloatingTextStrRefOnCreature(83353,oPC);    //"Invalid Target, must select armor or helmet"

    return;

  }


  if (GetItemPossessor(oTarget) != oPC)

  {

       FloatingTextStrRefOnCreature(83354,oPC);    //"target must be in inventory"

       return;

  }



  // save if the item was equipped before the process

  int bEquipped;

  int nSlot;

  if (nBase == BASE_ITEM_HELMET )

  {

      nSlot = INVENTORY_SLOT_HEAD;

      bEquipped = (GetItemInSlot(nSlot,oPC) == oTarget);

  }

  // GZ@2006/03/26: Added cloak support

  else if (nBase == BASE_ITEM_CLOAK )

  {

      nSlot = INVENTORY_SLOT_CLOAK;

      bEquipped = (GetItemInSlot(nSlot,oPC) == oTarget);

  }

  else

  {

      nSlot = INVENTORY_SLOT_CHEST;

      bEquipped = (GetItemInSlot(nSlot,oPC) == oTarget);


  }





  // GZ@2006/03/26: Added new color palette support. Note: Will only work

  //                if craig updates the in engine functions as well.

  int nColor     =  0;


  // See if we find a valid int between 0 and 127 in the last three letters

  // of the tag, use it as color

  int nTest      =  StringToInt(GetStringRight(GetTag(oItem),3));

  if (nTest > 0 && nTest <= DYE_MAX_COLOR_INDEX )

  {

        nColor = nTest;

  }

  else //otherwise, use last two letters, as per legacy HotU

  {


        nColor = StringToInt(GetStringRight(GetTag(oItem),2));

  }



  // move the item into the IP work container

  object oNew = CopyItem(oTarget, IPGetIPWorkContainer(), TRUE);

  int nCursed = GetItemCursedFlag(oTarget);


  DestroyObject(oTarget);


  // Dye the armor

  oTarget = IPDyeArmor(oNew,nColorType, nColor);

  SetItemCursedFlag(oTarget,nCursed);

  DelayCommand(0.01f,FinishDyeScript(oPC,oTarget,bEquipped,nSlot));


}



               
               

               
            

Legacy_WhiteTiger

  • Hero Member
  • *****
  • Posts: 889
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #11 on: February 09, 2015, 04:36:27 am »


               

Excelent CPP getting into this! Updating my script of dye armor in 3... 2... 1...



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #12 on: February 09, 2015, 07:22:33 am »


               

Note that the same problem of cursed flag will still exist for craft armor and craft weapon when a player is modifying the appearance, although there the plot flag will block the appearance change.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #13 on: February 15, 2015, 09:45:58 am »


               


Note that the same problem of cursed flag will still exist for craft armor and craft weapon when a player is modifying the appearance, although there the plot flag will block the appearance change.




You are correct, plot flag block the appearance change but still crafting an appearance can be used to remove "cursed" item from character. Problem is that its not 100% possible to fix this other than blocking the appearance change for such item because there is a full inventory issue.


               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Item losing undroppable flag on use dye
« Reply #14 on: February 15, 2015, 10:09:01 pm »


               


Problem is that its not 100% possible to fix this other than blocking the appearance change for such item because there is a full inventory issue.




 


I wasn't even going to go there, but the full inventory issue applies just as much to the dyes as the appearance change from crafting as all weapons/armor can be equipped.