Author Topic: Item breakage system?  (Read 504 times)

Legacy_slave of slaanesh

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Item breakage system?
« on: April 28, 2011, 02:26:21 am »


                Hi.  I am currently using a really useful weapon breakage system that i found on ign, but i recently installed cep 2.3 with a load more item catagories.  I have tried to include them into the script but cant get it to compile.  I know its a bit of a vague question, but can anyone help?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Item breakage system?
« Reply #1 on: April 28, 2011, 02:37:44 am »


               I know that right now I do not have time to look into anything to deep.  

In the spirit of getting you an answer however it would help if at bear minium you at least posted a link to the package on the vault.  Code snipets of what you are having trouble getting to compile and the error you are getting would also go a long way to getting you a responce.
               
               

               
            

Legacy_slave of slaanesh

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Item breakage system?
« Reply #2 on: April 29, 2011, 12:12:55 am »


               http://nwvault.ign.c...ad.php?id=72586

the code is:

/* Script Created By Rami_Ahmed */
/* Include file for Weapon Breakadge System */
#include "x2_inc_itemprop"

// Weakens oItem.
// if bDecrease is true (default) it will add decreases to the items.
// if bAll is true (false by default) it will weaken all inventory items instead of Helmet, Shield & Weapon
// if bRandomChance is 1, there is 25 percent chance of not getting item decreased
// if bRandomChance is 2, there is 50 percent chance of not getting item decreased
// if bRandomChance is 3, there is 75 percent chance of not getting item decreased
void WeakenItem(object oItem, int bAll = FALSE, int bDecrease = TRUE, int bRandomChance = 0);

// Destroys oItem and removes all ints from it.
void DestroyItem(object oItem);

// Sets nAmount break points on oItem, max nAmount to set is 100.
void SetBreakInt(object oItem, int nAmount);

// Reapairs oItem from any Decreases and resets Break Points to zero.
void RepairItem(object oItem, int bCost = 0);

// Returns TRUE If oItem is a weapon.
int GetIsWeapon(object oItem);

// Returns TRUE if oItem is a shield (TowerShield, LargeShield or SmallShield).
int GetIsShield(object oItem);

// Removes all -AC, -AB and -Damage Item Propertys from oItem.
void RemoveDecrease(object oItem);

// Returns the number of breakage points on oItem
int GetBreakInt(object oItem);

// Do not use! (only used in include file)
void WeaponSpecMakeDecrease(object oItem);

// // // // //
int GetBreakInt(object oItem)
{ return GetLocalInt(oItem, "Break_Amount");
}

void SetBreakInt(object oItem, int nAmount)
{ if (nAmount > 100) nAmount = 100;
 SetLocalInt(oItem, "Break_Amount", nAmount);
 if (GetBreakInt(oItem) >= 100)
 {  DestroyItem(oItem);
 }
}

void WeakenItem(object oItem, int bAll, int bDecrease, int bRandomChance)
{int nInt = GetBreakInt(oItem);
 object oPossesor = GetItemPossessor(oItem);
 if (bRandomChance == 1)
 {  if (d100() <= 25)
    {  return;
    }
 }
 else if (bRandomChance == 2)
 {  if (d100() <= 50)
    {  return;
    }
 }
 else if (bRandomChance == 3)
 {  if (d100() <= 75)
    {  return;
    }
 }
 if (bAll == FALSE)
 { if (nInt <= 50)
   { if (GetIsWeapon(oItem))
     { if (bDecrease)
       { IPSafeAddItemProperty(oItem, ItemPropertyAttackPenalty(1));
       }
       SetBreakInt(oItem, GetBreakInt(oItem) + 1);
       FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossesor, TRUE);
     }
     else if (GetBaseItemType(oItem) == BASE_ITEM_ARMOR)
     { if (bDecrease)
       { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_ARMOR, 1));
       }
       FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossesor, TRUE);
       SetBreakInt(oItem, GetBreakInt(oItem) + 1);
     }
     else if (GetIsShield(oItem))
     { if (bDecrease)
       { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_SHIELD, 1));
       }
       FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossesor, TRUE);
       SetBreakInt(oItem, GetBreakInt(oItem) + 1);
     }
   }
  else if (nInt >= 50)
   { if (GetIsWeapon(oItem))
     { if (bDecrease)
       { IPSafeAddItemProperty(oItem, ItemPropertyAttackPenalty(2));
       }
       FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossesor, TRUE);
       SetBreakInt(oItem, GetBreakInt(oItem) + 2);
    }
    else if (GetBaseItemType(oItem) == BASE_ITEM_ARMOR)
    {  if (bDecrease)
       { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_ARMOR, 2));
       }
       FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossesor, TRUE);
       SetBreakInt(oItem, GetBreakInt(oItem) + 2);
    }
    else if (GetIsShield(oItem))
    {  if (bDecrease)
       { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_SHIELD, 2));
       }
       FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossesor, TRUE);
       SetBreakInt(oItem, GetBreakInt(oItem) + 2);
    }
  }
}
else
{  int i; for (i; i <= NUM_INVENTORY_SLOTS; i++)
   {  object oWeaken = GetItemInSlot(i, oPossesor);
      if (GetIsObjectValid(oWeaken))
      {  if (bDecrease)
         {  WeaponSpecMakeDecrease(oWeaken);
         }
      }
   }
}
if (!GetIsObjectValid(GetItemPossessedBy(oPossesor, "wbs_breaktool")))
{  CreateItemOnObject("wbs_breaktool", oPossesor);
}
}
void WeaponSpecMakeDecrease(object oItem)
{ object oPossessor = GetItemPossessor(oItem);
 if (!GetIsObjectValid(oItem) || !GetIsObjectValid(oPossessor)) return;
 int nDecreaseWith;
 if (GetBreakInt(oItem) <= 50)
 { nDecreaseWith = 1;
 }
 else if (GetBreakInt(oItem) > 50)
 { nDecreaseWith = 2;
 }
 FloatingTextStringOnCreature("<caaa>Your "+GetName(oItem)+" slowly detoriates...</c>", oPossessor, TRUE);
 SetBreakInt(oItem, GetBreakInt(oItem) + nDecreaseWith);
 if (GetIsWeapon(oItem))
 { IPSafeAddItemProperty(oItem, ItemPropertyAttackPenalty(nDecreaseWith));
 }
 else if (GetBaseItemType(oItem) == BASE_ITEM_ARMOR || GetBaseItemType(oItem) == BASE_ITEM_BRACER)
 { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_ARMOR, nDecreaseWith));
 }
 else if (GetIsShield(oItem))
 { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_SHIELD, nDecreaseWith));
 }
 else if (GetBaseItemType(oItem) == BASE_ITEM_AMULET)
 { IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_NATURAL, nDecreaseWith));
 }
 else if (GetBaseItemType(oItem) == BASE_ITEM_BOOTS)
 {  IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_DODGE, nDecreaseWith));
 }
 else
 {  IPSafeAddItemProperty(oItem, ItemPropertyDecreaseAC(IP_CONST_ACMODIFIERTYPE_DEFLECTION, nDecreaseWith));
 }
}
void DestroyItem(object oItem)
{ int nInt = GetBreakInt(oItem);
 if (nInt >= 100)
 { DestroyObject(oItem, 0.1);
   FloatingTextStringOnCreature("<cæ>Your "+GetName(oItem)+" has broken.</c>", GetItemPossessor(oItem), TRUE);
 }
}

void RepairItem(object oItem, int bCost)
{ if (!GetIsObjectValid(oItem)) return;
 object oPC = GetItemPossessor(oItem);
 if (GetBreakInt(oItem) > 0)
 { if (GetGold(oPC) < bCost && bCost > 0)
   {  FloatingTextStringOnCreature("You dont have enough gold!", oPC);
     return;
   }
   TakeGoldFromCreature(bCost, oPC, TRUE);
   RemoveDecrease(oItem);
   FloatingTextStringOnCreature("<cä>Your "+GetName(oItem)+" has been repaired succesfully.</c>", oPC, TRUE);
   SetBreakInt(oItem, 0);
}
}
int GetIsWeapon(object oItem)
{ if (!GetIsObjectValid(oItem)) return FALSE;
 int bWeapon = FALSE;
 if (GetBaseItemType(oItem) == BASE_ITEM_BASTARDSWORD  || // if oItem is a Bastard Sword
     GetBaseItemType(oItem) == BASE_ITEM_BATTLEAXE     || // if oItem is a Battle Axe
     GetBaseItemType(oItem) == BASE_ITEM_CLUB          || // Etc...
     GetBaseItemType(oItem) == BASE_ITEM_DAGGER        ||
     GetBaseItemType(oItem) == BASE_ITEM_DIREMACE      ||
     GetBaseItemType(oItem) == BASE_ITEM_DOUBLEAXE     ||
     GetBaseItemType(oItem) == BASE_ITEM_DWARVENWARAXE ||
     GetBaseItemType(oItem) == BASE_ITEM_GREATAXE      ||
     GetBaseItemType(oItem) == BASE_ITEM_GREATSWORD    ||
     GetBaseItemType(oItem) == BASE_ITEM_HALBERD       ||
     GetBaseItemType(oItem) == BASE_ITEM_HANDAXE       ||
     GetBaseItemType(oItem) == BASE_ITEM_HEAVYFLAIL    ||
     GetBaseItemType(oItem) == BASE_ITEM_KAMA          ||
     GetBaseItemType(oItem) == BASE_ITEM_KATANA        ||
     GetBaseItemType(oItem) == BASE_ITEM_KUKRI         ||
     GetBaseItemType(oItem) == BASE_ITEM_LIGHTFLAIL    ||
     GetBaseItemType(oItem) == BASE_ITEM_LIGHTHAMMER   ||
     GetBaseItemType(oItem) == BASE_ITEM_LIGHTMACE     ||
     GetBaseItemType(oItem) == BASE_ITEM_LONGSWORD     ||
    // GetBaseItemType(oItem) == BASE_ITEM_MAGICSTAFF    ||  // Uncommented Magic Staff, didn't think it was under "Weapons"
     GetBaseItemType(oItem) == BASE_ITEM_MORNINGSTAR   ||
     GetBaseItemType(oItem) == BASE_ITEM_RAPIER        ||
     GetBaseItemType(oItem) == BASE_ITEM_SCIMITAR      ||
     GetBaseItemType(oItem) == BASE_ITEM_SCYTHE        ||
     GetBaseItemType(oItem) == BASE_ITEM_SHORTSPEAR    ||
     GetBaseItemType(oItem) == BASE_ITEM_SHORTSWORD    ||
     GetBaseItemType(oItem) == BASE_ITEM_SICKLE        ||
     GetBaseItemType(oItem) == BASE_ITEM_TWOBLADEDSWORD||
     GetBaseItemType(oItem) == BASE_ITEM_WARHAMMER     ||
     GetBaseItemType(oItem) == BASE_ITEM_WHIP )
     { bWeapon = TRUE;
     }
return bWeapon;
}

int GetIsShield(object oItem)
{ int bShield = FALSE;
 if (GetBaseItemType(oItem) == BASE_ITEM_TOWERSHIELD ||
     GetBaseItemType(oItem) == BASE_ITEM_LARGESHIELD ||
     GetBaseItemType(oItem) == BASE_ITEM_SMALLSHIELD )
   { bShield = TRUE;
   }
return bShield;
}
//
void RemoveDecrease(object oItem)
{ if (!GetIsObjectValid(oItem)) return;
 itemproperty ipLoop = GetFirstItemProperty(oItem);
 while (GetIsItemPropertyValid(ipLoop))
 { if ((GetItemPropertyType(ipLoop) == ITEM_PROPERTY_DECREASED_ATTACK_MODIFIER ||
       GetItemPropertyType(ipLoop) == ITEM_PROPERTY_DECREASED_DAMAGE          ||
       GetItemPropertyType(ipLoop) == ITEM_PROPERTY_DECREASED_AC) &&
       GetItemPropertyDurationType(ipLoop) == DURATION_TYPE_PERMANENT)
       { RemoveItemProperty(oItem, ipLoop);
       }
  ipLoop = GetNextItemProperty(oItem);
 }
}
/*
void main () {} // Only for error checking
*/

I tried adding the CEP base items underneath getbaseitem whip but it tells me that it is unable to compile because there is no right bracket but i put it in.
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Item breakage system?
« Reply #3 on: April 29, 2011, 12:50:31 am »


               At work right now but we use this system on our module and have not had a problem with cep 2.x at all. (We are curently cep 2.4)
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Item breakage system?
« Reply #4 on: April 29, 2011, 12:57:25 am »


               Instead of using get item type you may be able to use GetIsMeleeWeapon.
               
               

               
            

Legacy_slave of slaanesh

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Item breakage system?
« Reply #5 on: April 29, 2011, 01:05:28 am »


               how did you get the maul, nunchaku and the other weapons into the script TSMDude?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Item breakage system?
« Reply #6 on: April 29, 2011, 01:08:32 am »


               

ffbj wrote...

Instead of using get item type you may be able to use GetIsMeleeWeapon.


If I remember right GetIsMeleeWeapon is from one of the include files and is written about the same way this one is.  Unless cep has updated the include file.  I dont know I quit useing cep when they started all that stuff with the updater.

I may start useing it again since you can download it in one piece again. 


I would sugest that you replace the entire function

int GetIsWeapon(object oItem)
{ if (!GetIsObjectValid(oItem)) return FALSE;
int bWeapon = FALSE;
if (GetBaseItemType(oItem) == BASE_ITEM_BASTARDSWORD || // if oItem is a Bastard Sword
GetBaseItemType(oItem) == BASE_ITEM_BATTLEAXE || // if oItem is a Battle Axe
GetBaseItemType(oItem) == BASE_ITEM_CLUB || // Etc...
GetBaseItemType(oItem) == BASE_ITEM_DAGGER ||
GetBaseItemType(oItem) == BASE_ITEM_DIREMACE ||
GetBaseItemType(oItem) == BASE_ITEM_DOUBLEAXE ||
GetBaseItemType(oItem) == BASE_ITEM_DWARVENWARAXE ||
GetBaseItemType(oItem) == BASE_ITEM_GREATAXE ||
GetBaseItemType(oItem) == BASE_ITEM_GREATSWORD ||
GetBaseItemType(oItem) == BASE_ITEM_HALBERD ||
GetBaseItemType(oItem) == BASE_ITEM_HANDAXE ||
GetBaseItemType(oItem) == BASE_ITEM_HEAVYFLAIL ||
GetBaseItemType(oItem) == BASE_ITEM_KAMA ||
GetBaseItemType(oItem) == BASE_ITEM_KATANA ||
GetBaseItemType(oItem) == BASE_ITEM_KUKRI ||
GetBaseItemType(oItem) == BASE_ITEM_LIGHTFLAIL ||
GetBaseItemType(oItem) == BASE_ITEM_LIGHTHAMMER ||
GetBaseItemType(oItem) == BASE_ITEM_LIGHTMACE ||
GetBaseItemType(oItem) == BASE_ITEM_LONGSWORD ||
// GetBaseItemType(oItem) == BASE_ITEM_MAGICSTAFF || // Uncommented Magic Staff, didn't think it was under "Weapons"
GetBaseItemType(oItem) == BASE_ITEM_MORNINGSTAR ||
GetBaseItemType(oItem) == BASE_ITEM_RAPIER ||
GetBaseItemType(oItem) == BASE_ITEM_SCIMITAR ||
GetBaseItemType(oItem) == BASE_ITEM_SCYTHE ||
GetBaseItemType(oItem) == BASE_ITEM_SHORTSPEAR ||
GetBaseItemType(oItem) == BASE_ITEM_SHORTSWORD ||
GetBaseItemType(oItem) == BASE_ITEM_SICKLE ||
GetBaseItemType(oItem) == BASE_ITEM_TWOBLADEDSWORD||
GetBaseItemType(oItem) == BASE_ITEM_WARHAMMER ||
GetBaseItemType(oItem) == BASE_ITEM_WHIP )
{ bWeapon = TRUE;
}
return bWeapon;
}


This this one.

int GetIsWeapon(object oItem)
{
   if (!GetIsObjectValid(oItem)) return FALSE;
   int nCatagory = StringToInt(Get2DAString("baseitems","Category",GetBaseItemType(oItem)));
  
// Catagory 1 is melee weapons, Catagory 8 is staves.
   return (nCatagory == 1 || nCatagory == 8);
}


If you do not want to count the staves as weapons just remove the         "||nCatagory == 8"
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Item breakage system?
« Reply #7 on: April 29, 2011, 02:33:53 am »


               Pretty much as stated by ffjb as we added in a check/catch all. Though I think we did a if equipped way....
               
               

               


                     Modifié par TSMDude, 29 avril 2011 - 01:34 .
                     
                  


            

Legacy_slave of slaanesh

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Item breakage system?
« Reply #8 on: April 29, 2011, 11:20:15 am »


               I know i am an idiot for saying this but do i replace "baseitems" with the name of the base item?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Item breakage system?
« Reply #9 on: April 29, 2011, 12:44:15 pm »


               No,  You do not change anything in the function.  It is compleate needing no changes as it is.  

"baseitems" is the name of the 2da that the function uses to get the type of item that oItem is.  

so you no longer need  a long list of   baseitem == this  || baseitem == that
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Item breakage system?
« Reply #10 on: April 29, 2011, 11:04:55 pm »


               Ok I have added a bunch of constants to the function just to make it more human readable.  This will not change how the script compiles at all,  it will still compile to the same thing as the one I posted above.  Hopefully this will help you understand what is going on better. 

 const int CATEGORY_TYPE_NONE      =  0;
const int CATEGORY_TYPE_MELEE     =  1;
const int CATEGORY_TYPE_RANGED    =  2;
const int CATEGORY_TYPE_SHIELD    =  3;
const int CATEGORY_TYPE_ARMOR     =  4;
const int CATEGORY_TYPE_HELMET    =  5;
const int CATEGORY_TYPE_AMMO      =  6;
const int CATEGORY_TYPE_THROWN    =  7;
const int CATEGORY_TYPE_STAVES    =  8;
const int CATEGORY_TYPE_POTION    =  9;
const int CATEGORY_TYPE_SCROLL    = 10;
const int CATEGORY_TYPE_THIEVES_TOOLS  = 11;
const int CATEGORY_TYPE_MISC      = 12;
const int CATEGORY_TYPE_WANDS     = 13;
const int CATEGORY_TYPE_RODS      = 14;
const int CATEGORY_TYPE_TRAPS     = 15;
const int CATEGORY_TYPE_MISC_UNEQUIPPABLE = 16;
const int CATEGORY_TYPE_CONTAINER = 17;
const int CATEGORY_TYPE_HEALERS   = 19;

int GetIsWeapon(object oItem)
{
   if (!GetIsObjectValid(oItem)) return FALSE;
  
// This line gets the Category type for oItem from baseitems.2da.
   int nCatagory = StringToInt(Get2DAString("baseitems","Category",GetBaseItemType(oItem)));
   
  
   //Return TRUE if the nCatagory is a melee weapon or a staff.
   //Return FALSE if it is not.
   // Note: there is no need for an if statment here.
   //the compairson evaulates to the result we want to return.
   return (nCatagory == CATEGORY_TYPE_MELEE
                || nCatagory == CATEGORY_TYPE_STAVES);
}
 

 
               
               

               


                     Modifié par Lightfoot8, 29 avril 2011 - 10:06 .
                     
                  


            

Legacy_slave of slaanesh

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Item breakage system?
« Reply #11 on: April 29, 2011, 11:37:52 pm »


               Thank you so much for putting up with a total novice.
               
               

               
            

Legacy_Artistmonk

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +0/-0
Item breakage system?
« Reply #12 on: May 02, 2011, 11:43:20 pm »


               Slave where did you get original script from, do you have a link to it?
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Item breakage system?
« Reply #13 on: May 03, 2011, 12:27:40 am »


               I think this is the one he is referring too:

http://nwvault.ign.c....Detail&id=2929
               
               

               
            

Legacy_slave of slaanesh

  • Newbie
  • *
  • Posts: 36
  • Karma: +0/-0
Item breakage system?
« Reply #14 on: May 03, 2011, 11:41:02 pm »


               thats the one.