Page 1 of 1
Global Range Reduction Script
Posted: Sun Sep 02, 2012 7:04 pm
by Old_Warrior
Looking to figure out how to script a global range reduction for a mission. We have a fog script in one of the Normandy Missions but the problem is is that Unit A can spot for friendly Unit B, who is out of visibility range. If the Range value for the mission were set to the same length as the Visibility value then the units would not be able to spot for each other.
Here is the Fog script:
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
}
}
}
This works fine in reducing the visibility of units but not the range.
There must be script that can be added somewhere in the scenario script that will reduce the range. Can someone help me out with that using simple terms? Thanks!
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 8:03 pm
by pipfromslitherine
HERange and APRange would probably do it. I would need to double check the scripts to be sure, but off the top of my head that should work.
You might also want to set the *ReactionRange attribs too, but I think the ranges would prevent them from trying to react anyway.
Cheers
Pip
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 8:17 pm
by Old_Warrior
I will search around for the text "HERange" and "APRange" and see if I can come up with the script on my own. Thanks for pointing me in the right direction.
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 8:21 pm
by GottaLove88s
Unsure, but Pip might mean reducing the HERange and APRange distances and their reaction fire equivalents for the units concerned in squads.csv?
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 8:37 pm
by Old_Warrior
Here is a script from France5.BSF:
for(i=0; i<=1; i++)
{
id = GetUnitOnTile(18+i, 36) ;
if( id != -1 )
{
if( (GetGlobal("tanks") < 2) && (GetUnitDead(id) == 0) && (IsUnitType(id, "PANHARD_P178") == 1) )
{
SetAttrib(id, "AP", 0) ;
SetAttrib(id, "APRange", 0) ;
SetAttrib(id, "HERange", 0) ;
}
}
}
Is this saying that the range is now "0" ??
Is that "0" value the same as for the LOS script values?
So if
LOS = 25 ;
can I use:
SetAttrib(id, "APRange", 25) ;
Are the values measured in the same type of unit measurement?
???
I also need to know if a global range setting would affect the range for Special Acitons like Artillery and so on.
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 9:02 pm
by Old_Warrior
How close is this:
if( IsUnitSquadType(id, "TRACKED") == 1 )
SetAttrib(id, "APRange", 25) ;
SetAttrib(id, "HERange", 25) ;
This would set the range for all Tracked types. I just need to know if there exists a value for ALL types. And the above script may need more parts.
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 9:06 pm
by buffpilot
Am I on - DEF?
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 9:12 pm
by Old_Warrior
Yup, hearing you loud and clear, Buff.
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 9:24 pm
by Old_Warrior
Tried this in mission:
//*****************************************************************************
//StartTurn - Reduce LOS for Fog
//*****************************************************************************
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
}
}
// Reduce Range
if( IsUnitSquadType(id, "TRACKED") == 1 )
{
SetAttrib(id, "APRange", 3) ;
SetAttrib(id, "HERange", 3) ;
}
}
It did not work. Maybe needs to be under another FUNCTION? Maybe script is wrong? I didn't get an error message.
If the unit(A) has a helper unit(B) spot the target then the target can still be fired on by Unit A even if out of LOS range.
Re: Global Range Reduction Script
Posted: Sun Sep 02, 2012 11:10 pm
by pipfromslitherine
Why only for tracked units? I would expect that code to work - the CHECK_ functions for (e.g.) firing AP includes a check on APRange.
Ah - you have also put the reduce range stuff outside of the loop that goes through all the units, so it will only ever get done to the last unit on the 2nd side. It was hard to spot in the above code because the paste has killed off the indenting
Cheers
Pip
Re: Global Range Reduction Script
Posted: Mon Sep 03, 2012 12:05 am
by Old_Warrior
How should it look?
No, not only for tracked units. See my comments. I am looking for the statement that is for ALL units. Not just tracked. Is it "ALL" ??
Re: Global Range Reduction Script
Posted: Mon Sep 03, 2012 12:14 am
by pipfromslitherine
You have two for( loops, one doing each side (the one with GetSideCount() in it) and one doing each unit in the side (the one with GetUnitCount(i) in it). You need to place the APRange... stuff inside the loop, immediately following the LOS changes. The indentation should help see where the various code blocks are. Indented, the code should look something like below:
//*****************************************************************************
//StartTurn - Reduce LOS for Fog
//*****************************************************************************
FUNCTION StartTurnPost(side)
{
int i ;
int j ;
int id ;
int LOS ;
// Reduce LOS
for(i=0; i<GetSideCount(); i++)
{
for(j=0; j<GetUnitCount(i); j++)
{
id = GetUnitID(i, j) ;
if( GetBaseAttrib(id, "LOS") > 25 )
{
LOS = 25 ;
SetAttrib(id, "LOS", LOS) ;
}
// Reduce Range
if( IsUnitSquadType(id, "TRACKED") == 1 )
{
SetAttrib(id, "APRange", 3) ;
SetAttrib(id, "HERange", 3) ;
}
}
}
}
Re: Global Range Reduction Script
Posted: Mon Sep 03, 2012 12:24 am
by Old_Warrior
Odd that it would matter. The script was inside of the Function brackets. The Init ID was part of the FUNCTION and not the subscript.
I will try that out and get back to you ...
Re: Global Range Reduction Script
Posted: Mon Sep 03, 2012 12:45 am
by Old_Warrior
Here is the finished/working script:
Here is a screenshot of how it works in the game:
Note how the Sherman can only target ONE Panther even though it can "see" all of them (via the infantry unit in the lower left corner).
Also note that the script is not completely finished. This only affects tracked units. I need to change the expression so that it affects all units.
Re: Global Range Reduction Script
Posted: Mon Sep 03, 2012 3:45 pm
by pipfromslitherine
Old_Warrior wrote:Odd that it would matter. The script was inside of the Function brackets. The Init ID was part of the FUNCTION and not the subscript.
I will try that out and get back to you ...
The unit ID is different for every unit. Without the loop going through each unit, getting it's ID, and then doing things using that ID, then how would the code act on each unit? The variable id is just a name, it doesn't denote anything specific just because it is called id.
Cheers
Pip
Re: Global Range Reduction Script
Posted: Mon Sep 03, 2012 4:33 pm
by Old_Warrior
Here is the updated script:
I tried it out in the mission and it works.
Thanks for helping out, Pip!
Now if I can just write a script that will remove the fog from my brain!
