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

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(player.id) == false then

EGroup_SetPlayerOwner(eg_villagebuildings, player.id)

end
end
end
end

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)

Done.

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ā€¦