• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Random Building

Not open for further replies.
Level 3
Oct 8, 2007
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
Level 8
Dec 29, 2006
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)
Just keep repeating this for each building that you want to have a chance to be build, and it should work. Hope this helps
Level 6
Feb 2, 2005
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
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
    return false

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) )

function InitTrig_Exchange takes nothing returns nothing
    set gg_trg_Exchange = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Exchange, EVENT_PLAYER_UNIT_UPGRADE_FINISH )
    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 )

If you want the map i can attach it for ya :)
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
Not open for further replies.