GetUnitCount(0)

Modders can post their questions on scripting and more.

Moderators: Slitherine Core, BA Moderators

Post Reply
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

GetUnitCount(0)

Post by enric »

I was trying to define a border to exit units and I remembered in Rommel expansion you get a similar rutine.
I tried that rutine, but there should be something wrong with the loop that checks units as the result is that all units with higer id are also removed:

- if you move the unit ID 0 to the border all units are removed (no matter where they are)
- if you move unit 1 to the border all units except unit id 0 are removed
- if you move unit 6 to the border al units with ID >= 6 are removed.
- etc

The rutine is Rescue() and taked from AXIS10.BSF, is called from Tick()

FUNCTION RescueUnits()
{
int id ;
int i ;

for(i=0;i<GetUnitCount(0);i++)
{
id = GetUnitID(0, i) ;

if( GetUnitActive( id ) == 1)
{
if( GetUnitY(id) == 16 ) // 16 is the border
{
// rescue it
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;

// anything loaded on it?
if( GetLoadedUnit(id) != -1 )
{
// SetGlobal("Rescued", GetGlobal("Rescued")+1) ;
RemoveUnit( GetLoadedUnit(id), 1 ) ;
}

RemoveUnit(id, 1) ;
}
}
}
}
pipfromslitherine
Site Admin
Site Admin
Posts: 9929
Joined: Wed Mar 23, 2005 10:35 pm

Re: GetUnitCount(0)

Post by pipfromslitherine »

It seems to work correctly in the mission, are you saying you actually see this behaviour occurring? You could well SKIP removing units (because we are deleting units and the positions in the GetUnitID list would change) but I can't see how it would remove additional units.

Cheers

Pip
follow me on Twitter here
enric
Brigadier-General - 8.8 cm Pak 43/41
Brigadier-General - 8.8 cm Pak 43/41
Posts: 1855
Joined: Sun May 15, 2011 8:47 am

Re: GetUnitCount(0)

Post by enric »

are you saying you actually see this behaviour occurring?
Yes ( in my scenario test)
You could well SKIP removing units (because we are deleting units and the positions in the GetUnitID list would change) but I can't see how it would remove additional units.
I do not understand well this paragraph.

Don't worry, anyway I managed to get the task using another approach.
Post Reply

Return to “Battle Academy : Modders Corner ”