By the way, could any of you wise guys tell me what's wrong with this custom x2_s3_onhitcast script please? The code works most of the time, only, and I know it's far from being optimized anyway. I wished to avoid using the OR(||) operator and any include, to keep the script small and fast, yet I find the whole thing rather ugly...
void main()
{
object oItem = GetSpellCastItem(); // The item casting triggering this spellscript
int nType = GetBaseItemType(oItem);
if(nType == BASE_ITEM_ARMOR) return; //Only melee weapons and gloves degrade for now
if(nType == BASE_ITEM_TOWERSHIELD) return;
if(nType == BASE_ITEM_LARGESHIELD) return;
if(nType == BASE_ITEM_SMALLSHIELD) return;
int nMat = GetLocalInt(oItem, "Material");
if(nMat == 100000) return; //Jeweled weapons do not degrade
if(GetTag(oItem) == "ITM_DRAGGAUNTLET") return; //Same for dragon gauntlets
int nHealth = GetLocalInt(oItem, "Health");
if(nHealth == 0) //Destroy oItem if health goes lower than 0
{
DestroyObject(oItem);
return;
}
SetLocalInt(oItem, "Health", nHealth-1); //Decrement weapon's health
int nMax = (nHealth * 10 / nMat)+1; // max "sharpness" allowed according to health(each 10% = +1)
int ipMagn, ipDur;
itemproperty ip = GetFirstItemProperty(oItem);
while(GetIsItemPropertyValid(ip))
{
int nType = GetItemPropertyType(ip);
if(nType == ITEM_PROPERTY_ATTACK_BONUS)
{
ipMagn = GetItemPropertyCostTableValue(ip);
ipDur = GetItemPropertyDurationType(ip);
if(ipMagn > nMax)
{
RemoveItemProperty(oItem, ip);
AddItemProperty(ipDur, ItemPropertyAttackBonus(nMax), oItem);
}
}
else if(nType == ITEM_PROPERTY_ENHANCEMENT_BONUS)
{
ipMagn = GetItemPropertyCostTableValue(ip);
ipDur = GetItemPropertyDurationType(ip);
if(ipMagn > nMax)
{
RemoveItemProperty(oItem, ip);
AddItemProperty(ipDur, ItemPropertyEnhancementBonus(nMax), oItem);
}
}
ip = GetNextItemProperty(oItem);
}
string sMat = GetLocalString(oItem, "MatName");
SetName(oItem, sMat + " " + GetName(oItem, TRUE) + "(" + IntToString(nHealth) + ")");
/* Commented out to avoid a function call for the code above
if (GetIsObjectValid(oItem))
{
// * Generic Item Script Execution Code
// * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
// * it will execute a script that has the same name as the item's tag
// * inside this script you can manage scripts for all events by checking against
// * GetUserDefinedItemEventNumber(). See x2_it_example.nss
if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
{
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ONHITCAST);
int nRet = ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
if (nRet == X2_EXECUTE_SCRIPT_END)
{
return;
}
}
}
*/
}
You have my humble thanks, dear reader.
Kato
Modifié par Kato_Yang, 12 juin 2011 - 08:06 .