Unit flees when custom ability is triggered

So i added this block of code to edit an elite samurai.

void addSamarmor {

xsEffectAmount(cSetAttribute, 560, cMaxCharge, 1, 1);
xsEffectAmount(cSetAttribute, 560, cRechargeRate, .01, 1);
xsEffectAmount(cSetAttribute, 560, cChargeEvent, 25, 1);
xsEffectAmount(cSetAttribute, 560, cChargeType, -3, 1);
xsEffectAmount(cSetAttribute, 560, cCombatAbility, 97, 1);

xsTaskAmount(0, 5); // samurai buff
xsTaskAmount(1, 1);
xsTaskAmount(2, 25);
xsTaskAmount(3, 1);
xsTaskAmount(5, 10);
xsTaskAmount(6, 0);

xsTaskAmount(4, 117);
xsTask(560, 155, 906);
}

For some odd reason when the ability is triggered the unit flees when tasked.

I observed Zhang Fei (Hero) and he seems to stop moving when activating this skill. Im assuming this is why.

It’s not only custom task, the hero too but it’s worst than that and isn’t fleeing.

It’s a pathfinding issue ai issue. They’ve added a thing for ai priority logic and I suspect it to actually not be totally stable.

The hero you’ve mentioned seems to … How to say… “Go the oposite”, as in …He’s returning to where it was before ? Or inverted coordinate ?

I also saw my scouts in the el dorado mod version not obeying when I tell my group of unit including scouts and conquistador to attack building, the scouts are sometime just staying idle as if they brain heard “FIRE” instead of “ATTACK” so only ranged attacks.

Maybe it’s a new feature intended to work like that, well the fleeing I doubt, but pathfinding isn’t perfect, we know that for long.

Try reporting the issue using the hero unit, without modifying anything on it. And you know what, I think I know what’s happenning.

When I had the issue, I made my hero attack a building with regular attack, so he was “attack moving”, the unit stores where he was before he started that I think, it’s related to stances so defense stance can return to their origin points.
Yeah, confirming it’s that, I think the unit transform into another, return to the point it was previously as a “not atacking unit”, like last time it was idle / normal / out of combat, then process the attacking move. I think here the issue is that the unit information are, how to say, the process of the attack move is stopped and the unit panic abit so it fall back to the previous “stable” state it had and then redo the task it was doing before you pressed the ability. (The hero I’ve used is Guan Yu)

We’d need someone filming it, personally I can’t record it with my computer.

Yeah, thats pretty much was I was experiencing. Acouple of instances the unit actually executed a patrol action when they weren’t tasked to attack something but instead tasked to move. Ill try to get a video.

Never mind I think you are right!

Here is a video of the action mentioned above.


Here is a work around I did via 4 triggers for a temporary transform effect. This solved four issues I was having

  1. After transforming from a ranged unit to a melee unit. The unit would continue using ranged attacks or abilities they no longer have. For this instance healing. After transforming from a Warrior Priest to an Elite Berserk the transforming the unit would continue healing. The “Replace Object” trigger resolves that issue by refreshing the unit in some way.

  2. The unit would have erratic movements after using the “Charge Type -1”. This currently happens for any ability related to user activated “Charge Abilities”. When a user actives the charged ability while the unit is tasked to move it will cause some kind of error and the unit will attempt to go to a previous location. There was one issue though. After replacing the object the unit would not refresh its ability till it was idle once again leading to solution 3.

  3. The unit would not refresh “Trait 8(transform)” until it was idle. The solution for this was to task the unit to change formation. I went this route instead of using an action like “Stop” or “Freeze” because it would allow the user to continue controlling the unit without it randomly stopping.

  4. Resolves the erratic behavior of the " Active Temporary Transformation" ability.

Code for the units as follows:

xsEffectAmount(cEnableObject, 1811, cAttributeEnable, 0); //healer ranged
xsEffectAmount(cSetAttribute, 1811, cNameId, 5634, 1);
xsEffectAmount(cSetAttribute, 1811, cIconId, 420, 1);
xsEffectAmount(cSetAttribute, 1811, cSpecialGraphic, 12947, 1);
xsEffectAmount(cSetAttribute, 1811, cAttackGraphic, 12246, 1);
xsEffectAmount(cSetAttribute, 1811, cShownAttack, 20, 1);
xsEffectAmount(cSetAttribute, 1811, cShownRange, 9, 1);
xsEffectAmount(cSetAttribute, 1811, cShownMeleeArmor, 4, 1);
xsEffectAmount(cSetAttribute, 1811, cShownPierceArmor, 0, 1);
xsEffectAmount(cSetAttribute, 1811, cHitpoints, 110, 1);
xsEffectAmount(cSetAttribute, 1811, cArmor, 3256+0, 1);
xsEffectAmount(cSetAttribute, 1811, cArmor, 4
256+4, 1);
xsEffectAmount(cSetAttribute, 1811, cArmor, 25256+100, 1);
xsEffectAmount(cSetAttribute, 1811, cAttack, 4
256+20, 1);
xsEffectAmount(cSetAttribute, 1811, cAttackReloadTime, 2, 1);
xsEffectAmount(cSetAttribute, 1811, cLineOfSight, 7, 1);
xsEffectAmount(cSetAttribute, 1811, cMovementSpeed, 1, 1);
xsEffectAmount(cSetAttribute, 1811, cRegenerationRate, 25, 1);
xsEffectAmount(cSetAttribute, 1811, cSearchRadius, 7, 1);
xsEffectAmount(cSetAttribute, 1811, cWorkRate, 2, 1);
xsEffectAmount(cSetAttribute, 1811, cAttackDelay, 10, 1);
xsEffectAmount(cSetAttribute, 1811, cMaxRange, 9, 1);
xsEffectAmount(cSetAttribute, 1811, cProjectileUnit, 469, 1);
xsEffectAmount(cModResource, cAttributeHealRateModifer, cAttributeAdd, 3, 1);
xsEffectAmount(cModResource, cAttributeHealRange, cAttributeAdd, 2, 1);
xsEffectAmount(cSetAttribute, 1811, cTraitPiece, 694, 1);
xsEffectAmount(cSetAttribute, 1811, cHeroStatus, 96, 1);

xsEffectAmount(cSetAttribute, 469, cProjectileArc, .1, 1);
xsEffectAmount(cSetAttribute, 469, cMovementSpeed, 7.5, 1);
xsEffectAmount(cSetAttribute, 469, cHitMode, 1, 1);
xsEffectAmount(cSetAttribute, 469, cVanishMode, 0, 1);
xsEffectAmount(cSetAttribute, 469, cAreaDamage, 1, 1);

xsEffectAmount(cEnableObject, 694, cAttributeEnable, 0); //healer melee
xsEffectAmount(cSetAttribute, 694, cNameId, 5634, 1);
xsEffectAmount(cSetAttribute, 694, cIconId, 420, 1);
xsEffectAmount(cSetAttribute, 694, cSpecialGraphic, 12947, 1);
xsEffectAmount(cSetAttribute, 694, cDeadUnitId, 1812, 1);
xsEffectAmount(cSetAttribute, 694, cStandingGraphic, 12630, 1);
xsEffectAmount(cSetAttribute, 694, cDyingGraphic, 12629, 1);
xsEffectAmount(cSetAttribute, 694, cWalkingGraphic, 12632, 1);
xsEffectAmount(cSetAttribute, 694, cAttackGraphic, 12628, 1);
xsEffectAmount(cSetAttribute, 694, 131, 12628, 1);
xsEffectAmount(cSetAttribute, 694, cShownAttack, 15, 1);
xsEffectAmount(cSetAttribute, 694, cShownRange, 0, 1);
xsEffectAmount(cSetAttribute, 694, cShownMeleeArmor, 4, 1);
xsEffectAmount(cSetAttribute, 694, cShownPierceArmor, 0, 1);
xsEffectAmount(cSetAttribute, 694, cHitpoints, 110, 1);
xsEffectAmount(cSetAttribute, 694, cArmor, 3256+0, 1);
xsEffectAmount(cSetAttribute, 694, cArmor, 4
256+4, 1);
xsEffectAmount(cSetAttribute, 694, cAttack, 4*256+15, 1);
xsEffectAmount(cSetAttribute, 694, cAttackReloadTime, 1.9, 1);
xsEffectAmount(cSetAttribute, 694, cLineOfSight, 7, 1);
xsEffectAmount(cSetAttribute, 694, cMovementSpeed, 1, 1);
xsEffectAmount(cSetAttribute, 694, cRegenerationRate, 150, 1);
xsEffectAmount(cSetAttribute, 694, cSearchRadius, 4, 1);
xsEffectAmount(cSetAttribute, 694, cMaxRange, 0, 1);
xsEffectAmount(cSetAttribute, 694, cTraitPiece, 1811, 1);
xsEffectAmount(cSetAttribute, 694, 121, 014, 1);
xsEffectAmount(cSetAttribute, 694, cHeroStatus, 32, 1);

xsEffectAmount(cSetAttribute, 1831, cNameId, 5634, 1); //healer relic
xsEffectAmount(cSetAttribute, 1831, cIconId, 420, 1);
xsEffectAmount(cSetAttribute, 1831, cDeadUnitId, 1662, 1);
xsEffectAmount(cSetAttribute, 1831, cShownMeleeArmor, 4, 1);
xsEffectAmount(cSetAttribute, 1831, cShownPierceArmor, 0, 1);
xsEffectAmount(cSetAttribute, 1831, cHitpoints, 110, 1);
xsEffectAmount(cSetAttribute, 1831, cArmor, 3256+0, 1);
xsEffectAmount(cSetAttribute, 1831, cArmor, 4
256+4, 1);
xsEffectAmount(cSetAttribute, 1831, cLineOfSight, 7, 1);
xsEffectAmount(cSetAttribute, 1831, cMovementSpeed, .9, 1);
xsEffectAmount(cSetAttribute, 1831, cRegenerationRate, 150, 1);
xsEffectAmount(cSetAttribute, 1831, cHeroStatus, 96, 1);

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);
}