Here is a fix for abilities to avoid the erratic behavior with Toggle able skills to heal or buff a Hero unit. This code ensures that the unit will be reset upon death as well. You can only have a single unit on the map at a time but it works for hero units for RPG type stuff. The unit can be trained like any other unit at a barracks should it die.
The code below is set to apply the stats to every player, however, will apply the ability to player 1 exclusively. You would need to copy the “rule” block of code for every player that may have this unit and make copies of all the triggers for each respective player, along with a trigger variable for each respective player.
KR refers to the Elite Karambit Warrior
ETK refers to the Elite Teutonic Knight
I tried using the Elite Teutonic Knight and regular Teutonic Knight instead of the Karambit Warrior but “xsGetObjectCount” counts them as the same unit for whatever reason. Infact it does this for all Elite and regular units from what I can tell.
The reason I have triggers is because I couldn’t figure out a way to reset “Unit Trait” back to 0 via xsScript. Also I couldn’t figure out how to “refresh” the unit to reflect it has either had the unit trait 8 removed or added. So I had to make triggers to change the units formation in order to refresh the unit.
int P1_TankTimer = 12; // how long the cooldown is (change in the proceeding script as well
int P1_ETKbuffed = 0;
int P1_KRbuffed = 0;
int P1_TankHealTime = 11; // how long it will heal for (change in proceeding script as well)
//P1TANK--------------------------------------------------------------------------------------------------
rule P1_tankheal
active
minInterval 1
maxInterval 1
priority 1
group P1_herobuffs {
int P1_ETK = xsGetObjectCount(1, 25);
int P1_KR = xsGetObjectCount(1, 1123);
bool P1_HasETK = (P1_ETK > 0) && (P1_ETKbuffed == 0);
bool P1_HasKR = (P1_KR > 0) && (P1_KRbuffed == 0);
bool P1_ETKswapKR = (P1_ETKbuffed == 1) && (P1_KR == 1);
bool P1_KRswapETK = (P1_KRbuffed == 1) && (P1_ETK == 1);
bool P1_TankRe = (P1_ETK == 0) && (P1_KR == 0);
int a = xsTriggerVariable(9);
if (P1_TankRe == true && a == 1){
P1_ETKbuffed = 0;
P1_KRbuffed = 0;
P1_TankTimer = 12;
P1_TankHealTime = 11;
xsEffectAmount(cSetAttribute, 1125, 120, 0, 1);
xsEffectAmount(cSetAttribute, 554, 120, 0, 1);
xsEffectAmount(cAddAttribute, 1125, 54, 8, 1);
xsSetTriggerVariable(9, 2);
}
if (P1_TankRe == true && a == 2){
P1_ETKbuffed = 0;
P1_KRbuffed = 0;
P1_TankTimer = 12;
P1_TankHealTime = 11;
xsEffectAmount(cSetAttribute, 1125, 120, 0, 1);
xsEffectAmount(cSetAttribute, 554, 120, 0, 1);
}
if (P1_TankRe == true && a == 3){
P1_ETKbuffed = 0;
P1_KRbuffed = 0;
P1_TankTimer = 12;
P1_TankHealTime = 11;
xsEffectAmount(cSetAttribute, 1125, 120, 0, 1);
xsEffectAmount(cSetAttribute, 554, 120, 0, 1);
xsSetTriggerVariable(9, 2);
}
if (P1_HasETK == true){
P1_TankTimer--;
if(P1_TankTimer < 1){
xsEffectAmount(cAddAttribute, 554, 54, 8, 1);
P1_TankTimer = 12;
P1_KRbuffed = 0;
P1_ETKbuffed = 1;
xsSetTriggerVariable(9, 0);
}
}
if (P1_ETKswapKR == true){
P1_TankHealTime--;
xsEffectAmount(cSetAttribute, 1125, 120, 6, 1);
xsSetTriggerVariable(9, 1);
if (P1_TankHealTime < 1 && P1_ETKbuffed == 1){
xsEffectAmount(cSetAttribute, 1125, 120, 0, 1);
P1_KRbuffed = 0;
P1_ETKbuffed = 0;
P1_TankHealTime = 11;
}
}
if (P1_HasKR == true){
P1_TankTimer--;
if (P1_TankTimer < 1){
xsEffectAmount(cAddAttribute, 1125, 54, 8, 1);
P1_TankTimer = 12;
P1_ETKbuffed = 0;
P1_KRbuffed = 1;
xsSetTriggerVariable(9, 3);
}
}
if (P1_KRswapETK == true){
P1_TankHealTime--;
xsEffectAmount(cSetAttribute, 554, 120, 6, 1);
xsSetTriggerVariable(9, 2);
if (P1_TankHealTime < 1 && P1_KRbuffed == 1){
xsEffectAmount(cSetAttribute, 554, 120, 0, 1);
P1_ETKbuffed = 0;
P1_KRbuffed = 0;
P1_TankHealTime = 11;
}
}
}
void addTankStats(){
//tank----------------------------------------------------------------------------------------------------
xsEffectAmount(cEnableObject, 554, cAttributeEnable, 0);
xsEffectAmount(cSetAttribute, 554, cNameId, 5636, -1);
xsEffectAmount(cSetAttribute, 554, cIconId, 379, -1);
xsEffectAmount(cSetAttribute, 554, cShownAttack, 20, -1);
xsEffectAmount(cSetAttribute, 554, cShownRange, .25, -1);
xsEffectAmount(cSetAttribute, 554, cShownMeleeArmor, 10, -1);
xsEffectAmount(cSetAttribute, 554, cShownPierceArmor, 5, -1);
xsEffectAmount(cSetAttribute, 554, cHitpoints, 170, -1);
xsEffectAmount(cSetAttribute, 554, cArmor, 3*256+5, -1);
xsEffectAmount(cSetAttribute, 554, cArmor, 4*256+10, -1);
xsEffectAmount(cSetAttribute, 554, cAttack, 4*256+20, -1);
xsEffectAmount(cSetAttribute, 554, cAttackReloadTime, 2, -1);
xsEffectAmount(cSetAttribute, 554, cMaxRange, 0, -1);
xsEffectAmount(cSetAttribute, 554, cLineOfSight, 3, -1);
xsEffectAmount(cSetAttribute, 554, cMovementSpeed, .85, -1);
xsEffectAmount(cSetAttribute, 554, cMaxCharge, 1, -1);
xsEffectAmount(cSetAttribute, 554, cRechargeRate, .02, -1);
xsEffectAmount(cSetAttribute, 554, cChargeEvent, 10, -1);
xsEffectAmount(cSetAttribute, 554, cChargeType, 0, -1);
xsEffectAmount(cSetAttribute, 554, cCombatAbility, 96, -1);
xsEffectAmount(cSetAttribute, 554, cSearchRadius, 4, -1);
xsEffectAmount(cSetAttribute, 554, cHeroStatus, 32, -1);
xsEffectAmount(cSetAttribute, 554, 121, 97, -1);
xsEffectAmount(cSetAttribute, 554, 122, 19221, -1);
xsEffectAmount(cSetAttribute, 554, 123, 19221, -1);
xsEffectAmount(cSetAttribute, 554, cTraitPiece, 1125, -1);
xsEffectAmount(cEnableObject, 1125, cAttributeEnable, 0);
xsEffectAmount(cSetAttribute, 1125, cNameId, 5636, -1);
xsEffectAmount(cSetAttribute, 1125, cIconId, 379, -1);
xsEffectAmount(cSetAttribute, 1125, cDeadUnitId, 181, -1);
xsEffectAmount(cSetAttribute, 1125, cStandingGraphic, 1509, -1);
xsEffectAmount(cSetAttribute, 1125, cDyingGraphic, 1508, -1);
xsEffectAmount(cSetAttribute, 1125, cWalkingGraphic, 1511, -1);
xsEffectAmount(cSetAttribute, 1125, cAttackGraphic, 1506, -1);
xsEffectAmount(cSetAttribute, 1125, cAttack2Graphic, 1507, -1);
xsEffectAmount(cSetAttribute, 1125, cShownAttack, 20, -1);
xsEffectAmount(cSetAttribute, 1125, cShownRange, .25, -1);
xsEffectAmount(cSetAttribute, 1125, cShownMeleeArmor, 10, -1);
xsEffectAmount(cSetAttribute, 1125, cShownPierceArmor, 5, -1);
xsEffectAmount(cSetAttribute, 1125, cHitpoints, 170, -1);
xsEffectAmount(cSetAttribute, 1125, cArmor, 3*256+5, -1);
xsEffectAmount(cSetAttribute, 1125, cArmor, 4*256+10, -1);
xsEffectAmount(cSetAttribute, 1125, cAttack, 4*256+20, -1);
xsEffectAmount(cSetAttribute, 1125, cAttack, 29*256+4, -1);
xsEffectAmount(cSetAttribute, 1125, cAttack, 21*256+4, -1);
xsEffectAmount(cSetAttribute, 1125, cAttackReloadTime, 2, -1);
xsEffectAmount(cSetAttribute, 1125, cMaxRange, 0, -1);
xsEffectAmount(cSetAttribute, 1125, cLineOfSight, 3, -1);
xsEffectAmount(cSetAttribute, 1125, cMovementSpeed, .85, -1);
xsEffectAmount(cSetAttribute, 1125, cMaxCharge, 1, -1);
xsEffectAmount(cSetAttribute, 1125, cRechargeRate, .02, -1);
xsEffectAmount(cSetAttribute, 1125, cChargeEvent, 10, -1);
xsEffectAmount(cSetAttribute, 1125, cChargeType, 0, -1);
xsEffectAmount(cSetAttribute, 1125, cCombatAbility, 96, -1);
xsEffectAmount(cSetAttribute, 1125, cSearchRadius, 4, -1);
xsEffectAmount(cSetAttribute, 1125, cHeroStatus, 32, -1);
xsEffectAmount(cSetAttribute, 1125, 121, 97, -1);
xsEffectAmount(cSetAttribute, 1125, 122, 19221, -1);
xsEffectAmount(cSetAttribute, 1125, 123, 19221, -1);
xsEffectAmount(cSetAttribute, 1125, cTraitPiece, 554, -1);
}