• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to make Computer select unit from Tavern ?

Status
Not open for further replies.
Level 5
Joined
May 12, 2013
Messages
70
Ok, so I want the Computer to select a hero from the Tavern when the game starts, if the player is controlled by a computer. Like if the player is a computer, it should select or choose a hero from the tavern at map initialization. Also, how to make the hero choose his spells as he levels up and how to make him use his those spells at the right moment.
 
Level 5
Joined
May 12, 2013
Messages
70
@Spartipilo : The AI editor only works in melee maps, that's what i heard. And my map is'nt a melee map. I'm asking about the triggers !

@Apoclypse : This is really confusing, and i don't get it. Is there any other easier way to select a random hero ?
 
Level 30
Joined
Nov 29, 2012
Messages
6,637
Try this:

  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
      • (Player 1 (Red) controller) Equal to Computer
    • Actions
      • Set Heroes[1] = Paladin
      • Set Heroes[2] = Archmage
      • Set Heroes[3] = Mountain King
      • Set Heroes[4] = Blood Mage
      • Unit - Create 1 Heroes[(Random integer number between 1 and 4)] for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
We all know you can just make a player choose a random hero and that will act like that the computer AI player chose a random hero from a tavern.

At map init, it will scan if the owner of plyer 1 is a computer. If it is a computer. We will set each hero in your tavern into a variable and create a random hero random numbers from what you set so it will give a random hero to the player.

Hope this helps.... do this for every player.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
@Hell_Master: that's the exact same thing, but with leaks :p.

@Apoclypse : This is really confusing, and i don't get it. Is there any other easier way to select a random hero ?
(ap0calypse*)
How exactly confusing?
There's no easier way if you want to do it properly (this is already a really easy trigger).

The amount of heroes that can be randomed:
  • Set HeroTypeCount = 3
The heroes that can be randomed:
  • Set HeroType[1] = Hero A
  • Set HeroType[2] = Hero B
  • Set HeroType[3] = Hero C
This will decide which hero will get randomed:
  • Set RandInt = (Random integer number between 1 and HeroTypeCount)
It will create a random integer from 1 to the amount of heroes, meaning that every hero has an equal chance to get picked.

Now we can actually create the hero:
  • Unit - Create 1 HeroType[RandInt] for (Picked player) at TempLoc1 facing Default building facing degrees
Remember: RandInt is an integer between 1 and the amount of heroes.
If it is, say, 2, then HeroType[2] will get created - which equals Hero B (as seen above).

These functions make sure that a hero can only be picked once (if some AI randoms Hero A, then that hero cannot be picked again)
  • Set HeroType[RandInt] = HeroType[HeroTypeCount]
  • Set HeroTypeCount = (HeroTypeCount - 1)
You do not need to worry about this too much: it does what it's meant to do, and that's it :p.
If you do want to allow multiple players having the same hero, simply remove these actions.


And last but not least:
  • Set TempLoc1 = ((Picked player) start location)
  • Custom script: call RemoveLocation(udg_TempLoc1)
These actually came before, but I left them out on purpose.
They only fulfill a single role: remove the location leak. Leaks cause mid-to late-game lag and are to be avoided at all times.
 
Level 5
Joined
May 12, 2013
Messages
70
Thankyou all of you ! I got my mistake. I was selecting the Variable type to be Unit rather than Unit-type and thats why i didn't had an option to choose a hero ! =P

@ap0calypse : What if i do it like :

" Unit - Create 1 HeroType[RandInt] for (Picked player) at Player 1 start Location facing Default building facing degrees "

Will it still leak that way ? Like without the region ?

Also in :

" Set RandInt = (Random integer number between 1 and HeroTypeCount) "

Doesn't the word between means that only numbers BETWEEN 1 and HeroTypeCount excluding 1 and HeroTypeCount themselves, leaving only 2 in this case ?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
it shouldnt leak because player 1 start location is a point.
What do you mean "it shouldn't leak"? Of course it will leak! It's a location. It will leak if it doesn't get removed.

@DJAB: every location leaks. Whether you use regions, starting locations, unit positions, it doesn't matter.
Your brain should go: "Is it a location? Yes --> Leak".
  • ((Center of (Region)) offset by 200.00 towards 0.00 degrees)
^ That has 2 leaks, because there are 2 locations ("Center of Region" and "point with offset").


Doesn't the word between means that only numbers BETWEEN 1 and HeroTypeCount excluding 1 and HeroTypeCount themselves, leaving only 2 in this case ?
I never noticed this before, but it is indeed a confusing trigger description.
Random integer will choose a random integer from 1 to HeroTypeCount (1 and HeroTypeCount included).
 
Status
Not open for further replies.
Top