IsUnitType(id, string)

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

IsUnitType(id, string)

Post by enric »

Is there a way to get the unit type name e.i if it's a "Sherman", a "M10", a "Priest", or anything else ?
As BA functions only return an integer maybe adding an attribute (int) that matches the name of the units will help.. or, there is a way?.

Obviously checking every unit, with every Name seems a dirty task.
for every unit
if ( IsUnitType(id, "name") then
if ( IsUnitType(id, "name2") then
if ( IsUnitType(id, "name3") then
etc. etc.
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: IsUnitType(id, string)

Post by pipfromslitherine »

IsUnitType is the only way of checking the unit type.

What task are you trying to achieve?

Cheers

Pip
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: IsUnitType(id, string)

Post by enric »

We are testing a scenario where the morale for the defender side was oscillating each time a unit is killed, dropping morale when friendly unit is killed and raising when enemy is killed. This will affect the scenario each turn.

Now we just check for "infantry", or "tracked", or "halftrack", but we can not (well not easily) check for more specific cases, so if we want to differentiate between a Sherman or a M10, or M5, we must ask for every case inside tracked vehicles.

Will be nice a function that given an id returns the name of the unit.
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: IsUnitType(id, string)

Post by pipfromslitherine »

Why not just add a new attrib to all units in the squads file and then drive it from the data? This is what we do for almost all the game logic. It provides the greatest flexibility. You could even use an existing stat such as the cost, or a combo of the AP/HE/Armour ratings. E.g. a more costly unit's loss will produce a greater morale effect.

Cheers

Pip
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: IsUnitType(id, string)

Post by enric »

Thanks for the suggestion.
Is there a limit to the number of attributes that can be added to the Squad file?
pipfromslitherine
Site Admin
Site Admin
Posts: 9937
Joined: Wed Mar 23, 2005 10:35 pm

Re: IsUnitType(id, string)

Post by pipfromslitherine »

There is a limit of 128 attributes total (this includes any added by scripts) plus 16 array attribs with 8 entries each.

Cheers

Pip
Post Reply

Return to “Battle Academy : Modders Corner ”