Use a trigger with 2 types of events: Unit Enters Region and Unit Leaves Region, setting "Unit" to the preset "Any Unit."
You don't necessarily have to use pre-placed regions to make this work, although it would probably be much simpler. I'm going to assume that's what you will want to do. Use a Unit Enters Region and a Unit Leaves Region event for each territory you want to be contestable.
Next you need to operate a switch based on the triggering region. You'll need a case for each region you have. Then it's just a matter of setting up the proper conditions and actions:
General-Switch(Actions)dependingon(Triggeringregion)CasesGeneral-If(Barracks1)ActionsUnitGroup-Pickeachunitin(AnyunitsinBarracks1ownedbyplayerAnyPlayermatchingExcluded:Structure,Missile,Dead,Hidden,withatmost1)anddo(Actions)ActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(NumberofLivingunitsin(UnitsinBarracks1havingallianceEnemywithplayer(Ownerof(Pickedunit))matchingExcluded:Structure,Missile,Dead,Hidden,withatmostAnyAmount))==0(OwnerofBarracks1Unit)!=(Ownerof(Pickedunit))ThenUnit-ChangeownershipofBarracks1Unittoplayer(Ownerof(Pickedunit))andChangeColorUI-Display"You tooked it overz LOLOLOL:):):)"for(Playergroup((Ownerof(Pickedunit))))toChatareaElseDefault
This code basically picks 1 random unit from within the region (excluding structures - that's very important) and checks to see if the owner of that unit has any enemies. If there are enemies, nothing happens. If not, the ownership of the structure changes to the owner of that unit and a message is displayed. Make sure you set it to "At Most 1" or it might cause lag with a lot of units present.
You'll also need a trigger to handle a unit death within a region, which will look almost the same with a few key changes:
Contest(Death)EventsUnit-AnyUnitdiesLocalVariablesConditionsActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If((Positionof(Triggeringunit))isinBarracks1)==TrueThenUnitGroup-Pickeachunitin(AnyunitsinBarracks1ownedbyplayerAnyPlayermatchingExcluded:Structure,Missile,Dead,Hidden,withatmost1)anddo(Actions)ActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If(NumberofLivingunitsin(UnitsinBarracks1havingallianceEnemywithplayer(Ownerof(Pickedunit))matchingExcluded:Structure,Missile,Dead,Hidden,withatmostAnyAmount))==0(OwnerofBarracks1Unit)!=(Ownerof(Pickedunit))ThenUnit-ChangeownershipofBarracks1Unittoplayer(Ownerof(Pickedunit))andChangeColorUI-Display"You tooked it overz LOLOLOL:):):)"for(Playergroup((Ownerof(Pickedunit))))toChatareaGeneral-BreakElseElse
Here I use the Unit Dies event and an If/Then/Else function instead of a Switch function. This is because there isn't a simple function I can use when determining different cases for the switch. Anyway, you'll need to use a different If/Then/Else function for each territory. The trigger basically checks which region the dying unit is in and runs the same actions as the first trigger.
That should do it. Let me know if you have any further questions.
Was my response helpful? I'm thinking about making it into a mini-tutorial. Please let me know :)
Use a trigger with 2 types of events: Unit Enters Region and Unit Leaves Region, setting "Unit" to the preset "Any Unit."
You don't necessarily have to use pre-placed regions to make this work, although it would probably be much simpler. I'm going to assume that's what you will want to do. Use a Unit Enters Region and a Unit Leaves Region event for each territory you want to be contestable.
Here's an example of what I mean so far:
Next you need to operate a switch based on the triggering region. You'll need a case for each region you have. Then it's just a matter of setting up the proper conditions and actions:
This code basically picks 1 random unit from within the region (excluding structures - that's very important) and checks to see if the owner of that unit has any enemies. If there are enemies, nothing happens. If not, the ownership of the structure changes to the owner of that unit and a message is displayed. Make sure you set it to "At Most 1" or it might cause lag with a lot of units present.
You'll also need a trigger to handle a unit death within a region, which will look almost the same with a few key changes:
Here I use the Unit Dies event and an If/Then/Else function instead of a Switch function. This is because there isn't a simple function I can use when determining different cases for the switch. Anyway, you'll need to use a different If/Then/Else function for each territory. The trigger basically checks which region the dying unit is in and runs the same actions as the first trigger.
That should do it. Let me know if you have any further questions.