• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Magnitude?

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
I currently have it set up so my hero randomly drops a gold coin when killing buildings. Like random chance 1 of 20 to drop a coin. I need to set it up so that if the enemy players have a hero near the other teams hero that gold does not drop. So basically if Hero 1 is within a certain distance of hero 2 on opposing team execute the code. I'm not sure how to go about this?
Thanks.
 
Level 18
Joined
Oct 17, 2012
Messages
822
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Random integer number between 1 and 100) Less than or equal to 5
    • Actions
      • Unit Group - Pick every unit in (Units within 200.00 of (Position of (Triggering unit))) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Triggering unit)) Equal to Footman
            • Then - Actions
              • Set nUnits = 1
              • Skip remaining actions
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • nUnits Equal to 0
        • Then - Actions
          • Item - Create Tome of Experience at (Position of (Triggering unit))
        • Else - Actions
          • Set nUnits = 0
 
Level 18
Joined
Oct 17, 2012
Messages
822
Are you positive that the chance factor has nothing to do with your results? Try increasing the chance of the item dropping.

Edit: I just tested the same trigger with your correction and a chance of 100%. I also increased the distance to 500. It worked as intended.
 
Last edited:
Level 10
Joined
Apr 4, 2010
Messages
286
Unit Group - Pick every unit in (Units within 200.00 of (Position of (Triggering unit))) and do (Actions)

Use Dying unit instead of Triggering unit.

I'd also suggest using a variable for your Pick every unit commands and cleaning it up at the end, to avoid leaks.

(Unit-type of (Triggering unit)) Equal to Footman

Use Picked unit instead of Triggering unit.
 
Level 12
Joined
Dec 2, 2016
Messages
733
  • Death and bounty
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set SlayerNear = False
      • Unit Group - Pick every unit in (Units within 200.00 of (Position of (Dying unit))) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Slayer P
            • Then - Actions
              • Game - Display to (All players) the text: yes
              • Set SlayerNear = True
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SlayerNear Equal to False
          • (Owner of (Killing unit)) Equal to Player 11 (Dark Green)
        • Then - Actions
          • Set Random = (Random integer number between 1 and 20)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SlayerNear Equal to False
              • Random Equal to 8
            • Then - Actions
              • Item - Create Gold Coin DG at (Position of (Triggering unit))
            • Else - Actions
              • If (Random Equal to 9) then do (Item - Create Big Gold Coin DG at (Position of (Triggering unit))) else do (Do nothing)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SlayerNear Equal to False
              • (Owner of (Killing unit)) Equal to Player 12 (Brown)
            • Then - Actions
              • Set Random = (Random integer number between 1 and 20)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • SlayerNear Equal to False
                  • (Owner of (Attacking unit)) Equal to Player 12 (Brown)
                  • Random Equal to 8
                • Then - Actions
                  • Item - Create Gold Coin Brown at (Position of (Triggering unit))
                • Else - Actions
                  • If (Random Equal to 9) then do (Item - Create Big Gold Coin Brown at (Position of (Triggering unit))) else do (Do nothing)
            • Else - Actions
 
Level 13
Joined
May 10, 2009
Messages
868
"Random Equal to 8". Shouldn't it be "LESS_THAN_OR_EQUAL_TO"? For testing purposes, try to make that condition to always return true (less than or equal to 20). Also, internally, the (Dying Unit) function returns the (Triggering Unit)'s value, so it's just a matter of choice/flavor, because both in that event have the same value.

  • SlayerNear Equal to False
You don't need to check it multiple times, because SlayerNear variable never changes its value again in that trigger. So, the very first "SlayerNear Equal to False" is enough.
 
Level 18
Joined
Oct 17, 2012
Messages
822
Use Dying unit instead of Triggering unit.

Triggering unit = Dying unit. Triggering unit works for all unit related events.
Even though Slayer P is the one killing the units the message is not displayed.
Test your trigger again with a greater distance for detection. The following works as intended (500 units as distance):
  • Untitled Trigger 001
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set IsSlayerNear = False
      • Unit Group - Pick every unit in (Units within 500.00 of (Position of (Triggering unit))) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Footman
            • Then - Actions
              • Set IsSlayerNear = True
              • Game - Display to (All players) the text: Setting IsSlayerNea...
              • Skip remaining actions
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • IsSlayerNear Equal to False
          • ((Owner of (Killing unit)) is an enemy of (Triggering player)) Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: (IsSlayerNear: + False)
          • Set chance = (Random integer number between 1 and 20)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • chance Equal to 1
            • Then - Actions
              • Set chance = (Random integer number between 0 and 100)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • chance Less than or equal to 60
                • Then - Actions
                  • Game - Display to (All players) the text: Small Coin Dropped!
                  • Item - Create Tome of Experience at (Position of (Triggering unit))
                • Else - Actions
                  • Game - Display to (All players) the text: Big Coin Dropped!
                  • Item - Create Tome of Power at (Position of (Triggering unit))
            • Else - Actions
              • Game - Display to (All players) the text: No coin dropped!
        • Else - Actions
 
Last edited:
Status
Not open for further replies.
Top