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: 1418
Joined: Fri Nov 05, 2010 12:02 am
Location: Bradenton, Florida

Counting Units that are still Alive

Post by jcb989 » Sun Aug 10, 2014 12:48 pm

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: 8952
Joined: Wed Mar 23, 2005 10:35 pm

Re: Counting Units that are still Alive

Post by pipfromslitherine » Mon Aug 11, 2014 3:55 pm

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: 1418
Joined: Fri Nov 05, 2010 12:02 am
Location: Bradenton, Florida

Re: Counting Units that are still Alive

Post by jcb989 » Mon Aug 11, 2014 10:21 pm

Thanks Pip! I will put this to work!

Post Reply

Return to “Battle Academy : Modders Corner ”