[General] Making a newly created unit have RNG stats based on two existing units? Weird question, detailed in post.

Level 5
Joined
Nov 17, 2022
Messages
84
I do not know how to title this so hopefully I can inquire better here what I mean.

So, I am doing a horse simulator-like game with survival elements and a breeding system. Currently, I have it foals are born with RNG stats based on nothing influencing it, so some baby horses are born better and some worse for no real reason at all. You can improve the stats of your horses however via collecting items or obviously leveling up your Stallion, however. So even a bad horse could become a good horse with some elbow grease.

I had a sudden thought strike me whilst looking over my triggers and wondered how to make breeding more elaborate and stuff: Would it at all be possible to make it so the stats [damage, defense, hp and mana amount] of the parents [Stallion unit and Mare unit] could influence the RNG of what stats the foal inherits when it spawns?

So for example taking an amount of damage stat from either the Stallion Unit, Mare Unit, or both?

If it's possible, would anyone here have an idea how I could go about setting a trigger like that up? 🤔 I feel like it'd be linked to custom value of unit but I am not sure how to take advantage of it or set something up..
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
how is the breeding system on your map currently set up?
Like this atm:
Breeding Horses
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Father Foals (Breed Foals)
(Mana of (Target unit of ability being cast)) Greater than or equal to 50.00
(Life of (Target unit of ability being cast)) Greater than or equal to 50.00
Or - Any (Conditions) are true
Conditions
(Unit-type of (Triggering unit)) Equal to Stallion [Black]
(Unit-type of (Target unit of ability being cast)) Equal to Mare [Chestnut]
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Random integer number between 1 and 10) Less than or equal to 5
Then - Actions
Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare is now pr...
Unit - Create 1 Unborn Horse for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
Unit Group - Add (Last created unit) to Unborn_Foals
Unit - Set the custom value of (Last created unit) to (Integer((Substring((String((Key (Last created unit).))), 4, 7))))
Set VariableSet Father[(Custom value of (Last created unit))] = (Triggering unit)
Set VariableSet Mother[(Custom value of (Last created unit))] = (Target unit of ability being cast)
Unit - Order (Target unit of ability being cast) to Load (Last created unit)
Hero - Add 50 experience to (Triggering unit), Show level-up graphics
Else - Actions
Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare did not b...


  • Foal Births
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Unborn_Foals and do (Actions)
        • Loop - Actions
          • Set VariableSet Unborn_Horse = (Picked unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Mana of Unborn_Horse) Equal to 400.00
            • Then - Actions
              • Animation - Play Mother[(Custom value of Unborn_Horse)]'s death animation
              • Animation - Queue Mother[(Custom value of Unborn_Horse)]'s stand animation
              • Unit Group - Remove Unborn_Horse from Unborn_Foals.
              • Unit - Remove classification of A sapper from Mother[(Custom value of Unborn_Horse)]
              • Unit - Set mana of Mother[(Custom value of Unborn_Horse)] to 0.00
              • Game - Display to (All players matching ((Owner of Mother[(Custom value of Unborn_Horse)]) Equal to (Matching player)).) the text: A mare in your herd...
              • Unit - Kill Unborn_Horse
              • Unit - Create 1 Foal [Chestnut] for (Owner of Unborn_Horse) at (Position of Unborn_Horse) facing Default building facing degrees
              • Unit - Set the custom value of (Last created unit) to (Integer((Substring((String((Key (Last created unit).))), 4, 7))))
              • Unit - Order (Last created unit) to Follow Mother[(Custom value of Unborn_Horse)]
              • Hero - Add 100 experience to Father[(Custom value of Unborn_Horse)], Show level-up graphics
              • Set VariableSet Skintest = (Last created unit)
              • Custom script: call BlzSetUnitSkin(udg_Skintest, udg_Foal_Types[GetRandomInt(1,6)])
              • Set VariableSet Foal_Age[(Custom value of (Last created unit))] = 0
              • Animation - Change (Last created unit)'s vertex coloring to ((Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%, (Random real number between 60.00 and 100.00)%) with 0.00% transparency
              • Unit - Add Foal_Spells[(Random integer number between 1 and 5)] to (Last created unit)
              • Unit - Set Max Mana of (Last created unit) to (Random integer number between 150 and 300)
              • Unit - Add Wander (Neutral) to (Last created unit)
              • Unit - Set Armor of (Last created unit) to 0.00
              • Unit - Set Unit: (Last created unit)'s Integer Field: Defense Type ('udty') to Value: 0
              • Unit - Set Base Damage of (Last created unit) to 0 for weapon index: 0
              • Unit - Set Base Damage of (Last created unit) to (Random integer number between 1 and 5) for weapon index: 0
              • Unit - Set Max HP of (Last created unit) to (Random integer number between 200 and 500)
              • Unit Group - Add (Last created unit) to Foal_Group
              • Unit Group - Add (Last created unit) to Foal_Money_Group
            • Else - Actions
 
Level 5
Joined
Nov 17, 2022
Messages
84
please add the trigger tag to the first one too
Sorry trying to fix it rn bc noticed it screwed up when I posted the trigger. My internet pooped out immediately after so gonna try fixing it on my phone currently 🙃

  • Breeding Horses
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Father Foals (Breed Foals)
      • (Mana of (Target unit of ability being cast)) Greater than or equal to 50.00
      • (Life of (Target unit of ability being cast)) Greater than or equal to 50.00
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Stallion [Black]
          • (Unit-type of (Target unit of ability being cast)) Equal to Mare [Chestnut]
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 10) Less than or equal to 5
        • Then - Actions
          • Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare is now pr...
          • Unit - Create 1 Unborn Horse for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
          • Unit Group - Add (Last created unit) to Unborn_Foals
          • Unit - Set the custom value of (Last created unit) to (Integer((Substring((String((Key (Last created unit).))), 4, 7))))
          • Set VariableSet Father[(Custom value of (Last created unit))] = (Triggering unit)
          • Set VariableSet Mother[(Custom value of (Last created unit))] = (Target unit of ability being cast)
          • Unit - Order (Target unit of ability being cast) to Load (Last created unit)
          • Hero - Add 50 experience to (Triggering unit), Show level-up graphics
        • Else - Actions
          • Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare did not b...
 
Level 25
Joined
Mar 29, 2020
Messages
1,466
you don't really need to add anything complicated with custom value here.

when you create the unborn foal - give it the stats you want it to have then, and when the foal is "born", just transfer those stats to the born unit. since everything here is instant (the father of foals ability instantly creates the unborn foal etc') you don't need other mechanics to keep tack of the data. just do whatever math you want during the first spell, and then just have those stats copy over to the next unit then the foal is born.

something like -
set max hp of unborn foal to (((max hp of casting unit) + (max hp of targeted unit of ability being cast)) / 2)

and then just transfer all the relevant stats over to the born unit

I hope this was detailed enough...
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Never SET the Custom Value of a unit yourself, you're using a Unit Indexer in your map which does this automatically for you. It works like this:
  • Events
    • A unit enters the map
  • Conditions
  • Actions
    • Set Variable Integer = (Integer + 1)
    • Unit - Set the custom value of (The new unit) to Integer
The result is that each Unit has it's own unique Custom Value. First unit = 1, Second unit = 2, Third unit = 3, etc.

Also, this is not doing anything:
  • Unit - Set the custom value of (Last created unit) to (Integer((Substring((String((Key (Last created unit).))), 4, 7))))
The Key of the unit? You aren't using a Hashtable variable so you should not be referencing any kind of Hasthable related data. Plus like I said above, don't EVER change a unit's custom value yourself when using a Unit Indexer.


Here's an example of using the parent's Max HP to influence the baby:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Random integer number between 1 and 10) Less than or equal to 5
      • Then - Actions
        • Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare is now pr...
        • Unit - Create 1 Unborn Horse for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
        • Unit Group - Add (Last created unit) to Unborn_Foals
        • -------- --------
        • -------- NEW --------
        • Set VariableSet Unborn_CV = (Custom value of (Last created unit))
        • Set VariableSet Father[Unborn_CV] = (Triggering unit)
        • Set VariableSet Mother[Unborn_CV] = (Target unit of ability being cast)
        • Set VariableSet Parents_Max_HP = (Max HP of Father[Unborn_CV] + Max HP of Mother[Unborn_CV])
        • Unit - Set Max HP of (Last created unit) to (Parents_Max_HP / 2)
        • -------- --------
        • -------- --------
        • Unit - Order (Target unit of ability being cast) to Load (Last created unit)
        • Hero - Add 50 experience to (Triggering unit), Show level-up graphics
      • Else - Actions
        • Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare did not b..
The Unborn Horse in this example is given half of the combined value of the Mother and Father's max hp. You could also store this value in an Array variable using the Unit Indexing method just like you're doing with Father[] and Mother[]. But that's unnecessary here since this PARTICULAR information is readily available without the need for a variable, which is what Cheshire was saying.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
Never SET the Custom Value of a unit yourself, you're using a Unit Indexer in your map which does this automatically for you. It works like this:
  • Events
    • A unit enters the map
  • Conditions
  • Actions
    • Set Variable Integer = (Integer + 1)
    • Unit - Set the custom value of (The new unit) to Integer
The result is that each Unit has it's own unique Custom Value. First unit = 1, Second unit = 2, Third unit = 3, etc.

Also, this is not doing anything:
  • Unit - Set the custom value of (Last created unit) to (Integer((Substring((String((Key (Last created unit).))), 4, 7))))
The Key of the unit? You aren't using a Hashtable variable so you should not be referencing any kind of Hasthable related data. Plus like I said above, don't EVER change a unit's custom value yourself when using a Unit Indexer.


Here's an example of using the parent's Max HP to influence the baby:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Random integer number between 1 and 10) Less than or equal to 5
      • Then - Actions
        • Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare is now pr...
        • Unit - Create 1 Unborn Horse for (Triggering player) at (Position of (Target unit of ability being cast)) facing Default building facing degrees
        • Unit Group - Add (Last created unit) to Unborn_Foals
        • -------- --------
        • -------- NEW --------
        • Set VariableSet Unborn_CV = (Custom value of (Last created unit))
        • Set VariableSet Father[Unborn_CV] = (Triggering unit)
        • Set VariableSet Mother[Unborn_CV] = (Target unit of ability being cast)
        • Set VariableSet Parents_Max_HP = (Max HP of Father[Unborn_CV] + Max HP of Mother[Unborn_CV])
        • Unit - Set Max HP of (Last created unit) to (Parents_Max_HP / 2)
        • -------- --------
        • -------- --------
        • Unit - Order (Target unit of ability being cast) to Load (Last created unit)
        • Hero - Add 50 experience to (Triggering unit), Show level-up graphics
      • Else - Actions
        • Game - Display to (All players matching ((Owner of (Casting unit)) Equal to (Matching player)).) the text: This mare did not b..
The Unborn Horse in this example is given half of the combined value of the Mother and Father's max hp. You could also store this value in an Array variable using the Unit Indexing method just like you're doing with Father[] and Mother[]. But that's unnecessary here since this PARTICULAR information is readily available without the need for a variable, which is what Cheshire was saying.
Ok, I think I see what you two are saying.

My next question, so after creating the information in the breeding trigger for the foal's genetics, how do you go about passing it on to the foal once its born in the birth trigger?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Ok, I think I see what you two are saying.

My next question, so after creating the information in the breeding trigger for the foal's genetics, how do you go about passing it on to the foal once its born in the birth trigger?
Anything you can Set you can also Get, so what we're saying is that passing the data is always possible as long as you have a reference to the Units involved like the Mother, Father, and the Baby/Fetus.

So for example, here I am setting a unit's Max HP:
  • Actions
    • Unit - Set Max HP of (Some unit) to 1000
Here I am getting the unit's Max HP:
  • Actions
    • Set Variable Max_HP_Variable = (Max HP of (Some unit))
Simple enough.

So with that in mind, you could pass this data between two Units pretty easily:
  • Actions
    • Set Variable Max_HP_Variable = (Max HP of (Unit A))
    • Unit - Set Max HP of (Unit B) to Max_HP_Variable
Now my second unit (B) has the same Max HP as the first unit (A).

Now let's say some time has passed and the Unborn Horse is finally born. I believe you have a trigger for when this occurs. At this stage you will have probably lost the reference to the Father and Mother, but that's why we have those two Unit array variables:
  • Actions
    • Set Variable Unborn_CV = (Custom value of (The newborn foal))
    • Set Variable Max_HP_Variable = (Max HP of Mother[Unborn_CV]) + Max HP of (Father[Unborn_CV])
    • Unit - Set Max HP of (The newborn foal) to Max_HP_Variable
Now our newborn foal's Max HP is equal to the sum of it's parents Max HP. Of course you can incorporate your own math equations here to change the outcome.

You can do this with Variable arrays as well, which is necessary for custom data like "Age" or "Gender". Variable arrays also let you "snapshot" data, meaning you can preserve the value of something over time without having to worry about it changing. This could serve useful if say a Father was to be removed from the game before the baby is born, since you could still access Father-related data even though the Father no longer exists.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
Anything you can Set you can also Get, so what we're saying is that passing the data is always possible as long as you have a reference to the Units involved like the Mother, Father, and the Baby/Fetus.

So for example, here I am setting a unit's Max HP:
  • Actions
    • Unit - Set Max HP of (Some unit) to 1000
Here I am getting the unit's Max HP:
  • Actions
    • Set Variable Max_HP_Variable = (Max HP of (Some unit))
Simple enough.

So with that in mind, you could pass this data between two Units pretty easily:
  • Actions
    • Set Variable Max_HP_Variable = (Max HP of (Unit A))
    • Unit - Set Max HP of (Unit B) to Max_HP_Variable
Now my second unit (B) has the same Max HP as the first unit (A).

Now let's say some time has passed and the Unborn Horse is finally born. I believe you have a trigger for when this occurs. At this stage you will have probably lost the reference to the Father and Mother, but that's why we have those two Unit array variables:
  • Actions
    • Set Variable Unborn_CV = (Custom value of (The newborn foal))
    • Set Variable Max_HP_Variable = (Max HP of Mother[Unborn_CV]) + Max HP of (Father[Unborn_CV])
    • Unit - Set Max HP of (The newborn foal) to Max_HP_Variable
Now our newborn foal's Max HP is equal to the sum of it's parents Max HP. Of course you can do incorporate your own math equations here to change the outcome.

You can do this with Variable arrays as well, which is necessary for custom data like "Age" or "Gender". Variable arrays also let you "snapshot" data, meaning you can preserve the value of something over time without having to worry about it changing. This could serve useful if say a Father was to be removed from the game before the baby is born, since you could still access Father-related data even though the Father no longer exists.
I did some setting up and it does seem to work but for some reason the foal is born with low red HP despite having the max HP, as in, say it has 500 HP but its born as idk 60/500. It also seems that the foals are all born with the same HP stat instead of randomized for each foal if they're all born very close together, the number also gets weirdly high despite the fact mare and stallion had low HP values when bred as well.
 
Level 25
Joined
Mar 29, 2020
Messages
1,466
I did some setting up and it does seem to work but for some reason the foal is born with low red HP despite having the max HP, as in, say it has 500 HP but its born as idk 60/500.
so far the examples we have been giving you have just been setting the max hp. you can also set the current hp. What me and uncle showed you is not the full solution, but rather the way you can "inherit" any stat. now you can implement this system with any other stats you wish to inherit.

in this specific case you don't need to inherit the stat of current hp, since you can just copy over the value from max hp (uness it works by percentage and then just do 100%).

It also seems that the foals are all born with the same HP stat instead of randomized for each foal if they're all born very close together, the number also gets weirdly high despite the fact mare and stallion had low HP values when bred as well.

this makes sense, since the math in this thread was just a simple example. We just gave the foal the average of the hp of both of it's parents. since the parents have probably already leveled up - this means the foal is getting the max hp stat according to the parents current levels.

a more accurate way to do it would be to use the average of the parent's health as a factor in the equation of how you compute the foals health. this ultimately is pretty flexible and depends on your vision for the base stats vs stat growth.

if a foal has about half the health of a breeding-level horse, you could have the base health for foals be (parents average)/2 and then add a random amount to it within the range you defined (maybe a range that can also be negative, so some horses have less stats then their parents did).

I think a good way to find a decent equation for this might be to brainstorm it with chat gpt.
 
Level 11
Joined
Nov 15, 2007
Messages
800
in this specific case you don't need to inherit the stat of current hp, since you can just copy over the value from max hp (uness it works by percentage and then just do 100%).
You could also just set the max HP of the unit you're modifying to 999999 or whatever in the object editor, since its current HP will be clamped to the modified max there's no need to modify it when max HP is reduced.
 
Top