Help!
PostPosted: 20 Jan 2014, 15:17
I created this topic before, but deleted it again as I thought sado and me found the solution to my problem. But we did not. So now I will rewrite everything and upgrade it a bit. 
I'm working on the script of TNL 7, and in that mission the player has to break through a barricade which consists of a large number of units. I'm looking for a way to script this objective and I found one, except that it's not working.
What my script should do is: search in a radius of 14 tiles around location (74, 67) for enemy units --> if there are none and both AI players have less soldiers than 5, you win.
What my script does: no idea, but you win as soon as both players have less than 5 soldiers. The other condition never turns true although it should turn true right at the start?
Here is the script itself:
This is all on OnTick. PointOfDefenceX and PointOfDefenceY are constants. You may ignore AttackIntruders, I will be needing it later on. The script does not give an error.
So I guess there is a problem with the condition since BarricadeIntact and Barricade2Intact never turn true. But what?
Edit: wait a second... If I set BarricadeIntact/Barricade2Intact as true on OnMissionStart, the same thing happens... So that must mean they are always false, no matter what? Or they are just being ignored in the last part of the script (if lala PlayerWin)?
I must have made an obvious mistake somewhere. 

I'm working on the script of TNL 7, and in that mission the player has to break through a barricade which consists of a large number of units. I'm looking for a way to script this objective and I found one, except that it's not working.
What my script should do is: search in a radius of 14 tiles around location (74, 67) for enemy units --> if there are none and both AI players have less soldiers than 5, you win.
What my script does: no idea, but you win as soon as both players have less than 5 soldiers. The other condition never turns true although it should turn true right at the start?
Here is the script itself:
- Code:
Units := States.PlayerGetAllUnits(0); UnitsEnemy := States.PlayerGetAllUnits(1); UnitsEnemy2 := States.PlayerGetAllUnits(2); for i := 0 to Length(Units) -1 do begin if (((States.UnitPositionX(Units[i]) > (PointOfDefenceX - 14)) and (States.UnitPositionX(Units[i]) < (PointOfDefenceX + 14))) and ((States.UnitPositionY(Units[i]) > (PointOfDefenceY - 14)) and (States.UnitPositionY(Units[i]) < (PointOfDefenceY - 14)))) then begin AttackIntruders := True; end; end; begin for j := 0 to Length(UnitsEnemy) -1 do if (((States.UnitPositionX(UnitsEnemy[j]) > (PointOfDefenceX - 14)) and (States.UnitPositionX(UnitsEnemy[j]) < (PointOfDefenceX + 14))) and ((States.UnitPositionY(UnitsEnemy[j]) > (PointOfDefenceY - 14)) and (States.UnitPositionY(UnitsEnemy[j]) < (PointOfDefenceY - 14)))) then BarricadeIntact := True else BarricadeIntact := False; end; begin for k := 0 to Length(UnitsEnemy2) -1 do if (((States.UnitPositionX(UnitsEnemy2[k]) > (PointOfDefenceX - 14)) and (States.UnitPositionX(UnitsEnemy2[k]) < (PointOfDefenceX + 14))) and ((States.UnitPositionY(UnitsEnemy2[k]) > (PointOfDefenceY - 14)) and (States.UnitPositionY(UnitsEnemy2[k]) < (PointOfDefenceY - 14)))) then Barricade2Intact := True else Barricade2Intact := False; end; if (BarricadeIntact = false) and (States.StatArmyCount(1) < 5) and (Barricade2Intact = false) and (States.StatArmyCount(2) < 5) then begin Actions.PlayerWin([0], False); end;
So I guess there is a problem with the condition since BarricadeIntact and Barricade2Intact never turn true. But what?

Edit: wait a second... If I set BarricadeIntact/Barricade2Intact as true on OnMissionStart, the same thing happens... So that must mean they are always false, no matter what? Or they are just being ignored in the last part of the script (if lala PlayerWin)?

