HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Random Childbirth Replacement

04-24-2006, 08:48 AM#1
Anubis
Say i have a [Baby] when it is trained it is allowed a 5 second grace period before it is replaced by random of 2 options [Male Child] or [Female Child]. How would i go about this?

Im guessing i would need to use a (wait) function for the 5 seconds but how would i do the random part.
04-24-2006, 09:27 AM#2
Mystic Prophet
this one is actually pretty simple. you simply need to make a variable and set it to a random number between one and two. now assuming you train this unit from a building the trigger would go as follows. im using if then/else multiple functions because its easier to edit and read. but you can use a singular if/then if you prefer.

Trigger:
gender select
Collapse Events
Unit- building finishes training a unit
Collapse Conditions
(trained unit) equal to baby
Collapse Actions
set baby gender = (random integer number between 1 and 2)
wait 5.00 seconds
Collapse if (all conditions are true) then do (then actions) else do (else actions)
Collapse if - conditions
babygender equal to 1
Collapse then - actions
unit - replace (trained unit with a male using the new unit's max life and mana
Collapse else - actions
unit - replace (trained unit with a female using the new unit's max life and mana

you may need to set the trained baby as a variable due to the wait in the trigger. can't be sure without testing it though.
04-24-2006, 10:21 AM#3
Earth-Fury
Quote:
Originally Posted by Mystic Prophet
this one is actually pretty simple. you simply need to make a variable and set it to a random number between one and two. now assuming you train this unit from a building the trigger would go as follows. im using if then/else multiple functions because its easier to edit and read. but you can use a singular if/then if you prefer.

Trigger:
gender select
Collapse Events
Unit- building finishes training a unit
Collapse Conditions
(trained unit) equal to baby
Collapse Actions
set baby gender = (random integer number between 1 and 2)
wait 5.00 seconds
Collapse if (all conditions are true) then do (then actions) else do (else actions)
Collapse if - conditions
babygender equal to 1
Collapse then - actions
unit - replace (trained unit with a male using the new unit's max life and mana
Collapse else - actions
unit - replace (trained unit with a female using the new unit's max life and mana

you may need to set the trained baby as a variable due to the wait in the trigger. can't be sure without testing it though.

why set it to a variable?

Trigger:
gender select
Collapse Events
Unit- building finishes training a unit
Collapse Conditions
(trained unit) equal to baby
Collapse Actions
wait 5.00 seconds
Collapse if (all conditions are true) then do (then actions) else do (else actions)
Collapse if - conditions
(random integer number between 1 and 2) equal to 1
Collapse then - actions
unit - replace (trained unit with a male using the new unit's max life and mana
Collapse else - actions
unit - replace (trained unit with a female using the new unit's max life and mana

and i dont think "trained unit" works after a wait. use "triggering unit". but that might refer to the unit that trained the trained unit. should that be the case, store "trained unit" in a variable before the wait.
04-24-2006, 10:32 AM#4
Mystic Prophet
hmm didnt think of putting random integer as a condition.
04-24-2006, 10:48 AM#5
Anubis
very weird was working earlier with the variable now it isnt.. getting lots of females again
04-24-2006, 12:46 PM#6
BBDino
Is Fixed Random Seed turned off in the World Editor prefrences? "Test Map" will use non-random generation if this is turned on (i think it's default).
04-24-2006, 01:10 PM#7
Vuen
Quote:
Originally Posted by Earth-Fury
why set it to a variable?

and i dont think "trained unit" works after a wait. use "triggering unit". but that might refer to the unit that trained the trained unit. should that be the case, store "trained unit" in a variable before the wait.

Lol. You answered your own question.

Don't use triggering unit at all. Never use any of those after a wait, just in case. Set it to a temp variable instead.

Make a unit variable called TEMP_Unit in the variable editor, then do this:

Trigger:
gender select
Collapse Events
Unit- building finishes training a unit
Collapse Conditions
(trained unit) equal to baby
Collapse Actions
Custom Script: local unit udg_TEMP_Unit
set TEMP_Unit = (Trained Unit)
wait 5.00 game-time seconds
Collapse if (all conditions are true) then do (then actions) else do (else actions)
Collapse if - conditions
(random integer number between 1 and 2) equal to 1
Collapse then - actions
unit - replace TEMP_Unit with a male using the new unit's max life and mana
Collapse else - actions
unit - replace TEMP_Unit with a female using the new unit's max life and mana
set TEMP_Unit = No unit

The custom script gives you a local version of the variable, and setting it to 'no unit' at the end cleans up the memory leak. Also make sure you're waiting game-time seconds, as above.
04-24-2006, 07:31 PM#8
Anitarf
Trained unit should work after a wait. The only thing I know for sure that doesn't work after a wait are cast event responses (casting unit, target unit/point of ability being cast).