| 12-10-2003, 01:43 AM | #1 |
For the life of me, I can't figure out what I'm doing wrong with this trigger. Basically, what I wan to happen is that if an appropriate unit is within range of a field, then the player gains one food. If the unit leaves, then the player loses that food. Each field should only be able to support four farmers. Pretty simple in principle, but for some reason, when I run this trigger the player's food cap just keep going down, please help. E: Periodic C: None A: For each (Integer A) from 1 to (Number of players in (All players)), do (Actions) Loop - Actions Player - Set (Player((Integer A))) Food cap to (((Player((Integer A))) Food cap) - FarmerFoodArray[(Integer A)]) Set FarmerFoodArray[(Integer A)] = 0 Unit Group - Add all units of (Units owned by (Player((Integer A))) of type Field (Real)) to Fields Set FarmersPotential = (Units owned by (Player((Integer A))) matching ((Unit-type of (Matching unit)) Equal to Average Peasant)) Unit Group - Pick every unit in Fields and do (Actions) Loop - Actions Set FarmersInt = 0 Set Farmers = (Units within 75.00 of (Position of (Picked unit)) matching (((Matching unit) is in FarmersPotential) Equal to True)) Unit Group - Pick every unit in Farmers and do (Actions) Loop - Actions Animation - Play FocusedUnit's Animation - Stand animation Set FarmersInt = (Number of units in Farmers) If (FarmersInt Greater than 4) then do (Set FarmersInt = 4) else do (Do nothing) Set FarmerFoodArray[(Integer A)] = (FarmerFoodArray[(Integer A)] + FarmersInt) For each (Integer A) from 1 to FarmersInt, do (Actions) Loop - Actions Set FocusedUnit = (Random unit from Farmers) Animation - Play FocusedUnit's Animation - Attack Lumber animation Unit Group - Remove FocusedUnit from Farmers Unit Group - Remove FocusedUnit from FarmersPotential Player - Set (Player((Integer A))) Food cap to (((Player((Integer A))) Food cap) + FarmerFoodArray[(Integer A)]) |
| 12-10-2003, 02:46 AM | #2 |
Ok...well, firstly I'm not exactly sure what you want, well I think I know what you want the trigger to do, but that trigger seems really inefficient but even then I'm not really sure if it is, because I can't follow it easily especially since you don't list when a forloop ends. So from what I can tell, you want a unit called a field, a unit called a farmer, for every farmer that is near a field you want the player who owns them to gain extra food for their maximum food. So...why...if you're going with the periodic timer idea, why don't you just do something like... E: Every 1 second of game C: none A: Pick every unit matching unit type "Field" Set FarmersGroup = units within 75.00 of picked unit of type "Farmer" and owner of matching unit = owner of picked unit Playerfood(owner of picked unit) = Playerfood(owner of picked unit) + count number of units in FarmersGroup For 1 to (total number of players) do Player(Integer A) food cap = 0 Player(Integer A) food cap = Playerfood(Integer A) Now that may very well not be at all what you want, but I'm still confused as to what it is you want, please rephrase the description of the trigger and I'll be able to help you more. |
