Item breakage system?
#1
Posté 28 avril 2011 - 01:26
#2
Posté 28 avril 2011 - 01:37
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.
#3
Posté 28 avril 2011 - 11:12
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.
#4
Posté 28 avril 2011 - 11:50
#5
Posté 28 avril 2011 - 11:57
#6
Posté 29 avril 2011 - 12:05
#7
Posté 29 avril 2011 - 12:08
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"
#8
Posté 29 avril 2011 - 01:33
Modifié par TSMDude, 29 avril 2011 - 01:34 .
#9
Posté 29 avril 2011 - 10:20
#10
Posté 29 avril 2011 - 11:44
"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
#11
Posté 29 avril 2011 - 10:04
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 .
#12
Posté 29 avril 2011 - 10:37
#13
Posté 02 mai 2011 - 10:43
#14
Posté 02 mai 2011 - 11:27
#15
Posté 03 mai 2011 - 10:41
#16
Posté 04 mai 2011 - 03:19





Retour en haut






