- Joined
- Dec 2, 2016
- Messages
- 733
So the following code is for a tower that when it attacks a unit, it will add -x armor to the unit. The -armour depends on the type of the tower, as there is two towers I'm using. One being -1 armor, the upgraded tower being -2 per hit.
So I detect when a unit is attacked, and then use 'OnAttack()' to check which unit the attacker is. If he's tower#1 (-1 armor) then set boolean 'towerType' to 1. If he's tower#2 then set boolean 'towerType' to 2.
Now I've tested with messaging inside the OnAttack() function, and it does work like if the attacker is 'Tower1' it will output 'Tower1' and if attacker is 'Tower2' then it outputs 'Tower2'.
But this part
Even though the 'OnAttack()' function should be changing the Boolean to 2. The 2nd part
Never seems to run. For some reason my boolean isn't changing or my 2nd if statement here isn't running properly. Is there anything wrong you guys can see? Did I code this wrong? Thanks. Full code below:
Edit: So I added this in
to check what the variable was at, it outputs '1' when Tower#1 and doesn't output anything when Tower#2
So for some reason my code is not changing 'towerType' to 2 when it's the Tower#2 attacking.
So I detect when a unit is attacked, and then use 'OnAttack()' to check which unit the attacker is. If he's tower#1 (-1 armor) then set boolean 'towerType' to 1. If he's tower#2 then set boolean 'towerType' to 2.
Now I've tested with messaging inside the OnAttack() function, and it does work like if the attacker is 'Tower1' it will output 'Tower1' and if attacker is 'Tower2' then it outputs 'Tower2'.
But this part
JASS:
OnAttack();
if (towerType == 1) {
DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-1" );
AddUnitBonus(u, BONUS_ARMOR, -1);
}
if (towerType == 2) {
DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-2" );
AddUnitBonus(u, BONUS_ARMOR, -2);
}
Even though the 'OnAttack()' function should be changing the Boolean to 2. The 2nd part
JASS:
if (towerType == 2) {
DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-2" );
AddUnitBonus(u, BONUS_ARMOR, -2);
}
Never seems to run. For some reason my boolean isn't changing or my 2nd if statement here isn't running properly. Is there anything wrong you guys can see? Did I code this wrong? Thanks. Full code below:
JASS:
library bloodTower requires libMisc, libSetup, unitClassification, BonusMod {
public integer towerType;
HandleTable bloodTowersTable;
timer t = null;
integer total = 0;
bloodTowerData bloodTowers[];
private function OnAttack() -> boolean {
unit u = GetTriggerUnit();
unit d = GetAttacker();
if (GetUnitTypeId(d) == 'hT0a' ) {
// AddUnitBonus(u, BONUS_ARMOR, -1);
towerType = 1;
//DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-1" );
return true;
}
if (GetUnitTypeId(d) == 'h00S' ) {
// AddUnitBonus(u, BONUS_ARMOR, -2);
towerType = 2;
//DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-2" );
return true;
}
return false;
}
public function CheckBloodTower(unit u) {
//unit u = GetTriggerUnit();
unit d = GetAttacker();
OnAttack();
if (towerType == 1) {
DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-1" );
AddUnitBonus(u, BONUS_ARMOR, -1);
}
if (towerType == 2) {
DisplayTextToForce( GetPlayersAll(),GetUnitName(d)+"-2" );
AddUnitBonus(u, BONUS_ARMOR, -2);
}
}
private function onInit() {
trigger trg;
bloodTowersTable = HandleTable.create();
trg = TriggerCreateOnGameStarting();
TriggerRegisterAnyPlayerUnitEvent(trg, EVENT_PLAYER_UNIT_ATTACKED, null);
TriggerAddCondition(trg, Condition(function OnAttack));
}
}
Edit: So I added this in
JASS:
DisplayTextToForce( GetPlayersAll(),I2S(towerType) );
to check what the variable was at, it outputs '1' when Tower#1 and doesn't output anything when Tower#2
So for some reason my code is not changing 'towerType' to 2 when it's the Tower#2 attacking.
Last edited: