choose a random race for ai?

sunshinex3

You can change this now in User CP.
Reaction score
7
people want ai on my map.

problem is i dont know where to start. When my map starts a dialog screen pops up and human players pick a race and then they start playing. how do i get a race to spawn with ai? and i would like a randomness factor. so the game would never be the same.

i need:
a way for ai to pick a race randomly and start playing


info: their are nine races all have custom units, the map doesn't use food. '
when the game starts after 3 sec dialog buttons come up and allow players to choose a race. after the click on a race the dialog disappears.
 

death_knight

Dark is the heart of a corrupted man.
Reaction score
24
Well it could be as simple as assigning each race a number between 1 and 9 inclusive and then for each computer player, generate a random number between 1 and 9 inclusive and based on that number, select the race for that computer player.
 

sunshinex3

You can change this now in User CP.
Reaction score
7
ok sound good to me but...

how do you assign a race to a number? variables? array? maybe i don't know.
how do i generate a random number between 1 and 9?
and then i guess attach the number to the comp player and um. give it units and start its ai?
 

death_knight

Dark is the heart of a corrupted man.
Reaction score
24
Assigning each race a number is purely arbitrary and only used in triggers. The way you could start the trigger to set the race of computer players along the following lines:

Trigger:
  • Race Selecter
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set raceInt[(Integer A)] = (Random integer number between 1 and 9)


Then you could use that randomly generated number to select the race for each player. Note: "raceInt" is an array variable of type "Integer".

I can't really offer you any more one how t o select the race for a computer player because I have no idea how you've implemented your custom races.
 

O.A

Quantum physics rules
Reaction score
29
You could also put the workers from each race to a unit-type array, and use the random (1-9) method death knight showed, to pick units from there.
The worker would then define the race of that player.
Trigger:
  • workers
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Player_Count = (Number of players in (All players matching ((((Matching player) controller) Equal to User) and (((Matching player) slot status) Equal to Is playing))))
      • Set Array_UnitType_Workers[1] = Wisp
      • Set Array_UnitType_Workers[2] = Acolyte
      • Set Array_UnitType_Workers[3] = Peasant
      • Set Array_UnitType_Workers[4] = And so on
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Player_Count Less than 12
        • Then - Actions
          • For each (Integer A) from (Player_Count + 1) to 12, do (Actions)
            • Loop - Actions
              • Unit - Create 1 Array_UnitType_Workers[(Random integer number between 1 and 9)] for (Player((Integer A))) at ((Player((Integer A))) start location) facing Default building facing degrees
        • Else - Actions


I don't know anything about melee games, so i have no idea how to make the AI do anything, but this is a method to create a random worker for as many computer AIs as there are free slots.

Updated
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
The starting location only works if you actually placed the starting location on the map. But it works for all players if placed.

Just on a sidenote; you are leaking a point and a player group in your trigger. But I guess you are aware of that.
 

O.A

Quantum physics rules
Reaction score
29
I had all the starting locations in the map. The problem was though, you have to set all the players from Player Properties as either user or computer for the editor to use those locations, and you have to check the fixed starting locations box (at least player 2's units kept appearing randomly at 3's or 4's starting location, and this fixed it). I'll update the trigger.

As for the leaks, i did not actually know it leaked a player group. I thought i'd mention the point leak if OP does not go AWOL, and decides to use something like this, but for now i thought this trigger only runs once, so i won't remove the points. (i almost did though, just to keep you happy, i knew you'd mention it :) )
 

sunshinex3

You can change this now in User CP.
Reaction score
7
thax guys, I'm going to try this. let me give you the triggers i have for human players to choose race.

//this is the dialog trigger that brings of the dialog buttons for the races

dialog choose race
Events
Time - Elapsed game time is 3.00 seconds
Conditions
Actions
Dialog - Clear mydialog
Dialog - Change the title of mydialog to Choose a Race
Dialog - Create a dialog button for mydialog labelled Legion
Set button1legion = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Naga
Set button2naga = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Night Elf
Set button3NightElf = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Nerubian
Set button4Nerubian = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Corrupted
Set button5satyr = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Tribunal
Set button6tribunal = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Orc
Set button7orc = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Scourge
Set button8scouge = (Last created dialog Button)
Dialog - Create a dialog button for mydialog labelled Human
Set button9human = (Last created dialog Button)
Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
Loop - Actions
Dialog - Show mydialog for (Picked player)

//this is the trigger for the first button "legion"

button1 legion
Events
Dialog - A dialog button is clicked for mydialog
Conditions
(Clicked dialog button) Equal to button1legion
Actions
Unit - Create 1 Demonic Gate for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
Unit - Create 5 Fel Orc Peon for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
Player - Set (Triggering player) Current gold to 500
Game - Display to (All players) for 30.00 seconds the text: (Name of (Triggering player))
Game - Display to (All players) for 30.00 seconds the text: HAS CHOSEN LEGION!!

//their are 8 other buttons I could post if it would help better explain.(this is just the //first one)
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Trigger:
  • Initialization
    • Events
      • Map initialization
    • Conditions
      • Actions
        • Set Building[1] = Town Hall
        • Set Building[2] = Great Hall
        • Set Building[3] = Tree of Life
        • Set Building[4] = Necropolis
        • -------- Building is a unit-type array --------
        • Set Worker[1] = Peasant
        • Set Worker[2] = Peon
        • Set Worker[3] = Wisp
        • Set Worker[4] = Acolyte
        • -------- Worker is a unit-type array --------
        • Set RaceName[1] = Human
        • Set RaceName[2] = Orc
        • Set RaceName[3] = Night Elf
        • Set RaceName[4] = Undead
        • -------- RaceName is a string array --------
        • Wait 3.00 seconds
        • -------- - --------
        • Set TempPlayerGroup = (All players controlled by a Computer player)
        • Player Group - Pick every player in TempPlayerGroup and do (Actions)
          • Loop - Actions
            • Set TempPoint = (Picked player) start location
            • Set TempInt = (Random integer between 1 and 9)
            • Unit - Create 1 Building[TempInt] for (Picked player) at TempPoint facing Default building facing degrees
            • Unit - Create 5 Worker[TempInt] for (Picked player) at TempPoint facing Default building facing degrees
            • Custom script: call RemoveLocation (udg_TempPoint)
        • Custom script: call DestroyForce (udg_TempPlayerGroup)
        • Game - Display to (All players) the text: ((Name of (Picked player)) + ( has chosen + RaceName[TempInt]))

Something like this, maybe? How you "start your AI" is up to you, though, since gameplay isn't involved yet.
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Doubtful, since you can't assign different values to each array index. They'll all end up being the same unit.
 

sunshinex3

You can change this now in User CP.
Reaction score
7
Set TempPlayerGroup = (All players controlled by a Computer player) what varibal is this? player? or player group?

also should i set the initial values to the unit i want when I'm making the building and worker variables?
 

sunshinex3

You can change this now in User CP.
Reaction score
7
it wont let me edit my post for some reason, it must be player group im going to assume this i just know the size? 12?
Set AiPlayersGroup[12] = (All players controlled by a Computer player)

again. thank you for your help.
 

sunshinex3

You can change this now in User CP.
Reaction score
7
this is what i have so far.

AI
Events
Map initialization
Conditions
Actions
-------- Main Halls --------
Set AiBuilding2[1] = Town Hall
Set AiBuilding2[2] = Great Hall
Set AiBuilding2[3] = Necropolis
Set AiBuilding2[4] = Tree of Life
Set AiBuilding2[5] = Temple of Tides
Set AiBuilding2[6] = Demonic Gate
Set AiBuilding2[7] = Troll Hut
Set AiBuilding2[8] = Forgotten One
Set AiBuilding2[9] = Corrupted Tree of Life
-------- Workers --------
Set AiWorker[1] = Peasant
Set AiWorker[2] = Peon
Set AiWorker[3] = Acolyte
Set AiWorker[4] = Wisp
Set AiWorker[5] = Mur'gul Slave
Set AiWorker[6] = Fel Orc Peon
Set AiWorker[7] = Runt
Set AiWorker[8] = Scarab
Set AiWorker[9] = Wisp (corrupted)
Wait 3.00 seconds
Set AiPlayersGroup[12] = (All players controlled by a Computer player)
Player Group - Pick every player in AiPlayersGroup[12] and do (Actions)
Loop - Actions
Set AiTempPoint = ((Picked player) start location)
Set AiTempRandomNumber[9] = (Random integer number between 1 and 9)
Unit - Create 1 Town Hall for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
 

O.A

Quantum physics rules
Reaction score
29
You don't need to set up a size for a player group, there you have set up a player group array, which is unnecessary for this trigger. Set it to be a normal player group variable. The AiTempPoint is set up so it can be later removed to avoid a leak, so you have to use it when creating the units (create unit at AiTempPoint), see how Kaerfnomekop does it using the Custom Script. And finally, your AiTempRandomNumber is also an array, which it need not be, for it is rewritten on every loop. What needs to be an array, is the unit type array you set up in the trigger (Town Hall[AiTempRandomNumber]).

Using the Custom Scripts is entirely optional, if they cause trouble. They remove leaks, but since this trigger runs once, it doesn't really matter, however it is good to learn how to remove leaks early on.
 

afisakov

You can change this now in User CP.
Reaction score
37
you should replace
Trigger:
  • Unit - Create 1 <b>Town Hall</b> for (<b>Triggering</b> player) at ((Triggering player) start location) facing Default building facing degrees

with
Trigger:
  • Unit - Create 1 <b>AiBuilding2[AiTempRandomNumber]</b> for (<b>Picked</b> Player) at (AiTempPoint) facing Default building facing degrees
    • custon script: call RemoveLocation(udg_AiTempPoint)

and as mentioned above, AiTempRandomNumber does not need to be an array
 

sunshinex3

You can change this now in User CP.
Reaction score
7
well it works thax
KaerfNomekop!!

and others!!

now i had some other questions regarding ai behavior when i turn on the script for the ai. in order for them to use a custom races were would i put that action. would it be in kaerfNomekop trigger above or would i have to make a new trigger?

and the ai ally/enemy system what would be a good way to implement this?

i was thinking maybe through chat commands, -vs ai, would mean all ai will attack human players and select ally victory.

-ai race ally, would mean ai/human with the same race ally and un-ally those with different races

if you guys think this to be possible how would i do this?

and if you have a better idea how would i do that?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top