• 🏆 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!

Replacing a Spell ?

Status
Not open for further replies.
Level 5
Joined
May 12, 2013
Messages
70
Greetings. I'm working on my map, where you buy spells from the Shop. The Items don't show, you buy the Spell Item and the Item is removed via Triggers. Only the specific spell is added to the hero. Now, the problem is, the hero already has 3 spells by default. So that leaves me with 4 more spells that a hero can buy. Now I want that when the Hero buys the 5th Spell from the Shop ( When he already has 7 Spells ) The first spell that he bought from the Shop is Replaced by the New Spell. Can someone please give me Triggers for this or something ? Any help appreciated.
 
Level 5
Joined
May 12, 2013
Messages
70
Like this :
  • Set Ability[1] = Your_Ability
after you added the ability to unit

- How do I know he has bought 4 spells already so I trigger the 5th one to Replace the 1st one ?
- How do I know which ability he bought first from the Shop ?
Suppose a Unit bought Ability "A" from the shop. I set it to Variable_Spell_1.
Then he buys another Ability "B" from the shop. I set it to Variable_Spell_2.
Now If he Buys "B" before "A", then B will still be stored in Variable_Spell_2 and when he buys 5th spells, I trigger it to Remove Variable_Spell_1, whereas he bought the Variable_Spell_2 First, then He bought 1.
 
Level 11
Joined
Dec 19, 2012
Messages
411
- How do I know he has bought 4 spells already so I trigger the 5th one to Replace the 1st one ?
- How do I know which ability he bought first from the Shop ?
Suppose a Unit bought Ability "A" from the shop. I set it to Variable_Spell_1.
Then he buys another Ability "B" from the shop. I set it to Variable_Spell_2.
Now If he Buys "B" before "A", then B will still be stored in Variable_Spell_2 and when he buys 5th spells, I trigger it to Remove Variable_Spell_1, whereas he bought the Variable_Spell_2 First, then He bought 1.


Do not separate Variable_Spell multiple, use array. Using array is easier for loop to check (If u have large number of spells that selling in shop).
From setting variable and count. When a unit buy ability "B" 1st,it will still set as "1" because it is the first spell the unit buy.
Example:
  • Set Ability[Temp_Integer+1] = Your_Ability
  • Set Temp_Integer = (Temp_Integer + 1)
This should be add after the condition checked the unit does not has that type of spell.
 
Last edited:
Level 5
Joined
May 12, 2013
Messages
70
Thanks. The First issue seems to be solved I guess, I'll try it that way, look It would go Fine. As for as the 2nd problem, I told you I remove the Items as soon as they are bought. Only The spells are added via Triggers.
 
Level 25
Joined
Sep 26, 2009
Messages
2,384
You can store in integer variable the index of the ability that should be replaced.

e.g. if your hero has 3 base abilities, then the integer variable should have value 4. So when he buys new ability, it is saved under Ability[4] (4 here being the value in integer). Then it is just a simple math incrementing and using ITE to check if value is higher than 4. If yes, you set the value back to 1.

e.g. something like this
  • Actions
    • Unit - Remove Ability[index] from your hero
    • Set Ability[index] = Ability gained from shop
    • Unit - Add Ability[index] to your hero
    • Set index = index + 1
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • index is greater than 4
      • Then - Actions
        • Set index = 1
      • Else - Actions
index is that integer variable I wrote about.
 
Level 25
Joined
Sep 26, 2009
Messages
2,384
You could try to make it MPI (multi player instancible)
Each player slot has an unchangeable number - it starts from Player 1 (Red) who has number 1 up to one of the neutral players with index 16.

You can use these numbers as indexes for arrays.

So you make integer variable an array.
For abilities, you can still have 1 ability variable array and use player's number as one number for multiplication.
---
The changes you would have to do would be this:
the index integer would vary from 0 to 3 (instead of 1 to 4 like I posted in my previous post) and the correct ability you want to replace would be
Ability[(player's number * 4 ) + index[player's number] ]

e.g. - you want to replace one of the 4 abilities of player 2 (Blue). This is pseudo code of the system I wrote above:
Code:
Unit buys item
Remove ability[(player number * 4) + index[player number] ]
Add bought ability
Set ability[(player number * 4) + index[player number] ] = add ability
Set index[player number] = index[player number] + 1
If - Conditions
    Index[player number] > 3
Then - Actions
    Set index = 0
Else - Actions

This is how it will work in practice:

Like I wrote, let's say it's player 2 (Blue) who bought the item => his number is 2
We want to find out which ability we want to replace. That is saved inside index[] array. Since we want to access player 2 (Blue)'s integer, we load index[2]. Let's say that the ability that should be replaced is the 3rd ability, so the number inside index is number 2 (you'll soon see why it is 2 and not 3 if you didn't already).

The calculation for loaded ability is [(player number * 4) + index[player number]]
If you add random player number, you will see that you get 4 "slots" per player for each ability.
In case of player 2, the slots are 8-11, because 2*4 is 8 and index can vary from 0 to 3.
Player 5 has slots 20-23, because 5*4 is 20 and index adds 0 to 3.

So when we want to load player 2 (Blue)'s 3rd ability, we load number ability[10], as that is the third ability in slots 8-11.

You can access player's number using the integer condition/action
  • (Player number of *your player*)
It is found under Integer comparison -> Player -> Player number

The above is the basic idea for MPI


This is how it should look:
  • Actions
    • Set num = (Player number of (Triggering player))
    • Unit - Remove Ability[((num x 4) + Index[num])] from (Triggering unit)
    • Unit - Add Avatar to (Triggering unit)
    • Set Ability[((num x 4) + Index[num])] = Avatar
    • Set Index[num] = (Index[num] + 1)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Index[num] Greater than 3
      • Then - Actions
        • Set Index[num] = 0
      • Else - Actions
note: num is integer variable; Index is integer array; Ability is ability array. I used num so I don't have to complicatedly access player's number each time I need to use it, so I just did it once at the start by saving player's number inside num variable.

In this trigger, the Avatar ability was add.
 
Level 5
Joined
May 12, 2013
Messages
70
You could try to make it MPI (multi player instancible)
Each player slot has an unchangeable number - it starts from Player 1 (Red) who has number 1 up to one of the neutral players with index 16.

You can use these numbers as indexes for arrays.

So you make integer variable an array.
For abilities, you can still have 1 ability variable array and use player's number as one number for multiplication.
---
The changes you would have to do would be this:
the index integer would vary from 0 to 3 (instead of 1 to 4 like I posted in my previous post) and the correct ability you want to replace would be
Ability[(player's number * 4 ) + index[player's number] ]

e.g. - you want to replace one of the 4 abilities of player 2 (Blue). This is pseudo code of the system I wrote above:
Code:
Unit buys item
Remove ability[(player number * 4) + index[player number] ]
Add bought ability
Set ability[(player number * 4) + index[player number] ] = add ability
Set index[player number] = index[player number] + 1
If - Conditions
    Index[player number] > 3
Then - Actions
    Set index = 0
Else - Actions

This is how it will work in practice:

Like I wrote, let's say it's player 2 (Blue) who bought the item => his number is 2
We want to find out which ability we want to replace. That is saved inside index[] array. Since we want to access player 2 (Blue)'s integer, we load index[2]. Let's say that the ability that should be replaced is the 3rd ability, so the number inside index is number 2 (you'll soon see why it is 2 and not 3 if you didn't already).

The calculation for loaded ability is [(player number * 4) + index[player number]]
If you add random player number, you will see that you get 4 "slots" per player for each ability.
In case of player 2, the slots are 8-11, because 2*4 is 8 and index can vary from 0 to 3.
Player 5 has slots 20-23, because 5*4 is 20 and index adds 0 to 3.

So when we want to load player 2 (Blue)'s 3rd ability, we load number ability[10], as that is the third ability in slots 8-11.

You can access player's number using the integer condition/action
  • (Player number of *your player*)
It is found under Integer comparison -> Player -> Player number

The above is the basic idea for MPI


This is how it should look:
  • Actions
    • Set num = (Player number of (Triggering player))
    • Unit - Remove Ability[((num x 4) + Index[num])] from (Triggering unit)
    • Unit - Add Avatar to (Triggering unit)
    • Set Ability[((num x 4) + Index[num])] = Avatar
    • Set Index[num] = (Index[num] + 1)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Index[num] Greater than 3
      • Then - Actions
        • Set Index[num] = 0
      • Else - Actions
note: num is integer variable; Index is integer array; Ability is ability array. I used num so I don't have to complicatedly access player's number each time I need to use it, so I just did it once at the start by saving player's number inside num variable.

In this trigger, the Avatar ability was add.


:vw_wtf: Too much... Ummm... Kinda Confusing for Newbie Like me. But anyways, I got the Answer in the Earlier Replies. Thanks both ! Rep +
 
Level 5
Joined
May 12, 2013
Messages
70
Oh, and I did it this way. As I said, I'm a newbie with it, so I don't know much, but please tell If there's an easier or quicker way to do it.
  • Untitled Trigger 017
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to Meat Hook
    • Actions
      • Item - Remove (Sold Item)
      • Wait 0.09 game-time seconds
      • Set Buying_Unit[(Player number of (Owner of (Buying unit)))] = (Player group((Owner of (Buying unit))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Meat Hook [Q] for (Buying unit)) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 1 (Red)
              • Integer_P1 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P1 = (Integer_P1 + 1)
              • Set Spell_P1[Integer_P1] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 2 (Blue)
              • Integer_P2 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P2 = (Integer_P2 + 1)
              • Set Spell_P2[Integer_P2] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 3 (Teal)
              • Integer_P3 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P3 = (Integer_P3 + 1)
              • Set Spell_P3[Integer_P3] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 4 (Purple)
              • Integer_P4 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P4 = (Integer_P4 + 1)
              • Set Spell_P4[Integer_P4] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 5 (Yellow)
              • Integer_P5 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P5 = (Integer_P5 + 1)
              • Set Spell_P5[Integer_P5] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 6 (Orange)
              • Integer_P6 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P6 = (Integer_P6 + 1)
              • Set Spell_P6[Integer_P6] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 7 (Green)
              • Integer_P7 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P7 = (Integer_P7 + 1)
              • Set Spell_P7[Integer_P7] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 8 (Pink)
              • Integer_P8 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P8 = (Integer_P8 + 1)
              • Set Spell_P8[Integer_P8] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 9 (Gray)
              • Integer_P9 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P9 = (Integer_P9 + 1)
              • Set Spell_P9[Integer_P9] = Meat Hook [Q]
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Buying unit)) Equal to Player 10 (Light Blue)
              • Integer_P99 Less than 4
            • Then - Actions
              • Unit - Add Meat Hook [Q] to (Buying unit)
              • Set Integer_P99 = (Integer_P99 + 1)
              • Set Spell_P99[Integer_P99] = Meat Hook [Q]
            • Else - Actions
        • Else - Actions
          • Game - Display to Buying_Unit[(Player number of (Owner of (Buying unit)))] the text: You have already bo...
          • Player - Add 195 to (Owner of (Buying unit)) Current gold
Where,
Integer_P1/2/3/4/5/6/7/8/9/99 = The same as index
Spell_P1/2/3/4/5/6/7/8/9/99 = The Ability

And I've done it the same way for all the spells, but its too long and time taking.
 
Level 25
Joined
Sep 26, 2009
Messages
2,384
yes there is an easier and quicker option - the one I posted in my previous post. Also your system won't work well - it will only work for adding 4 abilities, but it won't work the way you wrote - that if you bought 5th, 6th and 7th ability, then the first/second/third ability gets replaced.


Also, there's no real reason to use "wait" action. If anything it will mess things up (if 2 units buy items in the 0,09 period, only one of them can be Buying Unit I think)
More so, waits are inaccurate (their minimum time is a random time between 0,1 and 0,27 seconds) and they're inaccurate even more in multiplayer maps where the wait time is prolonged by latency
 
Level 11
Joined
Dec 19, 2012
Messages
411
  • Actions
    • Set Trigger_Player = (Owner of (Buying Unit))
    • Set num = (Player number of Trigger_Player)
    • For each (Integer Loop_Integer) from 1 to 10, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Level of Meat Hook for (Buying Unit)) Equal to 0
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Trigger_Player Equal to (Player(Loop_Integer))
              • Then - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • Integer[num] Equal to Check_Integer[num]
                  • Then - Actions
                    • Set Check_Integer[num] = (1 + Integer[num])
                    • Unit - Remove Ability[((num x 4) + Integer[num])] from (Buying Unit)
                  • Else - Actions
                • Set Ability[((num x 4) + Integer[num])] = Meat Hook
                • Unit - Add Ability[((num x 4) + Integer[num])] to (Buying Unit)
                • Set Integer[num] = (Integer[num] + 1)
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • Integer[num] Equal to 4
                  • Then - Actions
                    • Set Integer[num] = 0
                  • Else - Actions
              • Else - Actions
          • Else - Actions
            • Game - Display to (Player group(Trigger_Player)) the text: You have alraedy br...
            • Player - Add 175 to Trigger_Player Current gold
Variables explain :
1. Ability(array) = Used for stored player's (all players) abilities.

2. Check Integer = Used for check whether the player have total 7 number abilities ( assume the player has default 4 abilities )

3. Integer(array) = Used for check whether the player have brought total 3 number of abilities.

4. Loop_Integer = Used for looping integer.

5. num = Used for store player number.

6. Trigger Player = Used for store (Owner of (Buying Unit)) to prevent repeatedly calls.


Check Integer should be define at map init before use (number is 4)

I didn't try this trigger work or not...
 
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,384
The integer loop is completely unnecessary there. You access the player directly through the "num" integer, as it represents that player slot's number, thus the "layer" of every array of this system.
Because each player slot has different number, then it is impossible for two random player slots to have saved information in one same "layer" of array (thus replacing the last data that were there).

The system will bug even more, because it will return either 1750 gold (in case the unit which bought the item already has the ability) or 1575 (9x 175, because the first time the loop runs, that unit has level of ability = 0; but the remaining 9 times the level is no longer equal to 0)

I'm not sure what DJAB wants though. It would be nice if he explained.
Either a) You have a list of 7 abilities and you can have active only 4 of those, but you can learn the remaining 3 which are not active, but at the cost that of the 3 active abilities get replaced - and you can do this repeatedly.

or b) Works same as a), but you cannot do this repeatedly - if you learn the 7th ability (the 3rd inactive ability), you can no longer access the replaced abilities.


Anyway, I assumed it's the option a), thus I will show the trigger for that:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to Meat Hook
    • Actions
      • Set unit = (Buying unit)
      • Set PlayerNum = (Player number of (Owner of unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Meat Hook for unit) Equal to 0
        • Then - Actions
          • Unit - Remove Ability[((PlayerNum x 4) + Index[PlayerNum])] from unit
          • Unit - Add Meat Hook to unit
          • Set Ability[((PlayerNum x 4) + Index[PlayerNum])] = Meat Hook
          • Set Index[PlayerNum] = (Index[PlayerNum] + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Index[PlayerNum] Greater than 3
            • Then - Actions
              • Set Index[PlayerNum] = 0
            • Else - Actions
        • Else - Actions
          • Player - Add 350 to (Owner of unit) Current gold //this is the buying price of the item
      • Item - Remove (Sold Item)
Anyway, to make a whole system, it would be best to save all items and abilities to them related inside arrays for easier check.
If this is what you want, I could provide a test map with it.
 
Level 11
Joined
Dec 19, 2012
Messages
411
The integer loop is completely unnecessary there. You access the player directly through the "num" integer, as it represents that player slot's number, thus the "layer" of every array of this system.
Because each player slot has different number, then it is impossible for two random player slots to have saved information in one same "layer" of array (thus replacing the last data that were there).

The system will bug even more, because it will return either 1750 gold (in case the unit which bought the item already has the ability) or 1575 (9x 175, because the first time the loop runs, that unit has level of ability = 0; but the remaining 9 times the level is no longer equal to 0)

I'm not sure what DJAB wants though. It would be nice if he explained.
Either a) You have a list of 7 abilities and you can have active only 4 of those, but you can learn the remaining 3 which are not active, but at the cost that of the 3 active abilities get replaced - and you can do this repeatedly.

or b) Works same as a), but you cannot do this repeatedly - if you learn the 7th ability (the 3rd inactive ability), you can no longer access the replaced abilities.


Anyway, I assumed it's the option a), thus I will show the trigger for that:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Item-type of (Sold Item)) Equal to Meat Hook
    • Actions
      • Set unit = (Buying unit)
      • Set PlayerNum = (Player number of (Owner of unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Meat Hook for unit) Equal to 0
        • Then - Actions
          • Unit - Remove Ability[((PlayerNum x 4) + Index[PlayerNum])] from unit
          • Unit - Add Meat Hook to unit
          • Set Ability[((PlayerNum x 4) + Index[PlayerNum])] = Meat Hook
          • Set Index[PlayerNum] = (Index[PlayerNum] + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Index[PlayerNum] Greater than 3
            • Then - Actions
              • Set Index[PlayerNum] = 0
            • Else - Actions
        • Else - Actions
          • Player - Add 350 to (Owner of unit) Current gold //this is the buying price of the item
      • Item - Remove (Sold Item)
Anyway, to make a whole system, it would be best to save all items and abilities to them related inside arrays for easier check.
If this is what you want, I could provide a test map with it.

OMG! I made a damn stupid mistake, thanks for pointing that out. I made that mistake because originally i planed to make a loop function ( as u mentioned, store the abilities and items inside array). and later i changed my mind so i made this mistake :D

Also, i forgot i stored the player number and so i added a unnecessary condition.

A question : remove the ability before the ability exist would not cause any problem?
 
Level 25
Joined
Sep 26, 2009
Messages
2,384
No, it won't cause problem. But I think there was a custom script or something that worked like an ITE -> if the hero had the ability, it got removed, or something like that.

Since I was already in the mood, I made system with a test unit in it.
There are instructions with how to import it and also what to be wary off.

Triggers used:


Item Ability List - This trigger contains all items that grant the ability and all abilities that are to be learned by bought items.
  • Item Ability List
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- SET THE MAXIMUM INDEX --------
      • -------- the value in MaxIndex MUST be equal to the last indexed IA_Item --------
      • -------- -> e.g. currently last indexed IA_Item has index 7, so MaxIndex has value 7 --------
      • Set IA_MaxIndex = 7
      • -------- ------------------------------------------------------------------------------------------------------------ --------
      • -------- ------------------------------------------------------------------------------------------------------------ --------
      • -------- LIST OF ITEMS --------
      • Set IA_Item[1] = Anti-Magic Shell
      • Set IA_Item[2] = Berserk
      • Set IA_Item[3] = Dispel Magic
      • Set IA_Item[4] = Polymorph
      • Set IA_Item[5] = Rejuvenation
      • Set IA_Item[6] = Slow
      • Set IA_Item[7] = War Stomp
      • -------- ------------------------------------------------------------------------------------------------------------ --------
      • -------- ------------------------------------------------------------------------------------------------------------ --------
      • -------- LIST OF ABILITIES --------
      • -------- (Note: each ability that is corresponding to an item have same index number as the item) --------
      • Set IA_Ability[1] = Anti-magic Shell (Neutral Hostile)
      • Set IA_Ability[2] = Berserk
      • Set IA_Ability[3] = Dispel Magic (Neutral Hostile)
      • Set IA_Ability[4] = Polymorph (Neutral Hostile)
      • Set IA_Ability[5] = Rejuvenation (Neutral Hostile)
      • Set IA_Ability[6] = Slow
      • Set IA_Ability[7] = War Stomp (Neutral Hostile 1)
Ability Gain - This is the actual trigger that (re)places abilities. It checks first if the selling unit is the unit which sells these items (to prevent unnecessary stress) and then loops to find out which item was bought.
  • Ability Gain
    • Events
      • Unit - A unit Sells an item (from shop)
    • Conditions
      • (Selling unit) Equal to Trainer 0000 <gen>
    • Actions
      • -------- The condition ABOVE checks who the SELLING UNIT is --------
      • -------- ------------------------------------------------------------------------------------ --------
      • -------- ------------------------------------------------------------------------------------ --------
      • Set item = (Sold Item)
      • Set unit = (Buying unit)
      • Set PlayerNum = (Player number of (Owner of unit))
      • For each (Integer loop_int) from 1 to IA_MaxIndex, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of item) Equal to IA_Item[loop_int]
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of IA_Ability[loop_int] for unit) Equal to 0
                • Then - Actions
                  • Unit - Remove Ability[((PlayerNum x 4) + Index[PlayerNum])] from unit
                  • Unit - Add IA_Ability[loop_int] to unit
                  • Set Ability[((PlayerNum x 4) + Index[PlayerNum])] = IA_Ability[loop_int]
                  • Set Index[PlayerNum] = (Index[PlayerNum] + 1)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Index[PlayerNum] Greater than 3
                    • Then - Actions
                      • Set Index[PlayerNum] = 0
                    • Else - Actions
                • Else - Actions
                  • Player - Add 250 to (Owner of unit) Current gold
                  • Game - Display to (Player group((Owner of unit))) the text: (You already have the + ((Name of item) + ability!))
            • Else - Actions
      • Item - Remove item

Once again, I advise you read through the instructions and all the info I wrote there and try to make sense of it.
 

Attachments

  • ItemRecipeAbility.w3x
    22 KB · Views: 27
Level 5
Joined
May 12, 2013
Messages
70
yes there is an easier and quicker option - the one I posted in my previous post. Also your system won't work well - it will only work for adding 4 abilities, but it won't work the way you wrote - that if you bought 5th, 6th and 7th ability, then the first/second/third ability gets replaced.


Also, there's no real reason to use "wait" action. If anything it will mess things up (if 2 units buy items in the 0,09 period, only one of them can be Buying Unit I think)
More so, waits are inaccurate (their minimum time is a random time between 0,1 and 0,27 seconds) and they're inaccurate even more in multiplayer maps where the wait time is prolonged by latency

When I added the Wait Condition, There was a need for it. 2 Triggers had the Same conditions and Event. I needed to put a wait here to let that Trigger run First. But now I've made some changes and removed the Wait.
As for the Spells, I already told you, 3 spells are added to the Hero by Default at Map Init. He can buy 4 more at the Shop, So I am replacing only the Spells he bought from the Shop. So the Index is 4, because there's only the four abilities he bought from the shop, out of which the First one will get Replaced by the 5th one.
 
Status
Not open for further replies.
Top