Saturday, April 14, 2012

Item Combine

[:1]Hello,

I have a slight problem in a map I am creating. I will do my best to describe it without entering in the details of the map.

There is an "Income Unit" that receives six random items out of 80 possibilities, each "round" of the game. You then select one of these items, and depending on their "class" (i.e. Magic, armor, etc... let's call these "classes" 1,2,3,4), then one of four units receives the selected item (i.e. Unit 1 receives the selected item if it is of class "1").

What I am trying to do is, when a unit has 3 of the same item in his inventory, an ability appears in his ability panel that will combine these 3 items into a more powerful one when used. The only way I have found to do this is to create 160 variables that each count the amount of a particular item in a unit's inventory, and to give said unit the ability to combine the item if the count is equal to 3. What I want to do looks like this:

================================================== =======

Events

-"Unit 1" acquires an item.

-"Unit 1" loses an item.

Conditions

Actions

-For each (Integer A) from 1 to 6, do (Actions)

Loop - Actions

If ((Item-type of (Item carried by "Unit 1" in slot (Integer A))) equal to "Item 1" then do (Set "Var_Count_Item1" = ("Var_Count_Item1" + 1)) else do (Do nothing)

-If ("Var_Count_Item1" Greater than or equal to 3) then do (Unit - Add "Combine item 1 ability" to "Unit 1") else do (Unit - Remove "Combine item 1 ability" from "Unit 1"

================================================== =======

I would make such actions for each of the 4 units and each of the 80 items. But then, I also need another set of 80 variables and 80 loops like above for the "Income Unit" (i.e. If Income Unit has 3+ item 1 then add ability to combine.....) because I want it so that you can directly combine an item at the income unit if you're lucky enough to get 3 choices of the same item in a single round.

So, this makes 160 variables and a trigger 160 times the length of the one above. In my opinion, my method is inefficient and painful and long to accomplish. Would any of you mapmakers out there know a better way to proceed?

Sorry if my post was long, I tend to over describe simple things

Thanks in advance!|||i'll see if i can figure something out...|||I think this is too advance for GUI, a ton of triggers are needed..

Maybe JASS should do it..|||This is very easy. Just follow the tutorial here: http://world-editor-tutorials.thehel...php?view=58826.

Hope I helped!|||Thanks for your tutorial link evilwolf, but that is for combining items of different item-types, what I want is to combine 3 of the same items. I can't use "Unit has an item of type ...." because there is no way to check if a unit has 3 different instances of the same item-type.

Anyways, I have figured something out. It is more or less what I had described in my previous post, but with using Array variables. I am in a bit of a hurry so I can't post what the trigger looks like, but let's just say that instead of having 80 different variables for each item, there is 1 variable "Item" with an array size of 80, and this way I can use a loop that runs 80 times and that checks if the unit has an item of type "Item[Integer A]" in his different slots. There is 1 "Counter" variable that resets to 0 at the start of each loop, and at the end of each loop if "Counter" is greater than 3 then it adds the ability "Ability[Integer A]" to the unit, which are the combine abilities.

Of course this means that I had to do a trigger to set each index 1 to 80 of both "Item[]" and "Ability[]" to desired values (Item[1] = Item 1, Ability[1] = Ability 1, etc). It was painful but with a bit of patience I took care of it :P. At least, it makes the main trigger very short and I could say relatively efficient.

Suggestions are still welcome if anyone thinks of something even better, but I believe my problem is solved. Later everyone :)



Edit: Oops, sorry evilwolf, I see there is indeed a section for combining more than one item of the same item-type at the bottom of the tutorial you linked. I hadn't scrolled down enough to see it. Thank you, I'll check it out!

No comments:

Post a Comment