| 06-11-2005, 12:33 AM | #1 |
I was wondering how i could make something similar to Dota stlye of choosing a random unit. What it basically is, if you dont know, is that a player types "-random" and then a random hero gets selected. thanks |
| 06-11-2005, 01:08 AM | #2 |
Basically, Create a unit array Put your heroes into the unit array during a trigger running at or near map initialization When the pick trigger runs, have it generate a random number between 1 and whatever as the subscript to pick the random hero. Then there are a couple ways of handling how to avoid copies, if needed. You could have a boolean array that keeps track of what heroes are used and which ones aren't, or replace the hero already in the array with a special placeholder unit. Either way, that lets it know it's picked that before - then the trigger can just repeat itself. It helps to have variables assigned for the random number and for the player. That should work, but I've actually done it. |
| 06-11-2005, 03:53 PM | #3 |
how can i check if someone already has a hero? |
| 06-12-2005, 05:19 PM | #4 |
You mean that a player has already picked a hero for themselves? Could just add another boolean array for that, that triggers when a player either selects a hero or gets one randomly. |
| 06-12-2005, 05:54 PM | #5 |
A way of doing that is Code:
Make an integer variable no array i named my random_hero Event - Player 1 (Red) types -random as an exact match Conditions - Actions - Set Random_Hero (Random number between 1 and # of heros) If Random_Hero equal to 1 then create 1 paladin for triggering player else do nothing |
| 06-18-2005, 06:09 PM | #6 |
i made this trigger to create a random hero, but if the hero is already on the map it picks another one and creates it. the problem with my trigger is that well umm it freezes. if anyone knows how to fix this lemme know, thanks. Random Hero 1 Events Player - Player 1 (Red) types a chat message containing -random as An exact match Conditions Actions Set randomint = (Random integer number between 1 and 12) Unit - Create 1 RandomHero[randomint] for Player 1 (Red) at (Center of Team 1 Hero <gen>) facing Default building facing degrees If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions Or - Any (Conditions) are true Conditions ((Last created unit) belongs to an ally of (Owner of (Last created unit))) Equal to True ((Last restored unit) belongs to an enemy of (Owner of (Last created unit))) Equal to True Then - Actions Unit - Remove (Last created unit) from the game Set randomint = (Random integer number between 1 and 12) Unit - Create 1 RandomHero[randomint] for Player 1 (Red) at (Center of Team 1 Hero <gen>) facing Default building facing degrees If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions Or - Any (Conditions) are true Conditions ((Last created unit) belongs to an ally of (Owner of (Last created unit))) Equal to True ((Last restored unit) belongs to an enemy of (Owner of (Last created unit))) Equal to True Then - Actions Unit - Remove (Last created unit) from the game Trigger - Run (This trigger) (checking conditions) Else - Actions Do nothing Else - Actions Do nothing |
| 06-18-2005, 06:30 PM | #7 |
Yes, random Integers are the way to go, also, nice sig Luckyownz92. |
| 06-18-2005, 06:33 PM | #8 | |
Quote:
That is most likely causing the problem. I too would suggest you use a boolean rather than the system you used. |
| 06-18-2005, 06:38 PM | #9 |
That is just so wrong I don't know where to even begin correcting you. Ok, tell you what, just delete your trigger and do it like this: Code:
HeroChoosingInit
Events:
Map Initialization
Conditions:
Actions:
Set numberOfHeroTypes = 12
Set heroType[1] = your first hero
Set heroType[2] = your second hero
...Code:
HeroChoosingRemoveFromList
Events:
Unit enters playable map area
Conditions:
((entering unit) is a hero) equal to true
Actions:
For each Integer A from 1 to numberOfHeroTypes do actions
loop - actions:
If - then - else multiple functions
If - conditions:
(Unit type of (entering unit)) equal to heroType[(Integer A)]
Then - actions:
For each Integer B from (Integer A) to numberOfHeroTypes do actions
loop - actions:
set heroType[(Integer B)] = heroType[((IntegerB) + 1)]
set numberOfHeroTypes = numberOfHeroTypes - 1
Skip remaining actions
Else - actions:Code:
HeroChoosingRandom
Events:
Player - Player 1 (Red) types a chat message containing -random as An exact match
Player - Player 2 (Blue) types a chat message containing -random as An exact match
...
Conditions:
Actions:
Set tempUnitGroup = units owned by (triggering player) matching (((matching unit) is a hero) equal to true)
If - then - else multiple functions
If - conditions:
Number of units in tempUnitGroup equal to 0
Then - actions:
Set randomint = (Random integer number between 1 and numberOfHeroTypes)
Unit - Create 1 RandomHero[randomint] for (triggering player) at (Center of Team 1 Hero <gen>) facing Default building facing degrees
Else - actions:
Custom script: call DestroyGroup( udg_tempUnitGroup ) |
| 06-21-2005, 01:29 AM | #10 |
i cant seem to get it to work... i did exactly what you said. hey for the last trigger i you meant to not put all 12 events, but to make 12 triggers with the event for the player. so umm yeah when i put -random it doesnt even work. |
| 06-21-2005, 06:00 AM | #11 |
Posting your triggers would help... By the way, there is an error in my triggers, I named the variable that holds the hero types differently in two triggers (heroType[] and RandomHero[]) when it's actually meant to be the same variable. Perhaps that is the problem? |
| 06-21-2005, 07:14 AM | #12 |
Just curious Anitarf, this is used to prevent memory leaks right? Code:
Custom script: call DestroyGroup( udg_tempUnitGroup ) |
| 06-21-2005, 11:08 PM | #13 |
Code:
The Random Heroes
Events
Map initialization
Conditions
Actions
Set NumberOfRandomHeroes = 12
Set RandomHero[1] = ...
Set RandomHero[2] = ...
Set RandomHero[3] = ...
Set RandomHero[4] = ...
Set RandomHero[5] = ...
Set RandomHero[6] = ...
Set RandomHero[7] = ...
Set RandomHero[8] = ...
Set RandomHero[9] = ...
Set RandomHero[10] = ...
Set RandomHero[11] = ...
Set RandomHero[12] = ...Code:
Random Hero Checker
Events
Unit - A unit enters (Playable map area)
Conditions
((Entering unit) is A Hero) Equal to True
Actions
For each (Integer A) from 1 to NumberOfRandomHeroes, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Unit-type of (Entering unit)) Equal to RandomHero[(Integer A)]
Then - Actions
For each (Integer B) from (Integer A) to NumberOfRandomHeroes, do (Actions)
Loop - Actions
Set RandomHero[(Integer B)] = RandomHero[((Integer B) + 1)]
Set NumberOfRandomHeroes = (NumberOfRandomHeroes - 1)
Skip remaining actions
Else - ActionsCode:
Choosing Random Hero 1
Events
Player - Player 1 (Red) types a chat message containing -random as An exact match
Conditions
Actions
Set tempUnitGroup = (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in tempUnitGroup) Equal to 0
Then - Actions
Set randomint = (Random integer number between 1 and NumberOfRandomHeroes)
Unit - Create 1 RandomHero[randomint] for (Triggering player) at (Center of Buying Hero <gen>) facing Default building facing degrees
Else - Actions
Custom script: call DestroyGroup( udg_tempUnitGroup )i just put in the one for p1. ummm the "..." is just replaced with the hero type of the hero. |
| 06-22-2005, 10:34 PM | #14 |
You don't have to make a seperate trigger for every player, all players who's heroes spawn in the same region can have their events in the same trigger. I can't see any reason for it not to work other than that the player already has a hero... The trigger has a condition that makes the trigger only work if the player doesn't have a hero yet. Oh, and the custom script (which is there to prevent leaks) should be at the end of the trigger, not under Else actions, otherwise it doesn't clear the leak when you choose the hero (well, if a player can only do that once, it is insignificant, but it's always good to be consistent) |
| 06-26-2005, 03:25 AM | #15 |
ok i fixed the trigger so it works. the problem was that the variable tempGroup was unessacary. so i replaced it with someone simple as lumber, so you buy your hero. so instead of checking the tempgroup it just checks the lumber |
