• 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.

[Trigger] My Risk System help thread

Status
Not open for further replies.
Level 6
Joined
Feb 10, 2011
Messages
188
I am in the process of making a new Risk Trigger System. So far I have got the randomize bases trigger done. (Thanks to ruleofiron99 & deathismyfriend) This is going to be my thread to get this entire system done I will make a check list of what needs to be done still and what i need most help on. I will also post each trigger so you guys can double check it for efficient and leaks.

Here is the list of things that need to be done for the entire system to be finished.

1. Base randomizing & Setting starting defenders (Seems completed, feel free to comment)
2. Changing base defenders & owner of bases (Changing base defender is almost done, in the process of optimizing it. working on change owner of base trigger.)
3. Setting bases to countries
4. Income system
5. Unit spawn system
6. Multiboard (Possibly done, will post when I get to #6)
7. Game options
8. Camera (Possibly done, will post when I get to #8)
9. I may add more but I am kind of tired and can't think of any right now.

Here is the Base randomizing trigger / Starting defenders

  • Randomize Bases Set Defenders
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add buildings to the pool --------
      • Set Bases = (Units owned by Neutral Hostile matching (((Matching unit) is A structure) Equal to True))
      • -------- Set active players --------
      • Set players = (All players matching (((Matching player) slot status) Equal to Is playing))
      • -------- _________________ --------
      • Unit Group - Pick every unit in Bases and do (Actions)
        • Loop - Actions
          • -------- Give a City/Tower/Defender to a random player from the pool --------
          • Set tempPlayer = (Random player from players)
          • Set tempUnit = (Picked unit)
          • Unit - Change ownership of tempUnit to tempPlayer and Change color
          • Set tempPlayer1 = (Owner of tempUnit)
          • Set tempPoint = (Position of tempUnit)
          • Set tempPoint1 = (tempPoint offset by (-95.00, -290.00))
          • Unit - Create 1 Circle of Power (Custom) for Neutral Passive at tempPoint1 facing Default building facing degrees
          • Set tempPoint2 = (Position of (Last created unit))
          • Unit - Create 1 Guardtower Normal for tempPlayer1 at tempPoint2 facing Default building facing degrees
          • Set tempUnit1 = (Last created unit)
          • Unit - Add Defend (Casting) to tempUnit1
          • Unit - Create 1 Private for tempPlayer1 at tempPoint2 facing Default building facing degrees
          • Set BaseDefender = (Last created unit)
          • Unit - Order tempUnit1 to Orc Raider - Ensnare BaseDefender
          • Unit Group - Add BaseDefender to BaseDefenders
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_tempPoint )
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempUnit = null
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_BaseDefender = null
          • Custom script: set udg_tempPlayer1 = null
          • -------- Remove and Add Players --------
          • Player Group - Remove tempPlayer from players
          • Player Group - Add tempPlayer to playerstemper
          • -------- Refresh Player Pool --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of players in players) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in playerstemper and do (Actions)
                • Loop - Actions
                  • Player Group - Remove (Picked player) from playerstemper
                  • Player Group - Add (Picked player) to players
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units owned by Neutral Hostile of type City)) Equal to 0
            • Then - Actions
              • Trigger - Turn on Change Defender <gen>
            • Else - Actions
Here is the trigger that changes the defender of a base, when the player chooses to.

let me know if there anything i can do to make it better.

  • Change Defender
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Select New Defender
    • Actions
      • -------- Set New Defender & Position --------
      • Set tempUnit = (Target unit of ability being cast)
      • Set tempPoint = (Position of tempUnit)
      • -------- Set Casting Unit and Owner --------
      • Set tempUnit1 = (Triggering unit)
      • Set tempPlayer = (Owner of tempUnit1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (((Target unit of ability being cast) is in BaseDefenders) Equal to False) and ((((Target unit of ability being cast) is An Ancient) Equal to False) and ((Owner of tempUnit) Equal to tempPlayer))
        • Then - Actions
          • -------- Set Casting Unit Position --------
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempGroup = (Units within 500.00 of tempPoint1 matching (((Matching unit) is in BaseDefenders) Equal to True))
          • -------- Set Current Defender & Position --------
          • Set tempUnit2 = (Random unit from tempGroup)
          • Set tempPoint2 = (Position of tempUnit2)
          • -------- Swap Defenders & Remove/Add Buffs --------
          • Unit - Remove All buffs from tempUnit2
          • Unit Group - Remove tempUnit2 from BaseDefenders
          • Unit - Move tempUnit2 instantly to tempPoint
          • Unit - Move tempUnit instantly to tempPoint2
          • Unit Group - Add tempUnit to BaseDefenders
          • Set tempGroup1 = (Units within 500.00 of tempPoint1 matching ((Unit-type of (Matching unit)) Equal to Guardtower Normal))
          • Set tempUnit3 = (Random unit from tempGroup1)
          • Unit - Order tempUnit3 to Orc Raider - Ensnare tempUnit
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempUnit2 = null
          • Custom script: set udg_tempUnit3 = null
          • Custom script: call DestroyGroup( udg_tempGroup )
          • Custom script: call DestroyGroup( udg_tempGroup1 )
        • Else - Actions
          • Unit - Order tempUnit1 to Stop
          • Set tempForce = (All players matching ((Owner of tempUnit1) Equal to tempPlayer))
          • Game - Display to tempForce the text: Pick a different un...
      • Custom script: call RemoveLocation( udg_tempPoint )
      • Custom script: call DestroyForce ( udg_tempForce)
      • Custom script: set udg_tempUnit = null
      • Custom script: set udg_tempUnit1 = null
      • Custom script: set udg_tempPlayer = null
 
Last edited:
You can try using loops and multiple ITEs to shorten your problem. Also, Integer A leaks. Use a temp integer instead.

integer A doesnt leak it is just slower and less efficient than ur own variable.

@TO
the way u use integer A is wrong. That can create bugs and give unwanted results.
Also as mastertrainer has said u can shorten the second trigger to a few lines using a loop
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Enjoy.

How it works:
Add bases to a unit group.
All players are added to a temp "pool" player group.
Looping through every unit in the group, the currently picked unit is given to a random player in the pool group.
The player in the pool group is removed from the pool group, and added to the "refresh" group.
When the pool group is empty, all players from the refresh group are put back in the pool group.

If the number of bases doesn't divide equally between your number of players, a random handful of players will end up having 1 extra bases relative to the others.
 

Attachments

  • Random Bases.w3x
    17.8 KB · Views: 49
Level 6
Joined
Feb 10, 2011
Messages
188
integer A doesnt leak it is just slower and less efficient than ur own variable.

@TO
the way u use integer A is wrong. That can create bugs and give unwanted results.
Also as mastertrainer has said u can shorten the second trigger to a few lines using a loop

You can try using loops and multiple ITEs to shorten your problem. Also, Integer A leaks. Use a temp integer instead.


ya i figured i could i just have edited it, i actually dont use it anymore i use a system made by priwin but its in jass and just a template so i used this as an example

Enjoy.

How it works:
Add bases to a unit group.
All players are added to a temp "pool" player group.
Looping through every unit in the group, the currently picked unit is given to a random player in the pool group.
The player in the pool group is removed from the pool group, and added to the "refresh" group.
When the pool group is empty, all players from the refresh group are put back in the pool group.

If the number of bases doesn't divide equally between your number of players, a random handful of players will end up having 1 extra bases relative to the others.


thanks i will check this out, and hopefully understand it. haha
 
Last edited:
Level 6
Joined
Feb 10, 2011
Messages
188
Enjoy.

How it works:
Add bases to a unit group.
All players are added to a temp "pool" player group.
Looping through every unit in the group, the currently picked unit is given to a random player in the pool group.
The player in the pool group is removed from the pool group, and added to the "refresh" group.
When the pool group is empty, all players from the refresh group are put back in the pool group.

If the number of bases doesn't divide equally between your number of players, a random handful of players will end up having 1 extra bases relative to the others.

Alright, I just had time to look at it. I had to make a few changes since Risk requires other things to be placed/randomized to.
I also added a few things, it now adds an ability called defender to the riflemen created at the center of the CoP (called defend) (based off ensnare) it is used to keep the unit as the base defender and if the unit is melee adds a range.
Here is my version of the trigger, does it leak?

Ok so it all works well in game but for some reason each of the circle of powers that it creates are red colored? like they are owned by player 1, why is that?

  • Bases
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add buildings to the pool --------
      • Set Bases = (Units owned by Neutral Hostile matching (((Matching unit) is A structure) Equal to True))
      • -------- Set active players --------
      • Set players = (All players matching (((Matching player) slot status) Equal to Is playing))
      • -------- _________________ --------
      • Unit Group - Pick every unit in Bases and do (Actions)
        • Loop - Actions
          • -------- Give a barracks to a random player in the pool --------
          • Set tempplayer = (Random player from players)
          • Unit - Change ownership of (Picked unit) to tempplayer and Change color
          • Set temppoint = ((Position of (Picked unit)) offset by (-75.00, -275.00))
          • Destructible - Create a COP at (temppoint offset by (0.00, -50.00)) facing 90.00 with scale 1.50 and variation 0
          • Unit - Create 1 Guardtower Normal for (Owner of (Picked unit)) at temppoint facing Default building facing degrees
          • Set TempUnit = (Last created unit)
          • Unit - Add Defend (Casting) to TempUnit
          • Set temppoint1 = ((Position of (Last created unit)) offset by (0.00, 0.00))
          • Unit - Create 1 Private for (Owner of (Picked unit)) at temppoint1 facing Default building facing degrees
          • Set BaseDefender = (Last created unit)
          • Unit - Order TempUnit to Orc Raider - Ensnare BaseDefender
          • Unit Group - Add BaseDefender to StartingDefenders
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_temppoint )
          • Custom script: call RemoveLocation( udg_temppoint1 )
          • Custom script: set udg_TempUnit = null
          • Custom script: set udg_BaseDefender = null
          • -------- Remove and Add Players --------
          • Player Group - Remove tempplayer from players
          • Player Group - Add tempplayer to playerstemper
          • -------- Refresh Player Pool --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of players in players) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in playerstemper and do (Actions)
                • Loop - Actions
                  • Player Group - Remove (Picked player) from playerstemper
                  • Player Group - Add (Picked player) to players
            • Else - Actions
 
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
Not sure, but I guess destructibles default to the first player colour. Make the CP a unit instead.

You're leaking.

Fix:
  • Set temppoint = (Position of (Picked unit))
  • Set temppoint1 = (temppoint offset by (0.00, -50.00))
  • Set temppoint2 = (temppoint offset by (-75.00, -275.00))
  • Destructible - Create a COP at temppoint1 facing 90.00 with scale 1.50 and variation 0
  • Unit - Create 1 Guardtower Normal for (Owner of (Picked unit)) at temppoint2 facing Default building facing degrees
  • Set TempUnit = (Last created unit)
  • Unit - Add Defend (Casting) to TempUnit
  • Set temppoint3 = (Position of (Last created unit))
  • Unit - Create 1 Private for (Owner of (Picked unit)) at temppoint3 facing Default building facing degrees
  • Set BaseDefender = (Last created unit)
  • Unit - Order TempUnit to Orc Raider - Ensnare BaseDefender
  • Unit Group - Add BaseDefender to StartingDefenders
  • -------- Clear Leaks --------
  • Custom script: call RemoveLocation( udg_temppoint )
  • Custom script: call RemoveLocation( udg_temppoint1 )
  • Custom script: call RemoveLocation( udg_temppoint2 )
  • Custom script: call RemoveLocation( udg_temppoint3 )
 
Level 6
Joined
Feb 10, 2011
Messages
188
Not sure, but I guess destructibles default to the first player colour. Make the CP a unit instead.

You're leaking.

Fix:
  • Set temppoint = (Position of (Picked unit))
  • Set temppoint1 = (temppoint offset by (0.00, -50.00))
  • Set temppoint2 = (temppoint offset by (-75.00, -275.00))
  • Destructible - Create a COP at temppoint1 facing 90.00 with scale 1.50 and variation 0
  • Unit - Create 1 Guardtower Normal for (Owner of (Picked unit)) at temppoint2 facing Default building facing degrees
  • Set TempUnit = (Last created unit)
  • Unit - Add Defend (Casting) to TempUnit
  • Set temppoint3 = (Position of (Last created unit))
  • Unit - Create 1 Private for (Owner of (Picked unit)) at temppoint3 facing Default building facing degrees
  • Set BaseDefender = (Last created unit)
  • Unit - Order TempUnit to Orc Raider - Ensnare BaseDefender
  • Unit Group - Add BaseDefender to StartingDefenders
  • -------- Clear Leaks --------
  • Custom script: call RemoveLocation( udg_temppoint )
  • Custom script: call RemoveLocation( udg_temppoint1 )
  • Custom script: call RemoveLocation( udg_temppoint2 )
  • Custom script: call RemoveLocation( udg_temppoint3 )

alright i made the cp a unit instead, when i did it the placment got all weird. so i had to change a few things here in the new trigger, let me know i missed a leak or have any unused points. (although i dont think i do.)

also i am now noticing something, different areas of the map the circle will be placed in slightly different positions, could you tell me why this happens?

  • Bases
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add buildings to the pool --------
      • Set Bases = (Units owned by Neutral Hostile matching (((Matching unit) is A structure) Equal to True))
      • -------- Set active players --------
      • Set players = (All players matching (((Matching player) slot status) Equal to Is playing))
      • -------- _________________ --------
      • Unit Group - Pick every unit in Bases and do (Actions)
        • Loop - Actions
          • -------- Give a City/Tower/Defender to a random player from the pool --------
          • Set tempplayer = (Random player from players)
          • Unit - Change ownership of (Picked unit) to tempplayer and Change color
          • Set temppoint = ((Position of (Picked unit)) offset by (-95.00, -290.00))
          • Unit - Create 1 Circle of Power (Custom) for (Owner of (Picked unit)) at temppoint facing Default building facing degrees
          • Set temppoint2 = (Position of (Last created unit))
          • Unit - Create 1 Guardtower Normal for (Owner of (Picked unit)) at temppoint2 facing Default building facing degrees
          • Set tempunit1 = (Last created unit)
          • Unit - Add Defend (Casting) to tempunit1
          • Unit - Create 1 Private for (Owner of (Picked unit)) at temppoint2 facing Default building facing degrees
          • Set BaseDefender = (Last created unit)
          • Unit - Order tempunit1 to Orc Raider - Ensnare BaseDefender
          • Unit Group - Add BaseDefender to StartingDefenders
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_temppoint )
          • Custom script: call RemoveLocation( udg_temppoint2 )
          • Custom script: set udg_tempunit1 = null
          • Custom script: set udg_BaseDefender = null
          • -------- Remove and Add Players --------
          • Player Group - Remove tempplayer from players
          • Player Group - Add tempplayer to playerstemper
          • -------- Refresh Player Pool --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of players in players) Equal to 0
            • Then - Actions
              • Player Group - Pick every player in playerstemper and do (Actions)
                • Loop - Actions
                  • Player Group - Remove (Picked player) from playerstemper
                  • Player Group - Add (Picked player) to players
            • Else - Actions
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
  • Set temppoint = ((Position of (Picked unit)) offset by (-95.00, -290.00))
This still leaks.

It creates two points: position of picked unit, and the offset point.

You have to set one point variable at a time, and set the offset based on that variable, so that you can safely destroy both afterwards.

also i am now noticing something, different areas of the map the circle will be placed in slightly different positions, could you tell me why this happens?

Please post a screenshot or the map.
 
Level 6
Joined
Feb 10, 2011
Messages
188
  • Set temppoint = ((Position of (Picked unit)) offset by (-95.00, -290.00))
This still leaks.

It creates two points: position of picked unit, and the offset point.

You have to set one point variable at a time, and set the offset based on that variable, so that you can safely destroy both afterwards.



Please post a screenshot or the map.

ahhh ok i thought that you maybe made a mistake i will do that right now, give me one second and i will post a screenie.
oh and also i changed the o/p and will just be editing the triggers from there now. i figured it would make it a little easier.

ok this was the best screen shot i could get
i know the positioning doesnt seem like much of a difference, but when i have barracks near edges of the map or near trees and other stuff, it could be a huge difference.

if you look you can see some CoP have a small distance from the barracks and some are right up on it.

 
Level 6
Joined
Feb 10, 2011
Messages
188
Another leak, you aren't cleaning temppoint1.

By the way, take a look at this map, it includes various risk systems: http://www.hiveworkshop.com/forums/spells-569/risk-system-1-6-a-113274/

ops sorry forgot to add it in on the map, i was testing the circle thing on a terrained map and did it there had to redo on the whole system map :) its added in now, ill update it on the OP. that is actually the system i use in my current risk map, after a while it starts to lag the game and its pretty hard to edit because all his options make it very confusing. :p i did learn a lot from it though. plus some of it is in jass and its parts i need to edit. i dont know jass yet.
and there is a major bug, sometimes the game wont start after picking options. idk why though.

I just want to be able to get my own system done, so i can understand and edit it easily. also its a good learning experiance.
 
Level 6
Joined
Feb 10, 2011
Messages
188
added the change defender trigger to the first post in thread also here it is
let me know if u find leaks or know a better way to code this.
also i been looking at what MUI is, i dont think this is MUI and since it is very probable that 2 people will cast this spell at the same time during a game, so do i need to make this MUI?
  • Change Defender
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Select New Defender
          • ((Target unit of ability being cast) has buff Defender (BUFF)) Equal to False
          • ((Target unit of ability being cast) is An Ancient) Equal to False
        • Then - Actions
          • -------- Set Casting Unit --------
          • Set tempPoint = (Position of (Casting unit))
          • -------- Set Current Defender & Position --------
          • Unit Group - Pick every unit in (Units within 500.00 of tempPoint) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) has buff Defender (BUFF)) Equal to True
                • Then - Actions
                  • Set tempUnit1 = (Picked unit)
                • Else - Actions
          • Set tempPoint1 = (Position of tempUnit1)
          • -------- Set New Defender & Position --------
          • Set tempUnit2 = (Target unit of ability being cast)
          • Set tempPoint2 = (Position of tempUnit2)
          • -------- Swap Defenders & Remove/Add Buffs --------
          • Unit - Move tempUnit1 instantly to tempPoint2
          • Unit - Remove All buffs from tempUnit1
          • Unit - Move tempUnit2 instantly to tempPoint1
          • Unit Group - Pick every unit in (Units within 500.00 of (Position of tempUnit2)) 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 Guardtower Normal
                • Then - Actions
                  • Set tempUnit3 = (Picked unit)
                  • Unit - Order tempUnit3 to Orc Raider - Ensnare tempUnit2
                • Else - Actions
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_tempPoint )
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempUnit2 = null
          • Custom script: set udg_tempUnit3 = null
        • Else - Actions
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
It's MUI since it's instant (there are no waits or timers). It is simply impossible for two players to cast it at exactly the same time, so it's quite safe.

You're leaking a unit group:
  • Unit Group - Pick every unit in (Units within 500.00 of tempPoint) and do (Actions)
First set a unit group variable to (units within 500 of temp point), then pick every unit in this temp group.

When you're done with it,
  • Custom script: call DestroyGroup( udg_tempGroup )
 
Level 6
Joined
Feb 10, 2011
Messages
188
It's MUI since it's instant (there are no waits or timers). It is simply impossible for two players to cast it at exactly the same time, so it's quite safe.

You're leaking a unit group:
  • Unit Group - Pick every unit in (Units within 500.00 of tempPoint) and do (Actions)
First set a unit group variable to (units within 500 of temp point), then pick every unit in this temp group.

When you're done with it,
  • Custom script: call DestroyGroup( udg_tempGroup )

oh whew i was scared that someone would point out a million things i did wrong :p this makes me pretty happy lol. fixed the unit group's that leaked in the trigger. thanks for pointing it out.

oh thanks for letting me know that about MUI, good thing to know.
 
Last edited:
Level 30
Joined
Nov 29, 2012
Messages
6,637
I cant why understand if in your first ITE, you putted in the If the Target has no buff Defender then in the Then you made another ITE that when in If, you putted If the target has buff equal to Defender..... why?

But as far as I can see... thats all I spot and there's nothing wrong.
 
Level 6
Joined
Feb 10, 2011
Messages
188
I cant why understand if in your first ITE, you putted in the If the Target has no buff Defender then in the Then you made another ITE that when in If, you putted If the target has buff equal to Defender..... why?

But as far as I can see... thats all I spot and there's nothing wrong.

i put it in the first ITE so that the trigger only happens if it the unit is not already considered the base defender (only the base defender has that buff) in the second ITE i did it so it ONLY picks the unit that is considered the defender, so i can set the defender to tempunit1.

get it ?

haha now i feel like maybe i am doing something wrong :p

lmk what u think


Well I do not want to double post so from here down is about the changing base ownership when taken over by another player.

Alright guys this trigger has me stummped. It is the trigger that changes the base and tower owner when a player kills another players defender for the base.

Lets me explain a few things first

1.I need it to count how many units are within a distance about as big as the circle of power that are owned by the owner of the base.
2. If there is 0 units owned by that player, Then the attacking player would gain control of the base.
3. If there is more units within the distance of the defending player, when the "defender" dies, it will automatically switch the defender of the base to another unit (owned by the defending player) within the distance. (this part is not in the trigger yet, because I'm stuck on #2)
4. When part 2 is supposed to happen, I plan on making it so that the weakest attacking unit (health and stats wise) will become the defender. (this is not in the trigger yet, as I'm not sure on how to go about this and I want to get part 2. down right before I go on)

Now here is a rough draft of the trigger, (i made it to get a basic idea of what i would have to do, ignore the leaks) it only switches defenders and changes the bases owner, it all works properly.
  • Change Base Owner1
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (((Dying unit) has buff Defender (BUFF)) Equal to True) or (((Dying unit) is in StartingDefenders) Equal to True)
        • Then - Actions
          • Set tempPoint = (Position of (Dying unit))
          • Set tempUnit = (Killing unit)
          • Unit - Move tempUnit instantly to tempPoint
          • Unit Group - Pick every unit in (Units within 500.00 of tempPoint) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A structure) Equal to True
                • Then - Actions
                  • Unit - Change ownership of (Picked unit) to (Owner of tempUnit) and Change color
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Picked unit)) Equal to Guardtower Normal
                    • Then - Actions
                      • Unit - Order (Picked unit) to Orc Raider - Ensnare tempUnit
                    • Else - Actions
                • Else - Actions
        • Else - Actions
Here is the more complex version, which I'm having trouble with, For some reason only the bases tower will switch owner and the barracks owner will remain the same player as the previous defender.
  • Change Base Owner
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set tempUnit = (Dying unit)
      • Set tempPoint = (Position of tempUnit)
      • Set tempPlayer1 = (Owner of tempUnit)
      • Set tempGroup = (Units in (Region centered at tempPoint with size (100.00, 100.00)) owned by tempPlayer1)
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Set tempGroup1 = (Units in (Region centered at (Position of tempUnit) with size (100.00, 100.00)) matching (((Picked unit) is A structure) Equal to False))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in tempGroup1) Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((tempUnit has buff Defender (BUFF)) Equal to True) or ((tempUnit is in StartingDefenders) Equal to True)
                • Then - Actions
                  • Set tempUnit1 = (Killing unit)
                  • Unit - Move tempUnit1 instantly to tempPoint
                  • Set tempGroup2 = (Units within 300.00 of tempPoint)
                  • Unit Group - Pick every unit in tempGroup2 and do (Actions)
                    • Loop - Actions
                      • Set tempUnit2 = (Picked unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (tempUnit2 is A structure) Equal to True
                        • Then - Actions
                          • Unit - Change ownership of tempUnit2 to (Owner of tempUnit1) and Change color
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Unit-type of tempUnit2) Equal to Guardtower Normal
                            • Then - Actions
                              • Unit - Order tempUnit2 to Orc Raider - Ensnare tempUnit1
                              • -------- Clear Leaks --------
                              • Custom script: set udg_tempUnit = null
                              • Custom script: set udg_tempUnit1 = null
                              • Custom script: set udg_tempUnit2 = null
                              • Custom script: call RemoveLocation( udg_tempPoint )
                              • Custom script: set udg_tempPlayer1 = null
                              • Custom script: call DestroyGroup( udg_tempGroup )
                              • Custom script: call DestroyGroup( udg_tempGroup1 )
                              • Custom script: call DestroyGroup( udg_tempGroup2 )
                            • Else - Actions
                        • Else - Actions
                • Else - Actions
            • Else - Actions

I can upload the map if needed so you guys can check it out.
 
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
  • Set tempGroup1 = (Units in (Region centered at (Position of tempUnit) with size (100.00, 100.00)) matching (((Picked unit) is A structure) Equal to False))
Should be checking for (Matching unit).

Note this leaks:
(Region centered at (Position of tempUnit) with size (100.00, 100.00))

Your trigger is getting quite complex, a better way would be to use a unit indexer. http://www.hiveworkshop.com/forums/spells-569/gui-unit-indexer-1-2-0-2-a-197329/

The unit indexer automatically ensures that every unit has a unique Custom Value, so it can be reliably used as an array number for any variables.
Make a variable to store the defender's barracks, let's call it DefendersBarracks[ ].
When you set your defender, set DefendersBarracks[Custom value of defender] = barracks.

Now in this trigger, instead of using a unit group to find the barracks, you use the defender's custom value to find which barracks it is, this should simplify your trigger somewhat.

As for picking the weakest unit, try this:
Code:
set tempHP = 999999
set tempUnit = no unit
pick every unit in group and do:
 if picked unit HP < tempHP
  set tempUnit = picked unit
  set tempHP = picked unit HP
 
Level 6
Joined
Feb 10, 2011
Messages
188
  • Set tempGroup1 = (Units in (Region centered at (Position of tempUnit) with size (100.00, 100.00)) matching (((Picked unit) is A structure) Equal to False))
Should be checking for (Matching unit).

Note this leaks:
(Region centered at (Position of tempUnit) with size (100.00, 100.00))

Your trigger is getting quite complex, a better way would be to use a unit indexer. http://www.hiveworkshop.com/forums/spells-569/gui-unit-indexer-1-2-0-2-a-197329/

The unit indexer automatically ensures that every unit has a unique Custom Value, so it can be reliably used as an array number for any variables.
Make a variable to store the defender's barracks, let's call it DefendersBarracks[ ].
When you set your defender, set DefendersBarracks[Custom value of defender] = barracks.

Now in this trigger, instead of using a unit group to find the barracks, you use the defender's custom value to find which barracks it is, this should simplify your trigger somewhat.

As for picking the weakest unit, try this:
Code:
set tempHP = 999999
set tempUnit = no unit
pick every unit in group and do:
 if picked unit HP < tempHP
  set tempUnit = picked unit
  set tempHP = picked unit HP

hmm ok thank you, time to start reading haha, ill post again once i understand the custom value thing, I've seen it before but never messed with it.
 
Level 6
Joined
Feb 10, 2011
Messages
188
Take your time and maybe make a spell or two so that you're comfortable with it.

is there any good tutorials that just focuses on how to use custom values?

if not i will just have to play with it, then i will try making some spells and see how it comes out. good thing i dont have work tomorrow.
 
Level 6
Joined
Feb 10, 2011
Messages
188
Ok i just got done editing the change unit owner spell. i removed 2 of the ITE blocks and just set variables using conditions, let me know if it was a good idea (original version of the trigger is in the first post.)

  • Change Defender Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Ability being cast) Equal to Select New Defender ) and ((((Target unit of ability being cast) is in BaseDefenders) Equal to False) and (((Target unit of ability being cast) is An Ancient) Equal to False))
        • Then - Actions
          • -------- Set Casting Unit --------
          • Set tempPoint = (Position of (Casting unit))
          • -------- Set Current Defender & Position --------
          • Set tempGroup = (Units within 500.00 of tempPoint matching (((Matching unit) is in BaseDefenders) Equal to True))
          • Set tempUnit1 = (Random unit from tempGroup)
          • Set tempPoint1 = (Position of tempUnit1)
          • -------- Set New Defender & Position --------
          • Set tempUnit2 = (Target unit of ability being cast)
          • Set tempPoint2 = (Position of tempUnit2)
          • -------- Swap Defenders & Remove/Add Buffs --------
          • Unit - Remove All buffs from tempUnit1
          • Unit Group - Remove tempUnit1 from BaseDefenders
          • Unit - Move tempUnit1 instantly to tempPoint2
          • Unit - Move tempUnit2 instantly to tempPoint1
          • Unit Group - Add tempUnit2 to BaseDefenders
          • Set tempGroup1 = (Units within 500.00 of tempPoint2 matching ((Unit-type of (Matching unit)) Equal to Guardtower Normal))
          • Set tempUnit3 = (Random unit from tempGroup1)
          • Unit - Order tempUnit3 to Orc Raider - Ensnare tempUnit2
          • Game - Display to (All players) the text: then1
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_tempPoint )
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempUnit1 = null
          • Custom script: set udg_tempUnit2 = null
          • Custom script: set udg_tempUnit3 = null
          • Custom script: call DestroyGroup( udg_tempGroup )
          • Custom script: call DestroyGroup( udg_tempGroup1 )
        • Else - Actions
          • Game - Display to (All players) the text: else1
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Select New Defender
          • ((Target unit of ability being cast) is in BaseDefenders) Equal to True
        • Then - Actions
          • Set tempUnit = (Casting unit)
          • Unit - Order tempUnit to Stop
          • Set tempPlayer = (Owner of tempUnit)
          • Game - Display to (All players matching ((Owner of tempUnit) Equal to tempPlayer)) the text: That unit is alread...
          • Custom script: set udg_tempUnit = null
          • Custom script: set udg_tempPlayer = null
        • Else - Actions
oh and for some reason my then and else is firing when the trigger happens

could anyone tell me why
 
Level 6
Joined
Feb 10, 2011
Messages
188
or sorry i forgot to update that post, i actually ended up re doing a lot of that trigger (took me all day, i found out the way i had it was super buggy, and ability being cast wasnt working in the ITE block condition) this is the newest version, but i can do the and's for the condition. i'll actually go do it right now, and clean the trigger up a bit, then edit this post.


there we go, i cleaned it up a bit.

  • Change Defender
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Select New Defender
    • Actions
      • -------- Set New Defender & Position --------
      • Set tempUnit = (Target unit of ability being cast)
      • Set tempPoint = (Position of tempUnit)
      • -------- Set Casting Unit and Owner --------
      • Set tempUnit1 = (Triggering unit)
      • Set tempPlayer = (Owner of tempUnit1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (((Target unit of ability being cast) is in BaseDefenders) Equal to False) and ((((Target unit of ability being cast) is An Ancient) Equal to False) and ((Owner of tempUnit) Equal to tempPlayer))
        • Then - Actions
          • -------- Set Casting Unit Position --------
          • Set tempPoint1 = (Position of tempUnit1)
          • Set tempGroup = (Units within 500.00 of tempPoint1 matching (((Matching unit) is in BaseDefenders) Equal to True))
          • -------- Set Current Defender & Position --------
          • Set tempUnit2 = (Random unit from tempGroup)
          • Set tempPoint2 = (Position of tempUnit2)
          • -------- Swap Defenders & Remove/Add Buffs --------
          • Unit - Remove All buffs from tempUnit2
          • Unit Group - Remove tempUnit2 from BaseDefenders
          • Unit - Move tempUnit2 instantly to tempPoint
          • Unit - Move tempUnit instantly to tempPoint2
          • Unit Group - Add tempUnit to BaseDefenders
          • Set tempGroup1 = (Units within 500.00 of tempPoint1 matching ((Unit-type of (Matching unit)) Equal to Guardtower Normal))
          • Set tempUnit3 = (Random unit from tempGroup1)
          • Unit - Order tempUnit3 to Orc Raider - Ensnare tempUnit
          • -------- Clear Leaks --------
          • Custom script: call RemoveLocation( udg_tempPoint1 )
          • Custom script: call RemoveLocation( udg_tempPoint2 )
          • Custom script: set udg_tempUnit2 = null
          • Custom script: set udg_tempUnit3 = null
          • Custom script: call DestroyGroup( udg_tempGroup )
          • Custom script: call DestroyGroup( udg_tempGroup1 )
        • Else - Actions
          • Unit - Order tempUnit1 to Stop
          • Set tempForce = (All players matching ((Owner of tempUnit1) Equal to tempPlayer))
          • Game - Display to tempForce the text: Pick a different un...
      • Custom script: call RemoveLocation( udg_tempPoint )
      • Custom script: call DestroyForce ( udg_tempForce)
      • Custom script: set udg_tempUnit = null
      • Custom script: set udg_tempUnit1 = null
      • Custom script: set udg_tempPlayer = null
 
Last edited:
Level 25
Joined
Jul 10, 2006
Messages
3,315
I'm not 100% sure, but I think this leaks a force: (player group)
  • Game - Display to (All players matching ((Owner of tempUnit1) Equal to tempPlayer)) the text: Pick a different un...
Make a player group variable, say tempForce.
Then do:
  • Set tempForce = (All players matching ((Owner of tempUnit1) Equal to tempPlayer)
  • Game - Display message to tempForce
  • Custom script: call DestroyForce( tempForce )
 
Status
Not open for further replies.
Top