Ok I downloaded a module plan to use to play NWN with and to help me learn some thing about NWN scripting. I picked this module because it was a large PW that was mostly all done and it has some really nice scripts in it like the following
void fCheckItemBreakage(object oItem, int iBonus=0)
{
int iChance;
int iCharges = GetItemCharges(oItem);
object oPC = GetItemPossessor(oItem);
if(iCharges==0)
{
iCharges=50;
}
iCharges = iCharges - (d8(2));
iChance = -(iCharges) + iBonus + 20;
string sName = GetName(oItem);
if (d100(1)<=iChance || iCharges<=0)
{
DestroyObject(oItem);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_RESTORATION), oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SMOKE_PUFF), oPC);
AssignCommand(oPC, PlaySound("as_cv_claybreak3"));
DelayCommand(2.0, FloatingTextStringOnCreature(sName + " shatters!", oPC, FALSE));
}
else
{
SetItemCharges(oItem, iCharges);
DelayCommand(2.0, FloatingTextStringOnCreature(sName + " was damaged!", oPC, FALSE));
}
}
void fDoItemBreakage(object oPC)
{
//SendMessageToPC(oPC, "DEBUG - Durability check fired...");
if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_HEAD, oPC)) && d3(1)!=1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_HEAD, oPC));}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC)) && d3(1)!=1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC));}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC)) && d3(1)!=1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC));}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_LEFTRING, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_LEFTRING, oPC),30);}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oPC),30);}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_NECK, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_NECK, oPC),10);}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC));}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_ARMS, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_ARMS, oPC),10);}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_BELT, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_BELT, oPC),10);}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_BOOTS, oPC)) && d3(1)==1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_BOOTS, oPC),20);}
else if (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_CHEST, oPC)) && d3(1)!=1)
{fCheckItemBreakage(GetItemInSlot(INVENTORY_SLOT_CHEST, oPC),30);}
}
void fCheckDurabilityItem(object oItem, int iCombat)
{
if(!GetIsObjectValid(oItem))
{return;}
//int iDurTicker = 1; // How many hits before a charge minus
int iRandom;
if (iCombat==1)
{iRandom=d4(1);}
else
{iRandom=(d8(2)-1);}
if (iRandom==1) //supposed to be ==1
{
int iCharges = GetItemCharges(oItem);
if(iCharges==0)
{
SetItemCharges(oItem, 50);
return;
}
/*
int iCurrTick = GetLocalInt(oItem, "durability_ticker");
if (iCurrTick==0)
{
SetLocalInt(oItem, "durability_ticker",iDurTicker);
}
else
{
SetLocalInt(oItem, "durability_ticker",iCurrTick-1);
//SendMessageToPC(GetItemPossessor(oItem), "Durability tick " + GetName(oItem));
return;
}
*/
//SendMessageToPC(GetItemPossessor(oItem), "Durability " + GetName(oItem));
int iNewCharges = GetItemCharges(oItem)-1;
if (iNewCharges<=0)
{iNewCharges==0;}
object oPC = GetItemPossessor(oItem);
switch(iNewCharges)
{
case 49:
FloatingTextStringOnCreature(GetName(oItem) + " is no longer pristine condition", oPC, FALSE);
break;
case 40:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 35:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 30:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 25:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 20:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 15:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 10:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 5:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 3:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 2:
FloatingTextStringOnCreature(GetName(oItem) + " at " + IntToString(iNewCharges*2) + "%", oPC, FALSE);
break;
case 1:
FloatingTextStringOnCreature(GetName(oItem) + " is about to fall apart", oPC, FALSE);
break;
case 0:
FloatingTextStringOnCreature(GetName(oItem) + " has fallen apart!", oPC, FALSE);
break;
}
if (iNewCharges<=0)
{
DestroyObject(oItem);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_RESTORATION), oPC);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SMOKE_PUFF), oPC);
AssignCommand(oPC, PlaySound("as_cv_claybreak3"));
}
else
{
DelayCommand(1.0, SetItemCharges(oItem, iNewCharges));
}
}
}
void fDoDurabilityCheck(object oPC)
{
//SendMessageToPC(oPC, "DEBUG - Durability check fired...");
int iCombat;
if (GetIsInCombat(oPC))
{iCombat=1;}
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_ARMS, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_BELT, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_BOOTS, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_CHEST, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_HEAD, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_LEFTRING, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_RIGHTRING, oPC), iCombat);
fCheckDurabilityItem(GetItemInSlot(INVENTORY_SLOT_NECK, oPC), iCombat);
}
void fItemDurabilityHB(object oPC)
{
//SendMessageToPC(oPC, "Durability HB fired");
if (!GetIsDead(oPC) && GetCommandable(oPC))
{
if (d3(1)==1)
{
DelayCommand(IntToFloat(d3(1)), fDoDurabilityCheck(oPC));
return;
}
}
}
int fGetResRefQuality(object oItem)
{
return StringToInt(GetStringRight(GetResRef(oItem),3));
}
//void main(){}
First to me it looks like items have a %1 chance out of d100 to brake at 49, 40, 35, 30, 25, 20, 15, 10, 5, 3, 2, 1, 0. Am I right on this? Because if so I only want there to be a chance to brake on 0. So I that is the case then I should just be able to delete all the other lines right?
Second it looks to me that each item has 50 charges. because of the following lines I see in the script
if(iCharges==0)
{
iCharges=50;
}
and
int iCharges = GetItemCharges(oItem);
if(iCharges==0)
{
SetItemCharges(oItem, 50);
return;
}
I'm no scripter so I am just trying to read this and understand it. But these lines lead me to believe each items starts with 50 charges.
However I'm not sure what the lines are for or do
iCharges = iCharges - (d8(2));
iChance = -(iCharges) + iBonus + 20;
Now looking at the following lines
if (iCombat==1)
{iRandom=d4(1);}
else
{iRandom=(d8(2)-1);}
I'm also guessing that an item loses 1 + 1d4 or 1d8 charges per combat. Is that per creature they are in combat with? or is that per combat round? So if a fight lasts 10 rounds they would loss this each round?
So am I reading this right? I would like to make some changes to it but first I would like to know that I am reading it right so I could make the correct changes I would like to make.