• 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!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Get Random skill by item

Status
Not open for further replies.
Level 4
Joined
Jan 30, 2012
Messages
61
Hello,

I have a problem:

I did a map with soldiers, snipers, helicopters etc. and there is a item which gives the unit a random skill (spying drone, rocket, helicopter etc.)
But how to do that if he buys the item and he get the skill spying drone, the next time he buy the item, he will give a other random skill?
Because if he has spying drone and he buys the item again and the random system has chosen the spying drone, he gets no skill :/

Sorry for my bad english, i hope you know what i mean ^_^
Also i hope for a fast answer :)
 
You can use a stack structure :D

The same thing is done when you have an AoS and you only want some "Random Hero" feature to give different heroes for each player :)

First, you need to store the abilities in an array:

  • Set Ability[1] = ...
  • Set Ability[2] = ...
  • Set Ability[3] = ...
  • Set Ability[4] = ...
  • Set Ability[5] = ...
You should also store the number of elements in the array.
In this case, we have 5:

  • Set Count = 5
Now, whenever we want to get something random from the array, we do the following procedure:

  • Set TempInt = (Random number between 1 and Count)]
  • Set TempAbility = Ability[TempInt]
  • // Give the unit the ability here
  • Set Ability[TempInt] = Ability[Count]
  • Set Count = Count - 1
This works perfectly ^.^

Here's an explanation:

Assume we have:
A - B - C - D - E

Now, first, we select a random item in the list.
Assume we got 2.
B is the value that we're going to take.

So, we remove B:

A - _ - C - D - E

But, we can't leave an empty space, so, we can make the last item in the list take the place of B:

A - E - C - D - E

Now, we decrease the Count integer by 1 to remove the duplicate of E:

A - E - C - D

And viola ^.^
 
Level 4
Joined
Jan 30, 2012
Messages
61
Thanks for your answer but i dont exactly know how to do, can you do maybe the trigger and post it here? this would be cool, so i can see it ^^ i learn more by seeing ^^
If you do the trigger use
Ability [1] = UAV
Ability [2] = Mine
Ability [3] = Helicopter
Ability [4] = Rocket

I would be thankful if you do it :)

I dont know what the Variables types are ^^
Sorry for my stupidity xD

And it shall work for more players ^^
 
Status
Not open for further replies.
Top