• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to detect when a peasant finishes repairing?

Status
Not open for further replies.
Level 7
Joined
Jul 20, 2009
Messages
295
That a peasant has stopped repairing and now he has to go back to his Tent.

Details:
A building has been attacked, Create peasant next to Tent, order peasant to repair building.

(Now this part which i need help with)
If peasant stops repairing, order peasant to cast storm bolt at tent. <==

If unit casts storm bolt, remove unit.

+Rep to the helper.
 
Let's say you are in the part of issuing the order of repair.
Your first action would be adding the peasant to a unit group to ensure that the repair has been initiated and that he is still repairing. Then, another trigger will check the three order events:
  • Events
    • Unit - A unit Is issued an order targeting an object
    • Unit - A unit Is issued an order targeting a point
    • Unit - A unit Is issued an order with no target
The condition will be set to check whether the (Triggering unit) is in the unit group. If it is, then order the unit to stop, wait 0.00 seconds and order it again to use Storm Bolt on the tent.

In order to issue the order towards the right tent, you can use a hashtable, where you will save the tent to the peasant, e.g.
  • Set Unit1 = (Attacked unit)
  • Set Point1 = (Position of (Attacked unit))
  • Unit - Create 1 Peasant for (Triggering player) at Point1 facing Default building degrees
  • Unit - Order (Last created unit) to Human Peasant - Repair (Attacked unit)
  • Hashtable - Save handle of (Attacked unit) as (Key tent) of (Key(Last created unit)) in Hashtable
  • Unit Group - Add (Last created unit) to RepairGroup
  • Custom script: call RemoveLocation (udg_Point1)
Then, in the trigger that you will storm bolt the tent,
  • Set LoadUnit = (Load (Key tent) of (Key(Triggering unit)) from Hashtable)
  • Unit - Order (Triggering unit) to Human Mountain King - Storm Bolt LoadUnit
  • Hashtable - Clear all child hashtables of (Key(Triggering unit)) in Hashtable
  • Unit Group - Remove (Triggering unit) from RepairGroup
 
Level 8
Joined
Jan 8, 2010
Messages
493
why don't you create a periodic timer that will check if the Tent's hitpoints is already full instead of ordering the peasant to storm bolt the Tent? you can turn on the periodic trigger once the peasant starts repairing the Tent.

EDIT: or something like that ^^^^^ XD
 
Aww, hashtables :p I hate them lol, is there any other way to detect a unit has stopped repairing and order it to do something, without hashtables?

What you asked there has nothing to do with the use of the hashtable in my example. You just need to save the tent to the peasant, so that "he knows" which tent to Storm Bolt. Otherwise, you can't retrieve the proper target, can you? :p

P.S. Don't hate something, just because you are not familiar with it. Efficiency > Boredom
 
Level 8
Joined
Jan 8, 2010
Messages
493
just thought that the all that the peasant has to do is repair that damaged building, since kaizar said the peasant will appear once the building is damaged, and will be removed once it is done repairing.

~but oh wait, using periodic trigger will not check which peasant repaired a Tent. if units attack different Tents then someone finishes repairing a Tent every peasant repairing or not might disappear.
 
Level 7
Joined
Jul 20, 2009
Messages
295
What you asked there has nothing to do with the use of the hashtable in my example. You just need to save the tent to the peasant, so that "he knows" which tent to Storm Bolt. Otherwise, you can't retrieve the proper target, can you? :p

P.S. Don't hate something, just because you are not familiar with it. Efficiency > Boredom

I see, so you didn't fullfill what i was in need of help? =/
I meant by building, anythign other than tent, the tent is where the peasant comes from, and the building is like, next to the tent, let's say a tower.
When the tower takes dmg, peasant gets out of his tent, repairs then after tower has his life at max, the peasant returns bak to his tent, I couldn't find any event to help me find the peasant that was done with repairing.

The tent and the peasants are invulnerable, and both are owned by computer.

Edit: I think I can find a way to check if tower has 100% HP in which case i can then order the peasant to return bak to his tent, though, it has to be periodic, and might cause lag in-game as there will be many towers and many peasants and tents.
 
Level 7
Joined
May 18, 2010
Messages
264
  • Start
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamagedUnit) Equal to (==) Guard Tower
    • Actions
      • Set Unit_GT_Pesant[1] = GDD_DamagedUnit
      • Unit - Create 1 Peasant for (Owner of Unit_GT_Pesant[1]) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
      • Set Unit_GT_Pesant[2] = (Last created unit)
      • Unit - Order Unit_GT_Pesant[2] to Human Peasant - Repair Unit_GT_Pesant[1]
      • Trigger - Turn on Check <gen>
  • Check
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
      • (Percentage life of Unit_GT_Pesant[1]) Equal to (==) 100.00
    • Actions
      • Unit - Order Unit_GT_Pesant[2] to Move To (Center of (Playable map area))
      • Trigger - Turn off (This trigger)
i use GDD damage detection sistem
(unable to find link to it)
this would work but for a single peasant only
(... i chould make it for more of them but im tired)
 
Level 7
Joined
Jul 20, 2009
Messages
295
  • Start
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamagedUnit) Equal to (==) Guard Tower
    • Actions
      • Set Unit_GT_Pesant[1] = GDD_DamagedUnit
      • Unit - Create 1 Peasant for (Owner of Unit_GT_Pesant[1]) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
      • Set Unit_GT_Pesant[2] = (Last created unit)
      • Unit - Order Unit_GT_Pesant[2] to Human Peasant - Repair Unit_GT_Pesant[1]
      • Trigger - Turn on Check <gen>
  • Check
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
      • (Percentage life of Unit_GT_Pesant[1]) Equal to (==) 100.00
    • Actions
      • Unit - Order Unit_GT_Pesant[2] to Move To (Center of (Playable map area))
      • Trigger - Turn off (This trigger)
i use GDD damage detection sistem
(unable to find link to it)
this would work but for a single peasant only
(... i chould make it for more of them but im tired)

I have everything done, except the checking part, I don't want a periodic =/
 
Man, you either use hashtables or periodic. Its not our problem that you can't spent 5minutes to learn something new, since it isn't hard.

You either use hashtables/peridoc/checking order events or you dont want your trigger at all =)
Pharaoh_ already said above nice solution. I'll just paste periodic one. Uses Unit Indexer and GDD. 852024 is the id of order "repair".
Its just an egzample, you modify it as you desire.
  • get worker
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamagedUnit) Equal to Farm
    • Actions
      • Set tempp = (Position of GDD_DamagedUnit)
      • Unit - Create 1 ChĹ‚op for (Owner of GDD_DamagedUnit) at tempp facing DomyĹ›lna orientacja budynku degrees
      • Set key = (Custom value of (Last created unit))
      • Set u[key] = GDD_DamagedUnit
      • Wait 0.00 seconds
      • Custom script: call IssueTargetOrderById (bj_lastCreatedUnit, 852024, udg_u[udg_key])
      • Custom script: call GroupAddUnit (udg_repairg, bj_lastCreatedUnit)
      • Custom script: call RemoveLocation (udg_tempp)
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on repair loop <gen>
  • repair loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in repairg and do (Actions)
        • Loop - Actions
          • Custom script: local real r1
          • Custom script: local real r2
          • Set tempp = (Position of (Picked unit))
          • Custom script: set r1 = GetLocationX (udg_tempp)
          • Custom script: set r2 = GetLocationY (udg_tempp)
          • Custom script: if GetUnitCurrentOrder(GetEnumUnit()) != 852024 then
          • Custom script: call IssuePointOrder (GetEnumUnit(), "move", r1, r2)
          • Custom script: call UnitApplyTimedLife (GetEnumUnit(), 'BTLF', 0.50)
          • Unit Group - Remove (Picked unit) from repairg
          • Custom script: endif
          • Custom script: call RemoveLocation (udg_tempp)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (repairg is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
Here is a test map for you.
 

Attachments

  • Peasant repair.w3x
    27.2 KB · Views: 44
It either needs to be timer or wait or peasent wont get order at all.
I checked it many times, and if I'm not mistaken last time with situation about casting abilities it was you who told that Stop order is issued before casting :D. You were right, and here lies the same problem. Either use loop that orders peasant to repair (like every 0.5) or we use wait while creating.

For MUI I recommend removing wait, and adding loop described above, and as it was said already in my previous post I just gave an egzample. Was tired after discovering that order is issued before unit is created, therefore returning null so I needed to use some kind of delay to make it work properly.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
I checked it 100 times, and if I'm not remember last time about casting abilities it was you who told that Stop order is issued before casting. You were right, and he lies the same problem.

Yeah, but a non MUI system is still not acceptable ;)

Use a local unit variable with wait (waits are inaccurate) or a unit group/unit array with a timer with 0.00 expiration time for example.
 
Level 7
Joined
Jul 20, 2009
Messages
295
Man, you either use hashtables or periodic. Its not our problem that you can't spent 5minutes to learn something new, since it isn't hard.

You either use hashtables/peridoc/checking order events or you dont want your trigger at all =)
Pharaoh_ already said above nice solution. I'll just paste periodic one. Uses Unit Indexer and GDD. 852024 is the id of order "repair".
Its just an egzample, you modify it as you desire.
  • get worker
    • Events
      • Game - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamagedUnit) Equal to Farm
    • Actions
      • Set tempp = (Position of GDD_DamagedUnit)
      • Unit - Create 1 ChĹ‚op for (Owner of GDD_DamagedUnit) at tempp facing DomyĹ›lna orientacja budynku degrees
      • Set key = (Custom value of (Last created unit))
      • Set u[key] = GDD_DamagedUnit
      • Wait 0.00 seconds
      • Custom script: call IssueTargetOrderById (bj_lastCreatedUnit, 852024, udg_u[udg_key])
      • Custom script: call GroupAddUnit (udg_repairg, bj_lastCreatedUnit)
      • Custom script: call RemoveLocation (udg_tempp)
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on repair loop <gen>
  • repair loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in repairg and do (Actions)
        • Loop - Actions
          • Custom script: local real r1
          • Custom script: local real r2
          • Set tempp = (Position of (Picked unit))
          • Custom script: set r1 = GetLocationX (udg_tempp)
          • Custom script: set r2 = GetLocationY (udg_tempp)
          • Custom script: if GetUnitCurrentOrder(GetEnumUnit()) != 852024 then
          • Custom script: call IssuePointOrder (GetEnumUnit(), "move", r1, r2)
          • Custom script: call UnitApplyTimedLife (GetEnumUnit(), 'BTLF', 0.50)
          • Unit Group - Remove (Picked unit) from repairg
          • Custom script: endif
          • Custom script: call RemoveLocation (udg_tempp)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (repairg is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
Here is a test map for you.

Edit: nvm
 
Last edited:
Here is the MUI version. Improved a bit. Thats for you Maker :p
  • get worker
    • Events
      • Gra - GDD_Event becomes Equal to 0.00
    • Conditions
      • (Unit-type of GDD_DamagedUnit) Equal to Farm
    • Actions
      • Set tempp = (Position of GDD_DamagedUnit)
      • Unit - Create 1 Peasant for (Owner of GDD_DamagedUnit) at tempp facing Default building facing
      • Set key = (Custom value of (Last created unit))
      • Set u[key] = GDD_DamagedUnit
      • Timer - Start timer as a One shoot timer that will expire in 0.00 seconds
      • Custom script: call GroupAddUnit (udg_tempg, bj_lastCreatedUnit)
      • Custom script: call RemoveLocation (udg_tempp)
      • Trigger - Turn on repair loop <gen>
  • timer expires
    • Events
      • Time - timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in tempg and do (Actions)
        • Loop = Actions
          • Set key = (Custom value of (Picked unit))
          • Custom script: call IssueTargetOrderById (GetEnumUnit(), 852024, udg_u[udg_key])
          • Custom script: call GroupRemoveUnit (udg_tempg, GetEnumUnit())
          • Custom script: call GroupAddUnit (udg_repairg, GetEnumUnit())
  • repair loop
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in repairg and do (Actions)
        • Loop - Actions
          • Custom script: local real r1
          • Custom script: local real r2
          • Set tempp = (Position of (Picked unit))
          • Custom script: set r1 = GetUnitX (udg_udg_u[udg_key])
          • Custom script: set r2 = GetUnitY (udg_udg_u[udg_key])
          • Custom script: if GetUnitCurrentOrder(GetEnumUnit()) != 852024 then
          • Custom script: call IssuePointOrder (GetEnumUnit(), "move", r1, r2)
          • Custom script: call UnitApplyTimedLife (GetEnumUnit(), 'BTLF', 0.50)
          • Custom script: call GroupRemoveUnit (udg_repairg, GetEnumUnit())
          • Set u[key] = No unit
          • Custom script: endif
          • Custom script: call RemoveLocation (udg_tempp)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (repairg is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
 

Attachments

  • Peasant repairMUI.w3x
    27.6 KB · Views: 38
Status
Not open for further replies.
Top