Thanks to CCC, I have been able to continue with this mod. I made the basics now and am trying to translate some of my additional ideas into the code. However, at the moment I am a bit confused about how to actually code it in. I tried some things in below part of code, but I think I must think of something better than this. If you have any comments, please say so.
Please note: This code is not ready for use in the game yet; I don't know what would happen using this code gameplay-wise, but it won't be right. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/no.gif" style="vertical-align:middle" emoid="
" border="0" alt="no.gif" />
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> // PB: Blade Damage mod
if(!CheckAttribute(attack,"bladedamage.counter")) {attack.bladedamage.counter = 0;}
attack.bladedamage.counter = sti(attack.bladedamage.counter) + 1;
// Counts the amount of strokes you performed with your blade
string BladeID = attack.equip.blade;
string BladeBaseID;
if (findSubStr(&BladeID, "+", 0) > -1 || findSubStr(&BladeID, "-", 0) > -1)
BladeBaseID = strcut(&BladeID, 0, strlen(BladeID) - 3);
else
BladeBaseID = BladeID;
bool DecreaseQuality = false;
int breakchance_quality_scalar;
switch(GetItemQualityByID(BladeID))
// Better quality blades have lower chances of breaking
// IMPORTANT: settings need to be finetuned for gamebalancing
{
case 0: breakchance_quality_scalar = 1.00; break;
case 1: breakchance_quality_scalar = 0.90; break;
case 2: breakchance_quality_scalar = 0.75; break;
case 3: breakchance_quality_scalar = 0.50; break;
case 4: breakchance_quality_scalar = 0.30; break;
case 5: breakchance_quality_scalar = 0.10; break;
}
int breakchance_level_scalar;
// If a blade is too good for your level, the breaking chance will increase
// Note: weapon.minlevel ranges from 0 (dagger and saber) to 25 (bosun's choice)
breakchance_level_scalar = weapon.minlevel / 100;
int breakchance = breakchance_quality_scalar + breakchance_level_scalar;
if(sti(attack.bladedamage.counter) > breakchance)
{DecreaseQuality = true;}
if(attack.equip.blade != "bladeX4") DecreaseQuality = false;
// If attack is fighting with fists, the blade quality should not be decreased
if(DecreaseQuality)
{
RemoveCharacterEquip(attack, BLADE_ITEM_TYPE);
TakeItemFromCharacter(attack, BladeID);
attack.bladedamage.counter = 0;
switch(GetItemQualityByID(BladeID))
{
case 0:
PlaySound("OBJECTS\duel\sword_broken.wav");
if(FindCharacterItemByGroup(attack, BLADE_ITEM_TYPE) == "")
{GiveItem2Character(attack, "bladeX4");}
EquipCharacterByItem(attack, "bladeX4");
break;
case 1:
GiveItem2Character(attack, BladeBaseID + "-2");
EquipCharacterByItem(attack, BladeBaseID + "-2");
break;
case 2:
GiveItem2Character(attack, BladeBaseID + "-1");
EquipCharacterByItem(attack, BladeBaseID + "-1");
break;
case 3:
GiveItem2Character(attack, BladeBaseID);
EquipCharacterByItem(attack, BladeBaseID);
break;
case 4:
GiveItem2Character(attack, BladeBaseID + "+1");
EquipCharacterByItem(attack, BladeBaseID + "+1");
break;
case 5:
GiveItem2Character(attack, BladeBaseID + "+2");
EquipCharacterByItem(attack, BladeBaseID + "+2");
break;
}
}<!--c2--></div><!--ec2-->
If you want to give an early version of this mod a try, add the following code to LAi_events.c:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--> // PB: Blade Damage mod
if(!CheckAttribute(attack,"bladedamage.counter")) {attack.bladedamage.counter = 0;}
attack.bladedamage.counter = sti(attack.bladedamage.counter) + 1;
// Counts the amount of strokes you performed with your blade
string BladeID = attack.equip.blade;
string BladeBaseID;
if (findSubStr(&BladeID, "+", 0) > -1 || findSubStr(&BladeID, "-", 0) > -1)
BladeBaseID = strcut(&BladeID, 0, strlen(BladeID) - 3);
else
BladeBaseID = BladeID;
bool DecreaseQuality = false;
if(sti(attack.bladedamage.counter) > 5)
{DecreaseQuality = true;}
if(DecreaseQuality)
{
RemoveCharacterEquip(attack, BLADE_ITEM_TYPE);
TakeItemFromCharacter(attack, BladeID);
attack.bladedamage.counter = 0;
switch(GetItemQualityByID(BladeID))
{
case 0:
PlaySound("OBJECTS\duel\sword_broken.wav");
if(FindCharacterItemByGroup(attack, BLADE_ITEM_TYPE) == "")
{GiveItem2Character(attack, "bladeX4");}
EquipCharacterByItem(attack, "bladeX4");
break;
case 1:
GiveItem2Character(attack, BladeBaseID + "-2");
EquipCharacterByItem(attack, BladeBaseID + "-2");
break;
case 2:
GiveItem2Character(attack, BladeBaseID + "-1");
EquipCharacterByItem(attack, BladeBaseID + "-1");
break;
case 3:
GiveItem2Character(attack, BladeBaseID);
EquipCharacterByItem(attack, BladeBaseID);
break;
case 4:
GiveItem2Character(attack, BladeBaseID + "+1");
EquipCharacterByItem(attack, BladeBaseID + "+1");
break;
case 5:
GiveItem2Character(attack, BladeBaseID + "+2");
EquipCharacterByItem(attack, BladeBaseID + "+2");
break;
}
}<!--c2--></div><!--ec2-->
This code will decrease the quality of anyone's blade after five strokes with the blade. Eventually it will break.
I will be continuing work on this mod later. I hope to think of a better way to add the influence of character level, blade quality and some randomness as well.