- Joined
- Jan 6, 2008
- Messages
- 2,627
NOTE: I used Jass Newgen Pack for the triggers, if you cant do something thats inside this tutorial, you might need to download and use Jass Newgen Pack.
This Tutorial Contains!
FAQ about Variables
You need to be creative with Variables, and understand them.Variables are used for storing stuff. Variables are important for a smooth and efficient operation of your maps. They are nessessary for preventing leaks attached to the wait command. So if you are going to use a wait command and then do actions with a Unit, Destructible, Item, Floating Text, Special effects or other, you have to set temparary variables to prevent leaks, so you have to do it like this:
-
Variable Initalization
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
Set TempPoint = (Point(0.00, 0.00))
-
Unit - Create 1 Footman for Player 1 (Red) at TempLoc facing 90.00 degrees
-
Set TempUnit = (Last created unit)
-
Wait 2.00 seconds
-
Unit - Explode TempUnit
-
Custom script: call RemoveLocation(udg_TempPoint)
-
-
So it gets stored and cant be failed if another unit gets created before it explodes.
So to sum up the FAQ in some few words:
Variables stores the Unit or what you are using so you can use it later without making the trigger leak.
Variable List
Well, basicly here i will make an image of every single Variable you can find.Now that you know that, lets continue
Use of Arrays
Now, arrays are all about storing stuff, and make every single thing do something, or just make it cleaner, it could be used like the example below:Now im using Unit Group, Unit, Integer and Region variables, The unit variable has an array of 100, and a simple loop.
Note: This will make it ALOT easier than setting the units manually.
-
Set TempRegion = Region 000 <gen>
-
Set TempUnit_Group = (Units in TempRegion)
-
Unit Group - Pick every unit in TempUnit_Group and do (Actions)
-
Loop - Actions
-
Set TempInteger = (TempInteger + 1)
-
Set TempUnit2[TempInteger] = (Picked unit)
-
-
-
Custom script: call DestroyGroup(udg_TempUnit_Group)
The variables are TempPoint, Ability,
Now, this is the whole trigger ive got. This orders all the units in the region to Blink.
BAD VERSION
-
Bad Version
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
Unit - Add Blink to Mountain King 0001 <gen>
-
Unit - Order Mountain King 0001 <gen> to Night Elf Warden - Blink (Random point in (Playable map area))
-
Unit - Add Blink to Mountain King 0018 <gen>
-
Unit - Order Mountain King 0018 <gen> to Night Elf Warden - Blink (Random point in (Playable map area))
-
Unit - Add Blink to Mountain King 0032 <gen>
-
Unit - Order Mountain King 0032 <gen> to Night Elf Warden - Blink (Random point in (Playable map area))
-
-------- And so on --------
-
Wait 2.00 seconds
-
Unit - Remove Blink from Mountain King 0001 <gen>
-
Unit - Remove Blink from Mountain King 0018 <gen>
-
Unit - Remove Blink from Mountain King 0032 <gen>
-
-------- And so on --------
-
-
-
Variable Initalization
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Visibility across (Playable map area)
-
Set TempPoint = (Point(0.00, 0.00))
-
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 90.00 degrees
-
Set TempUnit = (Last created unit)
-
Custom script: call RemoveLocation(udg_TempPoint)
-
Set TempRegion = Region 000 <gen>
-
Set TempUnit_Group = (Units in TempRegion)
-
Unit Group - Pick every unit in TempUnit_Group and do (Actions)
-
Loop - Actions
-
Set TempInteger = (TempInteger + 1)
-
Set TempUnit2[TempInteger] = (Picked unit)
-
-
-
Custom script: call DestroyGroup(udg_TempUnit_Group)
-
Set TempAbility = Blink
-
For each (Integer A) from 1 to TempInteger, do (Actions)
-
Loop - Actions
-
Unit - Add TempAbility to TempUnit2[(Integer A)]
-
Set TempPoint = (Random point in (Playable map area))
-
Unit - Order TempUnit2[(Integer A)] to Night Elf Warden - Blink TempPoint
-
Custom script: call RemoveLocation(udg_TempPoint)
-
-
-
Wait 2.00 seconds
-
For each (Integer A) from 1 to TempInteger, do (Actions)
-
Loop - Actions
-
Unit - Remove TempAbility from TempUnit2[(Integer A)]
-
-
-
-
So to tell what arrays are used for in a sentece:
An array allows one variable to store more than one set of data.
Leaks
Leaks are horrible, you could say they are some kind of infection to the maps since they cause lag and errors.I will post the common leaks here.
The most known leaks are ofcourse
-
Custom script: call RemoveLocation(udg_PointVariableName!)
-
Custom script: call DestroyGroup(udg_Unit_GroupVariableName!)
Example:
BAD VERSION
-
Bad Version
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
Set TempPoint = (Position of TempUnit)
-
Special Effect - Create a special effect at TempPoint using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
-
Custom script: call RemoveLocation(udg_TempPoint)
-
Wait 4.00 seconds
-
Special Effect - Destroy (Last created special effect)
-
-
-
Special Effect
-
Events
-
Time - Elapsed game time is 1.00 seconds
-
-
Conditions
-
Actions
-
Set TempPoint = (Position of TempUnit)
-
Special Effect - Create a special effect at TempPoint using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
-
Set TempSpecial_Effect = (Last created special effect)
-
Custom script: call RemoveLocation(udg_TempPoint)
-
Wait 4.00 seconds
-
Special Effect - Destroy TempSpecial_Effect
-
-
-
Special Effect
-
Events
-
Time - Elapsed game time is 1.00 seconds
-
-
Conditions
-
Actions
-
Set TempPoint = (Position of TempUnit)
-
Special Effect - Create a special effect at TempPoint using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
-
Special Effect - Destroy (Last created special effect)
-
Custom script: call RemoveLocation(udg_TempPoint)
-
-
MPI Variables
Now, this part is actually very easy, you just need to use the Number code in the array Player Number of Triggering Player/Owner of Triggering Unit and so on. The same about the units, you could use something like this:WRONG WAY
-
Bad Version
-
Events
-
Unit - A unit enters Region 000 <gen>
-
-
Conditions
-
Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Owner of (Triggering unit)) Equal to Player 1 (Red)
-
-
Then - Actions
-
Set TempUnit3[1] = (Triggering unit)
-
-
Else - Actions
-
-
-------- And all the players --------
-
-------- Do your actions like this --------
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Owner of (Triggering unit)) Equal to Player 1 (Red)
-
-
Then - Actions
-
-------- Actions --------
-
-
Else - Actions
-
-
-
First we need to set the actions, this is a good trick.
-
Set MPI
-
Events
-
Time - Elapsed game time is 0.00 seconds
-
-
Conditions
-
Actions
-
-------- Setup the type of the actions you want to add in MPI --------
-
-------- Im gonna add a different String that can be used as a floating text for every players --------
-
Set TempString[1] = LUL
-
Set TempString[2] = Im'a Player 2
-
Set TempString[3] = Play0r 3 in da Hause
-
Set TempString[4] = Im fat
-
Set TempString[5] = someone up for laughing??
-
Set TempString[6] = And just make this for every player
-
-
-
MPI
-
Events
-
Unit - A unit enters Region 000 <gen>
-
-
Conditions
-
Actions
-
Set TempUnit3[(Player number of (Owner of (Triggering unit)))] = (Entering unit)
-
For each (Integer A) from (Player number of (Owner of (Triggering unit))) to (Player number of (Owner of (Triggering unit))), do (Actions)
-
Loop - Actions
-
-------- Variable Setup Functions --------
-
Floating Text - Create floating text that reads TempString[(Integer A)] above TempUnit3[(Integer A)] with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
-
Set TempFloating_Text[(Integer A)] = (Last created floating text)
-
Floating Text - Set the velocity of TempFloating_Text[(Integer A)] to 64.00 towards 90.00 degrees
-
Floating Text - Change TempFloating_Text[(Integer A)]: Enable suspend state
-
Floating Text - Change TempFloating_Text[(Integer A)]: Disable permanence
-
Floating Text - Change the lifespan of TempFloating_Text[(Integer A)] to 5.00 seconds
-
Floating Text - Change the fading age of TempFloating_Text[(Integer A)] to 4.00 seconds
-
-
-
-
Samples
More samples will be added later, feel free to add some samples, please read these samples and you will understand more.
My inventory setup sample, Not finished, almost done with 1 item.
-
InvItems
-
Events
-
Map initialization
-
-
Conditions
-
Actions
-
-------- 1hSwords --------
-
Do Multiple ActionsFor each (Integer A) from 1 to 1, do (Actions)
-
Loop - Actions
-
-------- Searing Blade --------
-
Set ITEMOneHandedSword[1] = Searing Blade
-
Set DestructibleITEMOneHandSword[1] = Searing Blade
-
Set Item1hSwordDescript[1] = Searing Blade|n|n|c0000FFFFClass:|r 1 Handed Sword|n|n|c0080FF00Requirements|r|n|c00FF8000Level:|r 0|n|c00FF8000Skills needed:|r None|n|c00FF8000Stats:|r 14 Damage, 8 Strength|n|n|c0080FF00Description|r|nA magical blade formed by dwarves.
-
Set ItemOnehandDmg[1] = 14
-
Set Item1hSwordAbilityStats[1] = 8 Strength
-
Set ItemOneHandFxPath[1] = war3mapImported\Searathil.mdx
-
Set ItemOnehandDmgSecondSlot[1] = 14
-
Set Item1hSwordAbilityStatsSecondS[1] = 8 Strength
-
Set ItemOneHandSwordReqlvl[1] = 1
-
-------- ' --------
-
-
-
-
-
-
Do Multiple ActionsFor each (Integer A) from 1 to 1000, do (Actions)
-
Loop - Actions
-
-------- 1h Sword 1st slot --------
-
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
WeaponUsed[1] Equal to (==) False
-
(Hero level of Unit[1]) Equal to (==) ItemOneHandSwordReqlvl[(Integer A)]
-
-
Then - Actions
-
Unit - Remove ItemOneHandSwordUsedabi[1] from Unit[1]
-
Unit - Remove ItemOneHandSwordUsedabi[2] from Unit[1]
-
Unit - Add Item1hSwordAbilityStats[(Integer A)] to Unit[1]
-
Set ItemOneHandSwordUsedabi[2] = Item1hSwordAbilityStats[(Integer A)]
-
Special Effect - Destroy ItemOneHandFx[1]
-
Special Effect - Destroy ItemOneHandFx[2]
-
Hero - Learn skill for Unit[1]: Item1hSwordAbilityStats[(Integer A)]
-
Special Effect - Create a special effect attached to the left,hand of Unit[1] using ItemOneHandFxPath[(Integer A)]
-
Set ItemOneHandFx[1] = (Last created special effect)
-
Special Effect - Create a special effect attached to the left,hand of Unit[2] using ItemOneHandFxPath[(Integer A)]
-
Set ItemOneHandFx[2] = (Last created special effect)
-
Set WeaponUsed[1] = True
-
-
Else - Actions
-
-
-
-------- 1h Sword 2th slot --------
-
Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Hero level of Unit[1]) Equal to (==) ItemOneHandSwordReqlvl[(Integer A)]
-
WeaponUsed[2] Equal to (==) False
-
-
Then - Actions
-
Unit - Remove ItemOneHandSwordUsedabi[3] from Unit[1]
-
Unit - Remove ItemOneHandSwordUsedabi[4] from Unit[1]
-
Set ItemOneHandSwordUsedabi[3] = Item1hSwordAbilityStats[(Integer A)]
-
Unit - Add Item1hSwordAbilityStatsSecondS[(Integer A)] to Unit[1]
-
Set ItemOneHandSwordUsedabi[4] = Item1hSwordAbilityStats[(Integer A)]
-
Special Effect - Destroy ItemOneHandFx[4]
-
Special Effect - Destroy ItemOneHandFx[3]
-
Special Effect - Create a special effect attached to the right,hand of Unit[1] using ItemOneHandFxPath[(Integer A)]
-
Set ItemOneHandFx[3] = (Last created special effect)
-
Special Effect - Create a special effect attached to the right,hand of Unit[2] using ItemOneHandFxPath[(Integer A)]
-
Set ItemOneHandFx[4] = (Last created special effect)
-
Set WeaponUsed[2] = True
-
-
Else - Actions
-
-
-
-
~Slaydon
Attachments
-
Header.png141.1 KB · Views: 221
-
Variables 1.png107.4 KB · Views: 215
-
Variables 2.png66.2 KB · Views: 209
-
Variables 3.png68.3 KB · Views: 235
-
Variables 4.png67.6 KB · Views: 194
-
Variables 5.png63.2 KB · Views: 215
-
Variables 6.png64.2 KB · Views: 197
-
Variables 7.png62.4 KB · Views: 212
-
Variables 8.png62.3 KB · Views: 204
-
Variables 9.png63.8 KB · Views: 210
-
Variables 10.png34 KB · Views: 194
Last edited: