Counting Units that are still Alive

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
jcb989
Colonel - Fallschirmjäger
Colonel - Fallschirmjäger
Posts: 1423
Joined: Fri Nov 05, 2010 12:02 am
Location: Bradenton, Florida

Counting Units that are still Alive

Post by jcb989 »

Hello,

Can anyone suggest the structure of a function I could use to count (a) total units left alive on each side, and (b) total number of units alive of a certain type?

Thanks,
pipfromslitherine
Site Admin
Site Admin
Posts: 9702
Joined: Wed Mar 23, 2005 10:35 pm

Re: Counting Units that are still Alive

Post by pipfromslitherine »

The basic format would be:

Code: Select all

	for(i=0;i<GetUnitCount(side);i++)
	{
		unit = GetUnitID(side, i) ;
		if( GetUnitDead(unit) == 1)
		{
		// dead
		}
		else
		{
		// alive
		}
	}
Use IsUnitType to tell if a given unit is of a specific type.

Cheers

Pip
follow me on Twitter here
jcb989
Colonel - Fallschirmjäger
Colonel - Fallschirmjäger
Posts: 1423
Joined: Fri Nov 05, 2010 12:02 am
Location: Bradenton, Florida

Re: Counting Units that are still Alive

Post by jcb989 »

Thanks Pip! I will put this to work!
Post Reply

Return to “Battle Academy : Modders Corner ”