• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Set chance

Status
Not open for further replies.
Level 3
Joined
Mar 1, 2015
Messages
53
How can I make spell with set chance in command?
I can't find an option to do it.

code example:
Code:
Trigger
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Your Ability
    Actions
        Set Chance = (Random integer number between 1 and 2)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                Chance Equal to 0
            Then - Actions
                -------- then actions --------
            Else - Actions
                -------- else actions --------
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Use trigger tags like this:
  • Your trigger [/ trigger]
  • [hidden=Quoted in trigger tags:] [trigger]Trigger
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Your Ability
    • Actions
      • Set Chance = (Random integer number between 1 and 2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Chance Equal to 0
        • Then - Actions
          • -------- then actions --------
        • Else - Actions
          • -------- else actions --------
[/hidden]Yes, this is the trigger you need except
  • Chance Equal to 0
this should be either 1 or 2.


Or are you asking how to make this line ?
  • Set Chance = (Random integer number between 1 and 2)
"Chance" is a user created variable which you make with the variable editor (the yellow X on top, near the other editors). This particular one should be of type "Integer"
The action is called "Set Variable"
For the left side you chose the newly created variable, and for the right side you find from the drop-down menu something called "Math - Random number"
 
Level 3
Joined
Mar 1, 2015
Messages
53
OK but how to do the rest?
Is there a tutorial on how to find all those set chance, if all conditions are true etc?
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Umm... yes... and no. As I remember, there is a thread listing all events/conditions/actions but it does not explain them very well or go in depth. Most of them are self explanatory.

If you like read some introduction to programming tutorial about variables, loops and basic stuff you will probably understand how they work.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I don't really understand in what you want to learn more about chances but this might be helpfull:

Pick a number between 0 and 99 (0 and 99.99 for reals)
If random is lower than change Then (percentage check where chance is the chance of succession.)

When you have to pick one out of a set where the total is dynamic:
Example item drop:
Item[1] has 10 chance
Item[2] has 60 chance
Item[3] has 1 chance

Pick a number between 0 and (10 + 60 + 1)
loop TempInteger between 1 and 3
set random = random - Chance[TempInteger]
If random is lower than or equal too 0 Then Spawn Item[TempInteger]


Next to these 2... there are like 200 more different types of chance calculations.
These 2 are (I think) the most used ones.
I am not going to write them all down ;)
 
Level 3
Joined
Mar 1, 2015
Messages
53
Ok It works, but how can I put more then,else actions?
for example

then(random 1)
else(random 2)

then(random 3)
else(random 4)

I tried doing
  • Set Chance = (Random integer number between 1 and 4)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • Chance Equal to 1
    • Then - Actions
    • -------- then actions --------
    • Else - Actions
    • -------- else actions --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
    • Chance Equal to 3
    • Then - Actions
    • -------- then actions --------
    • Else - Actions
    • -------- else actions --------
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well the best (most read-friendly) option is this:
  • Random Number
    • Actions
      • Set RANDOM = (Random integer number between 1 and 4)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RANDOM Equal to 1
        • Then - Actions
          • -------- Do action 1 --------
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RANDOM Equal to 2
        • Then - Actions
          • -------- Do action 2 --------
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RANDOM Equal to 3
        • Then - Actions
          • -------- Do action 3 --------
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RANDOM Equal to 4
        • Then - Actions
          • -------- Do action 4 --------
          • Skip remaining actions
        • Else - Actions
 
Level 3
Joined
Mar 1, 2015
Messages
53
It works but theres another problem: the movement speed of units that spell is casted is not going to defualt.
  • Actions
    • Set random = (Random integer number between 1 and 3)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • random Equal to 1
      • Then - Actions
        • Unit - Set (Target unit of ability being cast) movement speed to 300.00
        • Wait 6.00 game-time seconds
        • Unit - Set (Target unit of ability being cast) movement speed to (Default movement speed of (Target unit of ability being cast))
        • Skip remaining actions
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • random Equal to 2
      • Then - Actions
        • Unit - Set (Target unit of ability being cast) movement speed to 1200.00
        • Wait 6.00 game-time seconds
        • Unit - Set (Target unit of ability being cast) movement speed to (Default movement speed of (Target unit of ability being cast))
        • Skip remaining actions
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • random Equal to 3
      • Then - Actions
        • Unit - Set (Target unit of ability being cast) movement speed to 50.00
        • Wait 6.00 game-time seconds
        • Unit - Set (Target unit of ability being cast) movement speed to (Default movement speed of (Target unit of ability being cast))
        • Skip remaining actions
      • Else - Actions
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Because you use waits and dont save the unit.
The variables are lost when you put a wait action inside the trigger.

The best thing to do is just use a timer system (my Effect Over Time System is my personal favorite) and set the speed back when the effect expires.
 
Level 3
Joined
Mar 1, 2015
Messages
53
I think this one will be more efficient for my effect: http://www.hiveworkshop.com/forums/...279/mui-spells-using-artificial-waits-223315/
but yet again I have a problem
  • Cast
  • Events
  • Unit - A unit Starts the effect of an ability
  • Conditions
  • (Ability being cast) Equal to Animate Dead
  • Actions
  • Set MaxIndex = (MaxIndex + 1)
  • -------- Here's the bit we had in the first place before the wait --------
  • Set TempUnit[MaxIndex] = (Triggering unit)
  • Set TempPoint[MaxIndex] = (Position of TempUnit[MaxIndex])
  • -------- ----------------- --------
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • MaxIndex Equal to 1
  • Then - Actions
  • Trigger - Turn on Loop <gen>
  • Else - Actions
  • Loop
  • Events
  • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
  • For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)
  • Loop - Actions
  • -------- Here's the bit we had in the first place after the wait --------
  • Set TempGroup = (Units within 200.00 of TempPoint[CurrentIndex])
  • Unit Group - Pick every unit in TempGroup and do (Actions)
  • Loop - Actions
  • Unit - Cause TempUnit[CurrentIndex] to damage (Picked unit), dealing 50.00 damage of attack type Spells and damage type Normal
  • Custom script: call DestroyGroup(udg_TempGroup)
  • -------- This is recycling. It's unimportant in terms of spell effects, but it is important in terms of MU-Instancability --------
  • Custom script: call RemoveLocation(udg_TempPoint[udg_CurrentIndex])
  • Set TempPoint[CurrentIndex] = TempPoint[MaxIndex]
  • Set TempUnit[CurrentIndex] = TempUnit[MaxIndex]
  • Set MaxIndex = (MaxIndex - 1)
  • Set CurrentIndex = (CurrentIndex - 1)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • MaxIndex Equal to 0
  • Then - Actions
  • Trigger - Turn off (This trigger)
  • Else - Actionsp
for example how do I create such veriable?
  • Set MaxIndex = (MaxIndex + 1)
How I am supposed to know how to make every variable in this trigger?
 
Level 6
Joined
Oct 31, 2014
Messages
170
Is " Skip remaining actions" important to the trigger ? Never used it and never had problems... does it prevent leaks or ..?

good luck with your map L :p
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well because your random value is 1 (for example), you automatically know that it is not 2 and not 3 and not 4.
To improve game performance, you can tell the game to just not check for the other numbers by skipping the remaining actions.

Just performance but works without too.
 
Status
Not open for further replies.
Top