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!
Hey guys, still having trouble wrapping my head around how variables and arrays work. An example of what I need would be a trigger where whenever a high level monster dies there is a 10% chance it will drop a random item from a high level item group, with only one of each item ever dropping.
Honestly I would suggest you use the itempool type found in JASS to do this since it will be much, much simpler but since you don't understand arrays I'm going to assume you're using all GUI. First step is to set up the pool of N possible items:
Events
Time - Elapsed game time is 0.10 seconds
Conditions
Actions
Set ItemCount = 0
-------- --------
Set ItemCount = ItemCount + 1
Set ItemArray[ItemCount] = Ring of Power
-------- --------
Set ItemCount = ItemCount + 1
Set ItemArray[ItemCount] = Sword of Slicing
-------- --------
Set ItemCount = ItemCount + 1
Set ItemArray[ItemCount] = Big Bad Book
-------- repeat as necessary for all items in the drop pool --------
Set ItemCount = ItemCount + 1
Set ItemAray[ItemCount] = TheLastItem
Then when a unit dies if the 10% chance is met spawn a random item from the possible pool and then remove it from the pool:
Events
Unit - A Unit dies
Conditions
-------- this condition is necessary: --------
(Random integer from 1 to 10) less than or equal to 1
-------- will need some condition to check it's a high level creep, so you can make a gorup of them all or check by unit type id since I couldn't find a "get creep level" function in common.j or blizzard.j --------
-------- below are two example conditions you might use --------
(Triggering Unit) is in HIGH_LEVEL_CREEP_GROUP
-------- --------
Or - Any condition is true
(Unit-type of (Triggering Unit)) equal to BEAR
(Unit-type of (Triggering Unit)) equal to LION
(Unit-type of (Triggering Unit)) equal to WITCH
-------- continue as necessary --------
Actions
Set TempPoint = (Position of (Triggering Unit))
Set RandItem = (Random integer from 1 to ItemCount)
Item - Create 1 ItemArray[RandItem] at TempPoint
Custom script: call RemoveLocation(udg_TempPoint) //this cleans the point leak, look up the tutorial "things that leak" if you don't understand
In general, yeah what Pyrogasm said is what you need. I'm just gonna try and explain variables and arrays.
--------
Variables and arrays are life blood in programming, and they are very simple to understand - though they can be used in so many ways, and so beginners may feel they don't understand them. It really is dead simple.
A variable is a reference to a part in computer's memory, given a name. The main purpose of a variable is so that programmer can find it (i.e. easily and obviously accurately tell the program where to find it). There are many ways to save data to memory, and this data can be pretty much anything (a whole number, i.e. integer; a unit reference; a player's name etc.). A variable's name however allows you to find that specific unit (or whatever data) you saved. In your request you're looking for
"...a high level..."
So that's likely a variable. You can save the level as a whole number (integer) and then compare to that number when a monster dies was it of high enough level.
In most programming languages, and in what is used with Warcraft III, a variable must have its type defined as well (in this case an integer) in advance.
So a variable is: a name, a type, and a value (including "not-having-a-value", so-called null)
HighLevelMonster = 6
(yep that's literally it)
(this is fake code example how a variable is assigned. The name can be anything you like, i.e. whatever name you find most useful)
if LevelOf(DyingMonster) >= HighLevelMonster -> do stuff
(fake code again, its only point is to show how the variable is used)
From Pyrogasm's example
Set ItemCount = 0
means setting the variable named ItemCount (of type integer) to 0. It's really not that complicated
Here's an additional useful thing about variables (and there are many many of them) - if you decide later that HighLevelMonster should be of level 5, you can change it in one place, instead of going through the code. You might be thinking, well I won't, but that's not the point. Not only that you can decide, but you can have the program decide and change the value with time (e.g. as game progresses, a higher level of monster needs to be slain to drop an item). If you won't be changing the variable, then after all you might need a constant. (Yeah they really are called variables and constants, programming is A LOT about naming)
--------
An array is a type of variable which holds a list of things. It can hold the same as the variable example above whole numbers, units, names etc. but the point is that it's a list. (Well technically, the word "list" is usually associated with another type of variable, but to keep it simple, it'll suffice).
Array is numbered starting from 0 and up to a maximum which may or may not be defined (in Warcraft 3 GUI editor it is preset at like 4096 number of maximum place or some number like that, doesn't really matter at this point). So e.g. if you need player names, you could've stored them in an array (of type string) at the start of the game, and when you need the first name you call it by PlayerNames[0] (0 because arrays start with 0 and not 1; so the fifth in the list would be at [4]; and yeah a place in an array is defined in those brackets [ ] in most programming languages).
So if you might need all units you've saved in
unit array CarryingBomb
(as a side note this is also a good example of variables' usefulness, i.e. storing data for later use)
you can iterate through them by accessing every place in the array
IsCarryingBomb[0] -> do stuff
IsCarryingBomb[1] -> do stuff
IsCarryingBomb[2] -> do stuff
IsCarryingBomb[3] -> do stuff
...
or in you specific request you're looking for chances for items when monster of level dies.
So we can make it like this: (all of this is intended as pseudo code and this one expects you to have 101 items in your array, which is not something you likely want, but its purpose is only explaining)
Code:
item array ItemDrops = [item0, item1, item2..........]
// are you ready for real looking code? :P
// line prefixed with these / are "comments" and are ignored by the program
if LevelOf(DyingMonster) >= HighLevelMonster do
set RandomRoll = MakeARandomRollFromZeroTo(100)
// means: save me a random number from 0 to 100
DropItem( ItemDrops[RandomRoll] )
// means: drop an item (which item) -> item from ItemDrops [at array index = above saved number]
One option I was thinking of that I wanted to experiment with would be just have a little secret spot on the map and have 1 of each rare item in there, then when a high level creature dies I'll roll the 1-10 and if 1 is rolled just simply move 1 randomly selected item to the position of dying unit. But even if that worked it wouldn't involve any arrays, and I need to learn that
How important is cleaning "leaks" in a map? So far it tests fine and I have dozens of triggers without using that custom script or variable locations :\
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.