[Lua] Mass Unit Deletion

gargoyle575

Chieftain
Joined
Jan 20, 2012
Messages
94
How do I delete all instances of a unit? I know you can delete one unit at a time using Firetuner or a mod like Ingame Editor but I want to know how to delete all instances of a unit. As in instead of moving around the map deleting every Infantry unit, I want to delete all Infantry units for every Civ all at once.
 
Something like

Code:
-- change MAX_MAJOR_CIVS to MAX_CIV_PLAYERS to include CS and Barbs
for i = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
  local pPlayer = Players[i];
  if (pPlayer:IsAlive()) then
    for pUnit in pPlayer:Units() do
      -- If you just want infantry units, and not civ specific infantry units as well, remove "class" twice in the next line
      if (pUnit:GetUnitClassType() == GameInfoTypes.UNITCLASS_INFANTRY) then
        pUnit:Kill()
      end
    end
  end
end

remove the comments and you can put it all onto one line and paste it into the FireTuner Lua console
 
I think he means the generic infantry, that is, a unitcombat_melee domain_land unit.
 
I think he means the generic infantry, that is, a unitcombat_melee domain_land unit.

Change the condition to

Code:
if (pUnit:GetDomainType() == GameInfoTypes.DOMAIN_LAND) then
 
No I meant the actual unit, Infantry, but only as an example. But it worked out great, thanks.
 
Back
Top Bottom