Post 01 Jul 2016, 15:15

Can't get this script to work [SOLVED]

Hello fellow scripters,
Normally I wouldn't post a thing, I would try to find solution... but I ran out of options. For some reason this part of code just has a lot of problems. First the crashes and now I cannot find reason why part of the code starting by else if won't execute althought all requirements are met. I tried all different ways to write it (adding it to it's own if method, trying to enclose them to more ifs with only one parameter and removing Players[Owner].Enslaved, removing 'healing' procedure) but none of them seemed to work. So I have to ask you for help. What am I doing wrong? Any help will be appreciated. Thank you.
procedure OnHouseDamaged(aHouseId: Integer; aAttacker: Integer);
var TypeOfHouse, TakenDamage, Owner: Integer;
   TypeOfHouse := States.HouseType(aHouseId);
   Owner := States.HouseOwner(aHouseId);
   TakenDamage := States.HouseDamage(aHouseId);
   //if house isn't barrack, tower or market, heal it when damaged
   if (TypeOfHouse <> 29) and (TypeOfHouse <> 17) and (TypeOfHouse <> 21) and (States.HouseIsComplete(aHouseId)) and (Players[Owner].Enslaved = false) then
      Actions.HouseAddRepair(aHouseId, TakenDamage);   //this currently crashes the game when destroying not finished buildings thats why I included s.HIC(aHI)
   //if it's market, team attacker and owner of market after 250 dmg
   else if (TypeOfHouse = 29) and (TakenDamage > 250) and (Players[Owner].Enslaved = false) then
      Actions.PlayerShareFog(Owner, aAttacker, true);
      Actions.PlayerAllianceChange(Owner, aAttacker, true, true);

EDIT: So I figured out why it didn't work. Script was actually executed but method OnHouseDamaged doesn't return id o atacker but id of unit which attacked building. I fixed it by adding variable that got id of owner of the unit.