[Trigger] Trying to randomize heros on an otherwise normal melee map

Status
Not open for further replies.
Level 13
Joined
Mar 13, 2013
Messages
299
I apologize if this question has been asked/answered already. I looked through this thread and got what I could from it, but couldn't find anything more specific to what I need - however I've never used scripts before so it was a significant help!

Anyway, I'm trying to randomize the hero training process for an otherwise normal melee map. I would suspect this should be simple for most people here, but I'm having a problem: basically, I can not train a new hero at tier 2. It works 'fine' at tier 1 and tier 3, but for some reason it will not allow me to train a new hero at tier 2.

I've posted my entire code at the bottom as a screenshot, but the 'meat' of it is this line:

  • Unit - Replace (Trained unit) with a PHeros[(((y-1)x3) + x)] using The new unit's max life and mana.
I've also tried:
  • Unit - Remove (Trained unit) from the game
  • Unit - Create 1 Pheros[(((y - 1)x3) + x)] for Pnum at (Position of (Triggering unit)) facing Default building facing degrees
which also doesn't work..

When I do this it behaves as though the "replace" just hid the trained hero and added a random hero, but still assumes I have two heroes. So when I reach tier 2 I can't train a new one. Is there some way to reset the number of heroes I have back to the number I actually have? Or, is it 'obvious' to anyone here that something else is the problem? How do I fix it?


additional "optional" information:
Brief explanation of variables:
Pheros is a 'hero array' i set at map initialization. It has 36 elements - (max of 12 players and a max of 3 heroes for each player 3x12 = 36). So, elements 1, 2, and 3 would represent the first, second, and third hero for player 1. elements 4, 5, and 6 would represent the first, second, and third hero for player 2, and so on.. The heroes are assigned randomly in the array, with of course some simple checking to ensure no one gets the same hero twice and no one gets a non-neutral hero of another race. Note: this is all 'set in stone' at the onset of a given game, but that doesn't mean that there must be 12 players nor does it mean that any player must have 3 heroes.

y is the player number given by:
  • Set y = (Player number of Pnum)
x is the hero number generated by:
  • Set x = 0
  • set grp = (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))
  • Set y = (Player number of Pnum)
  • Unit Group - Pick every unit in grp and do (Actions)
  • Loop - Actions
  • Set x = (x+1)
Pnum is given by:
  • Set pnum = (Triggering player)
Edit: also, this is only aesthetic but if anyone has the time to teach a noob: when the hero is trained it plays the sound of the intended hero rather than the 'replacement' hero. I can not find any obvious way of changing that - but if no one knows how or has the time to explain it's not really a big deal.

Second edit: i just pasted all my code as a screenshot:
random hero
initialization
variables

and yes, in advance, i know there are probably much more efficient ways of doing what I have done thus far, but please understand that that's not why I am here - unless of course it results in the specified problem, then by all means explain.
 
Last edited:
Index your random units into an array and do:

E --> a unit enters palyable map area
C --> unit type of triggering unit equals to randomize
A --> replace triggering unit with RandomUnit[random number between A and B]

and for your "ptional" info: I once had the same problem by giving AI players a name without having two of the same.

Set Elements = 36
Set RHerotype[1] to ...
Set RHerotype[2] to ...
...
Set RHerotype[36] to ...
(for each player)
set Temp_Int = random number between 1 and Elements
create RHerotype[Temp_Int] at ...
set RHerotype[Temp_Int] = RHerotype[Elements]
set Elements = Elements - 1

I hope this helps ^^

Edit: o_O sorry I didn't read to the end before replying. Oh well... :am: lol
 
Status
Not open for further replies.
Top