function VillageSettlement_Conditions takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 'hfoo'
/* This 'hfoo' has to be replaced the Unit-Type Raw ID of the TownHall,
you can see it by pressing "CTRL+D" in the Object Editor. You'll se
everything has a different ID.
What this does is check if the Unit-Type of the unit that enters any of the
listed regions is a Town Hall.
All this green lines can be deleted */
endfunction
/* Anything placed in the VillageSettlement_Actions will happen only if the unit
that enters any of the regions is a TownHall */
function VillageSettlement_Actions takes nothing returns nothing
/* Here's where we'll make everything else, based on the TownHall */
local unit u = GetTriggerUnit() // The Triggering Unit (The TownHall)
local integer i = GetHandleId(u) // The Handle ID of the TownHall
local hashtable h = udg_Hash // h is easier than "udg_Hash".
local integer RID = GetHandleId(GetTriggeringRegion())
local integer pn = GetPlayerId(GetOwningPlayer(u)) + 1 // The Player Number of the Owner of the TownHall
local integer TotalHappiness = udg_Happiness+udg_GlobalModifiers[pn]
local texttag TT = CreateTextTag() // The Floating Text
local integer TTID = GetHandleId(TT) // The Floating Text ID
// udg_Hapiness is an Integer Variable for Default Hapiness
// udg_GlobalModifiers is an Integer Variable Array for player actions that affects
// the happiness of all towns (upgrades, alliances, revolts, etc.) of that player
call GroupAddUnit(udg_TownHalls, u) // This adds the TownHall to the TownHalls group.
call SaveBoolean(h, RID, 0, true) // Means the Region was occupied
call SaveInteger(h, i, 0, TotalHappiness) // We save the Hapiness into the TownHall ID
call SaveInteger(h, i, 1, 0) // We'll use this to modify just this town hapiness
call SaveInteger(h, i, 2, TTID) // The TextTag ID to modify it later
//These 3 following actions are for the Floating Text
call SetTextTagText(TT, "Happiness: " + I2S(TotalHappiness), 10 * 0.023 / 10) // the first 10 is the Size
call SetTextTagPos(TT, GetUnitX(u), GetUnitY(u), 10.00) // This 10.00 is the Height
call SetTextTagColor(TT, 255, 255, 255, 255) // These are red, green, blue, and alpha
// Cleaning Leaks
set u = null
set h = null
set TT = null
endfunction
//===========================================================================
function InitTrig_VillageSettlement takes nothing returns nothing
set udg_Hash = InitHashtable() // This requires a Hashtable variable creation called "Hash".
// Create a Region Array and call it "Regions"
local region R1 = CreateRegion()
call RegionAddRect(R1, gg_rct_1)
call TriggerRegisterEnterRegion(gg_trg_VillageSettlement, R1, null)
call SaveBoolean(udg_Hash, GetHandleId(R1), 0, false)
local region R2 = CreateRegion()
call RegionAddRect(R1, gg_rct_2)
call TriggerRegisterEnterRegion(gg_trg_VillageSettlement, R2, null)
call SaveBoolean(udg_Hash, GetHandleId(R2), 0, false)
local region R3 = CreateRegion()
call RegionAddRect(R1, gg_rct_3)
call TriggerRegisterEnterRegion(gg_trg_VillageSettlement, R3, null)
call SaveBoolean(udg_Hash, GetHandleId(R3), 0, false)
local region R4 = CreateRegion()
call RegionAddRect(R1, gg_rct_4)
call TriggerRegisterEnterRegion(gg_trg_VillageSettlement, R4, null)
call SaveBoolean(udg_Hash, GetHandleId(R4), 0, false)
/* R1, R2, R3, R4 are the regions
gg_rct_1, gg_rct_2, gg_rct_3, gg_rct_4 are the rects (what you create in the editor).
The system adds "gg_rct_*" to the name of the region. Continue with all the 100 regions
the same way those 4 were made. */
call TriggerAddCondition( gg_trg_VillageSettlement, function VillageSettlement_Conditions )
call TriggerAddAction( gg_trg_VillageSettlement, function VillageSettlement_Actions )
endfunction