I am having some pretty serious trouble with the bladedamage mod. For some reason, my changes seem to cause bugs and I can't figure out why. If any coder is wanting to have a look at it, please DO! <img src="style_emoticons/<#EMO_DIR#>/piratesing.gif" style="vertical-align:middle" emoid="
" border="0" alt="piratesing.gif" />
Code is in LAi_events.c and INTERFACE\itemsbox.c in the latest modpack update (25 March) available from the Post Build 12 thread.
Any modder who would want to help out for a bit, please post here. <img src="style_emoticons/<#EMO_DIR#>/bow.gif" style="vertical-align:middle" emoid="
" border="0" alt="bow.gif" />
If somebody can figure out what's wrong, please do, because it isn't working the way it should. If anybody can code it in a better way, feel free to do so. I wouldn't be surprised if my code isn't very efficient.
Code from <i>void LAi_CharacterAttack()</i>:
<!--QuoteBegin-"Lai_events.c"+--><div class='quotetop'>QUOTE("Lai_events.c")</div><div class='quotemain'><!--QuoteEBegin--> // PB: Blade Damage mod
if(BLADEDAMAGE_ENABLED == 1 && attack.equip.blade != "bladeX4" && attack.location != "Tutorial_Deck")
{
if(!CheckAttribute(attack,"bladedamage.counter"))
{
if(sti(attack.index) == GetMainCharacterIndex())
{attack.bladedamage.counter = 0;}
else
{attack.bladedamage.counter = rand(BLADEDAMAGE_RAND + BLADEDAMAGE_BASE);}
}
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;
bool BladeBreak = false;
// Bladedamage based on the usage of your blade
// -------------------------------------------------------
int bladedamage_usage;
bladedamage_usage = attack.bladedamage.counter;
//LogIt("Bladedamage Usage = " + bladedamage_usage);
// Bladedamage based on your level vs the blade's minlevel
// -------------------------------------------------------
int bladedamage_level;
bladedamage_level = sti(weapon.minlevel) - sti(attack.rank);
if(bladedamage_level < 0) bladedamage_level = 0;
//LogIt("Bladedamage Level = " + bladedamage_level);
int total_chance;
total_chance = sti(bladedamage_usage) + sti(bladedamage_level);
if(total_chance > rand(BLADEDAMAGE_RAND) + BLADEDAMAGE_BASE)
{DecreaseQuality = true;}
//LogIt("Total chance points = " + total_chance + " for character " + attack.name + " " + attack.lastname);
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");
BladeBreak = true;
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;
}
if(BladeBreak)
{
if(sti(attack.index) != GetMainCharacterIndex() && !CheckAttribute(attack, "nodisarm") && attack.chr_ai.group != LAI_GROUP_PLAYER && !bAbordageStarted && rand(2) > 0)
{
LAi_SetCitizenTypeNoGroup(enemy);
}
else
{
if(!FindCharacterItemByGroup(attack, "bladeX4"))
{GiveItem2Character(attack, "bladeX4");}
EquipCharacterByItem(attack, "bladeX4");
}
}
}
}<!--QuoteEnd--></div><!--QuoteEEnd-->
Code from <i>void LAi_CharacterBlock()</i>:
<!--QuoteBegin-"Lai_events"+--><div class='quotetop'>QUOTE("Lai_events")</div><div class='quotemain'><!--QuoteEBegin--> // PB: Bladedamage mod -->
int bladedamage_usage;
int bladedamage_level;
int total_chance;
string BladeID;
string BladeBaseID;
string weaponID;
aref weapon;
bool DecreaseQuality;
bool BladeBreak = false;
// Code for the bladedamage for the enemy:
if(BLADEDAMAGE_ENABLED == 1 && enemy.equip.blade != "bladeX4" && enemy.location != "Tutorial_Deck")
{
if(!CheckAttribute(enemy,"bladedamage.counter"))
{
if(sti(enemy.index) == GetMainCharacterIndex())
{enemy.bladedamage.counter = 0;}
else
{enemy.bladedamage.counter = rand(BLADEDAMAGE_RAND + BLADEDAMAGE_BASE);}
}
enemy.bladedamage.counter = sti(enemy.bladedamage.counter) + 2;
// Counts the amount of strokes you performed with your blade
BladeID = enemy.equip.blade;
if (findSubStr(&BladeID, "+", 0) > -1 || findSubStr(&BladeID, "-", 0) > -1)
BladeBaseID = strcut(&BladeID, 0, strlen(BladeID) - 3);
else
BladeBaseID = BladeID;
weaponID = enemy.equip.blade ; // defines weaponname
weapon;
Items_FindItem(weaponID, &weapon); // defines object for weaponattributes
DecreaseQuality = false;
BladeBreak = false;
// Bladedamage based on the usage of your blade
// -------------------------------------------------------
bladedamage_usage = enemy.bladedamage.counter;
//LogIt("Bladedamage Usage = " + bladedamage_usage);
// Bladedamage based on your level vs the blade's minlevel
// -------------------------------------------------------
bladedamage_level = sti(weapon.minlevel) - sti(enemy.rank);
if(bladedamage_level < 0) bladedamage_level = 0;
//LogIt("Bladedamage Level = " + bladedamage_level);
total_chance = sti(bladedamage_usage) + sti(bladedamage_level);
if(total_chance > rand(BLADEDAMAGE_RAND) + BLADEDAMAGE_BASE)
{DecreaseQuality = true;}
//LogIt("Total chance points = " + total_chance + " for character " + enemy.name + " " + enemy.lastname);
if(DecreaseQuality)
{
RemoveCharacterEquip(enemy, BLADE_ITEM_TYPE);
TakeItemFromCharacter(enemy, BladeID);
enemy.bladedamage.counter = 0;
switch(GetItemQualityByID(BladeID))
{
case 0:
PlaySound("OBJECTS\duel\sword_broken.wav");
BladeBreak = true;
break;
case 1:
GiveItem2Character(enemy, BladeBaseID + "-2");
EquipCharacterByItem(enemy, BladeBaseID + "-2");
break;
case 2:
GiveItem2Character(enemy, BladeBaseID + "-1");
EquipCharacterByItem(enemy, BladeBaseID + "-1");
break;
case 3:
GiveItem2Character(enemy, BladeBaseID);
EquipCharacterByItem(enemy, BladeBaseID);
break;
case 4:
GiveItem2Character(enemy, BladeBaseID + "+1");
EquipCharacterByItem(enemy, BladeBaseID + "+1");
break;
case 5:
GiveItem2Character(enemy, BladeBaseID + "+2");
EquipCharacterByItem(enemy, BladeBaseID + "+2");
break;
}
if(BladeBreak)
{
if(sti(enemy.index) != GetMainCharacterIndex() && !CheckAttribute(enemy, "nodisarm") && enemy.chr_ai.group != LAI_GROUP_PLAYER && !bAbordageStarted && rand(2) > 0)
{
LAi_SetCitizenTypeNoGroup(enemy);
}
else
{
if(!FindCharacterItemByGroup(enemy, "bladeX4"))
{GiveItem2Character(enemy, "bladeX4");}
EquipCharacterByItem(enemy, "bladeX4");
}
}
}
}
// Code for the bladedamage for the attack:
if(BLADEDAMAGE_ENABLED == 1 && attack.equip.blade != "bladeX4" && attack.location != "Tutorial_Deck")
{
if(!CheckAttribute(attack,"bladedamage.counter"))
{
if(sti(attack.index) == GetMainCharacterIndex())
{attack.bladedamage.counter = 0;}
else
{attack.bladedamage.counter = rand(BLADEDAMAGE_RAND + BLADEDAMAGE_BASE);}
}
attack.bladedamage.counter = sti(attack.bladedamage.counter) + 2;
// Counts the amount of strokes you performed with your blade
BladeID = attack.equip.blade;
if (findSubStr(&BladeID, "+", 0) > -1 || findSubStr(&BladeID, "-", 0) > -1)
BladeBaseID = strcut(&BladeID, 0, strlen(BladeID) - 3);
else
BladeBaseID = BladeID;
weaponID = attack.equip.blade ; // defines weaponname
weapon;
Items_FindItem(weaponID, &weapon); // defines object for weaponattributes
DecreaseQuality = false;
BladeBreak = false;
// Bladedamage based on the usage of your blade
// -------------------------------------------------------
bladedamage_usage = attack.bladedamage.counter;
//LogIt("Bladedamage Usage = " + bladedamage_usage);
// Bladedamage based on your level vs the blade's minlevel
// -------------------------------------------------------
bladedamage_level = sti(weapon.minlevel) - sti(attack.rank);
if(bladedamage_level < 0) bladedamage_level = 0;
//LogIt("Bladedamage Level = " + bladedamage_level);
total_chance = sti(bladedamage_usage) + sti(bladedamage_level);
if(total_chance > rand(BLADEDAMAGE_RAND) + BLADEDAMAGE_BASE)
{DecreaseQuality = true;}
//LogIt("Total chance points = " + total_chance + " for character " + attack.name + " " + attack.lastname);
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");
BladeBreak = true;
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;
}
if(BladeBreak)
{
if(sti(attack.index) != GetMainCharacterIndex() && !CheckAttribute(attack, "nodisarm") && attack.chr_ai.group != LAI_GROUP_PLAYER && !bAbordageStarted && rand(2) > 0)
{
LAi_SetCitizenTypeNoGroup(attack);
}
else
{
if(!FindCharacterItemByGroup(attack, "bladeX4"))
{GiveItem2Character(attack, "bladeX4");}
EquipCharacterByItem(attack, "bladeX4");
}
}
}
}
// PB: Bladedamage mod <--<!--QuoteEnd--></div><!--QuoteEEnd-->
Code from <i>void InitInterface_RS(string iniName,ref itemsRef,string faceID)</i>:
<!--QuoteBegin-"itemsbox.c"+--><div class='quotetop'>QUOTE("itemsbox.c")</div><div class='quotemain'><!--QuoteEBegin--> // PB -->
bool HasFists = false;
if(GetCharacterEquipByGroup(itemsRef, BLADE_ITEM_TYPE) == "bladeX4")
{TakeItemFromCharacter(itemsRef, "bladeX4")
HasFists = true;}
// If character has fists equipped, take fists away and set HasFists true
if(FindCharacterItemByGroup(itemsRef, "bladeX4"))
{TakeItemFromCharacter(itemsRef, "bladeX4")}
// If character has fists, but didn't have them equipped, just take the fists away
// PB <--<!--QuoteEnd--></div><!--QuoteEEnd-->
Code from <i>void ProcessExit_yes()</i>:
<!--QuoteBegin-"itemsbox.c"+--><div class='quotetop'>QUOTE("itemsbox.c")</div><div class='quotemain'><!--QuoteEBegin--> // PB -->
if(HasFists)
{GiveItem2Character(attack, "bladeX4");
EquipCharacterByItem(attack, "bladeX4");}
// If character had fists equipped, give them back and equip them again
// PB <--<!--QuoteEnd--></div><!--QuoteEEnd-->