# Random Building

Status
Not open for further replies.

#### Just call me Js

Level 3
Have you guys seen in like Gem TD where the building comes out random? Like you build something then it comes out probably as Building1 or Building2 or Building3?

I am trying to put that effect into my map but dont know how to

#### YoshiRyu

Level 9
trigger
builder is issued to built B0
set randint = random between 1 and 3
if (randint=1) order builder to built B1
if (randint=2) order builder to built B2
if (randint=3) order builder to built B3

#### Xzife_TD01

Level 8
Im not a computer with WE on it but ill try an explain, hope I can write it ok...

Events: A unit finishes construction
Conditions: Unit Type of (Constructed Structure) equal to (your structure)
Actions: If: (Random number from x to y) equal to 1
Then: Unit replace (Constructed Structure) With a (your structure)
Else If: (Random number from x to y) equal to 2
Then: Unit replace (Constructed Structure) With a (your structure)
Etc.
Just keep repeating this for each building that you want to have a chance to be build, and it should work. Hope this helps

#### YoshiRyu

Level 9
i prefer mine, because you've got the right build animation for each kind of building

#### Xelephant

Level 6
I did that one in a while. I used two Triggers, Type 1 was always builded and when it finished it was exchange with 2 other towers or would simply stay.

This one is to set my array
• Variables
• Events
• Map initialization
• Conditions
• Actions
• Set LuckDips[1] = Lucky Dip Type 2 Level 1
• Set LuckDips[2] = Lucky Dip Type 3 Level 1
• Set LuckDips[3] = Lucky Dip Type 2 Level 2
• Set LuckDips[4] = Lucky Dip Type 3 Level 2
• Set LuckDips[5] = Lucky Dip Type 2 Level 3
• Set LuckDips[6] = Lucky Dip Type 3 Level 3
• Set LuckDips[7] = Lucky Dip Type 2 Level 4
• Set LuckDips[8] = Lucky Dip Type 3 Level 4
• Set LuckDips[9] = Lucky Dip Type 2 Level 5
• Set LuckDips[10] = Lucky Dip Type 3 Level 5
This one is to exchange the Towers
JASS:
``````function Trig_Exchange_Conditions takes nothing returns boolean
local integer u
set u = GetUnitTypeId(GetTriggerUnit())
if ( (  u == 'h00S' ) or (u == 'h00Y') or (u == 'h00B') or ( u== 'h00T') or (u == 'h00X' )) then
return true
endif
return false
endfunction

function Trig_Exchange_Actions takes nothing returns nothing
local integer tmp
local integer value
set value = GetUnitUserData(GetTriggerUnit()) + 1
call SetUnitUserData(GetTriggerUnit(),value)
set tmp =  GetRandomInt(0,2)
if (tmp != 0) then
set tmp = tmp + 2 * (value - 1)
call ReplaceUnitBJ(GetTriggerUnit(),udg_LuckDips[tmp],bj_UNIT_STATE_METHOD_MAXIMUM)
call SetUnitUserData(GetLastReplacedUnitBJ(),value)
call SelectUnitForPlayerSingle( GetLastReplacedUnitBJ(), Player(0) )
endif
endfunction

//===========================================================================
function InitTrig_Exchange takes nothing returns nothing
set gg_trg_Exchange = CreateTrigger(  )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Exchange, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddCondition( gg_trg_Exchange, Condition( function Trig_Exchange_Conditions ) )
call TriggerAddAction( gg_trg_Exchange, function Trig_Exchange_Actions )
endfunction``````

If you want the map i can attach it for ya

#### Xzife_TD01

Level 8
Thats true, i never gave a thought about the animations lol

#### Just_Spectating

Level 39
it has to do with random integer variables and number integer of the # of random integer variables (to stand for the unit-type) input into "when unit builds building" event or w.e the action will replace the "building unit" with a random unit type from an integeral value of random(that would stand for your types of buildings that will be a % to be built) from 1 to "the # of random integer variables" like wut godless did but he forgot to add the "# of random integer variable"

• Initialize random buildings
• Events
• Map initialization
• Conditions
• Actions
• -------- These next values will be an example. --------
• Set RandomBuilding[1] = Guard Tower
• Set RandomBuilding[2] = Cannon Tower
• Set RandomBuilding[3] = Arcane Tower
• Set RandomBuilding[4] = Watch Tower
• Set RandomBuilding[5] = Spirit Tower
• Set RandomBuilding[6] = Nerubian Tower
• Set RandomBuilding[7] = Ancient Protector
• Set RandomBuilding[8] = Tidal Guardian
• Set RandomBuildingNumber = 8
set the RandomBuildingNumber to = the last value you input for your RandomBuildings

• Random regular buildings
• Events
• Unit - A unit Finishes construction
• Conditions
• Actions
• Unit - Replace (Constructed structure) with a RandomBuilding[(Random integer number between 1 and RandomBuildingNumber)] using The new unit's default life and mana
This will be universal, and will work for any player that builds a building. so you will only need one of this trigger

#### PurplePoot

Level 40
Array indexes start at 0 -.-

#### Just_Spectating

Level 39
Array indexes start at 0 -.-

w/e it still works... and starting at 1 makes it easier to see how many you have, else you might forget it starts at 0 and miss one

#### YoshiRyu

Level 9
that's just a small mem leak, because the 0 index still take its space in the ram.

PS: it make it easier for you, but anyone who is used to program use [0,n-1] index for the n-sized arrays, because that's the proper way to use arrays.

Status
Not open for further replies.

Replies
4
Views
1K
Replies
4
Views
991
Replies
12
Views
1K
Replies
2
Views
785
Replies
3
Views
9K