Convert buildings with a script?

Is anyone find a way to convert neutral building to a player when a goal is completed ? For exemple : i build a neutral village with 10 maa in, if the player 3 kill all maa of the village, all the buildings of the village is converted to Player 3. If someone have the method it would be awesome to share, thx :smile:.

I made a quick code example how you could achieve this (it worked for me when I tested).

Assuming this is a single player (like a campaign map), you could do something like this:

Create an entity group for the buildings that we can name “eg_villagebuildings” with the EGroup_Create() function and add the buildings to the group using the EGroup_Add() function

Create a squad group for the MAA that we can name “sg_villagemilitary” with the SGroup_Create() function and add the MAA to it in the function UnitEntry_DeploySquads() that spawns them.

Create a function that we can call “village_maa_isAlive” that checks and returns true/false if all MAA in the village is dead or not with the built-in SGroup_IsAlive() function:

function village_maa_isAlive()
return SGroup_IsAlive(sg_villagemilitary)

Create a function that we can call “take_over_buildings” that change ownership of the village buildings from the A.I to the player, it also first checks if all village MAA is dead by calling the first function we created:

function take_over_buildings()
if village_maa_isAlive() == false then
for i, player in pairs(PLAYERS) do
if AI_IsAIPlayer( == false then



Add a global event in your init / game start function that listens for units being killed and make it call your take_over_buildings() function:

Rule_AddGlobalEvent(take_over_buildings, GE_EntityKilled)


Look in Content Editor’s scardocs to see exactly how you use the built-in functions and thier parameters.

1 Like

what if two non ai players play against ai… … since it goes through all players the last non-ai player will always be the owner… with GE_EntityKilled you know who killed the entity… just use that id…