Page 1 of 1

Counterattacking if a line is breached?

Posted: Tue Aug 14, 2018 7:19 pm
by DestroyerofSid
Was searching to see if this was possible and saw Odenathaus had asked a similar question; however I'm having poor luck emulating his results. Here's what I have:

Code: Select all

	
	{
	if(side==1)
	{
	If(PlayerUnitIn(30,41,36,36,0,0,1)==1)
	{
		MoveTeamCoord(1,0,-1,-1,920);
		
Play-testing shows the enemy does not move even after the line has been breached. Would it have something to do with the final three values of the PlayerUnitIn line (I haven't been able to figure out their purpose) or does it have to do with the aggression level set?

As before, any help appreciated, thanks.

Re: Counterattacking if a line is breached?

Posted: Tue Aug 14, 2018 8:25 pm
by rbodleyscott

Code: Select all

// Function to report if any unrouted enemy unit is within the specified rectangle - with optional exclusions.
FUNCTION PlayerUnitIn(x1, y1, x2, y2, excludeFoot, excludeMounted, excludeLights)
As far as the script is concerned, your rectangle does not exist. You need to specify the coordinates of the lower corner of the rectangle, followed by the coordinates of the higher corner. x2 needs to be higher than x1, and y2 needs to be higher than y1. You need to use 30,36,36,41 not 30,41,36,36. This is probably the reason nothing at all is happening.

You have set it to ignore Lights, which seems likely to be what you want.

However, I am not sure what you are trying to achieve with an Aggression code of 920. Can you explain?

Also your MoveTeamCoord() order is to Team 0. Are the AI troops that you want to move in Team 0?

Re: Counterattacking if a line is breached?

Posted: Tue Aug 14, 2018 9:03 pm
by DestroyerofSid
rbodleyscott wrote: Tue Aug 14, 2018 8:25 pm
As far as the script is concerned, your rectangle does not exist. You need to specify the coordinates of the lower corner of the rectangle, followed by the coordinates of the higher corner. x2 needs to be higher than x1, and y2 needs to be higher than y1. You need to use 30,36,36,41 not 30,41,36,36. This is probably the reason nothing at all is happening.
Ah, its a rectangle. Adjusting for your advice made it work.

rbodleyscott wrote: Tue Aug 14, 2018 8:25 pm However, I am not sure what you are trying to achieve with an Aggression code of 920. Can you explain?
An error on my part - that's what I get for trying to do mental maths. Was attempting to add together a few of the 'ignore except close' - upon reflection ignore lights, seek and destroy is all I need.
rbodleyscott wrote: Tue Aug 14, 2018 8:25 pm Also your MoveTeamCoord() order is to Team 0. Are the AI troops that you want to move in Team 0?
Yes.

You've been a great help once again, hopefully this will be the last time I need to pester the forums.

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 12:28 am
by desicat
I want to do kind of the same thing, but just a line breach instead of a triangle. The AI Team "0" has a code 4 to hold, and I want them to seek and destroy (16, 16+4=20) after the line is breached. This is what I have. Was I supposed to add; "int IfPlayerUnitIn"?

FUNCTION StartTurnPost(side)
{
int IfPlayerUnitIn

// Scenario-specific AI code goes here - you can look at some of the historical scenarios for examples.
if (side == 1)
{
IfPlayerUnitIn(18,33,24,33,1)==1)
{
MoveTeamCoord(1,0,-1,-1,20);
}
}
}

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 8:02 am
by rbodleyscott
desicat wrote: Thu Apr 30, 2020 12:28 am I want to do kind of the same thing, but just a line breach instead of a triangle. The AI Team "0" has a code 4 to hold, and I want them to seek and destroy (16, 16+4=20) after the line is breached. This is what I have. Was I supposed to add; "int IfPlayerUnitIn"?

FUNCTION StartTurnPost(side)
{
int IfPlayerUnitIn

// Scenario-specific AI code goes here - you can look at some of the historical scenarios for examples.
if (side == 1)
{
IfPlayerUnitIn(18,33,24,33,1)==1)
{
MoveTeamCoord(1,0,-1,-1,20);
}
}
}
No. PlayerUnitIn() is a function call, not a variable.

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 10:17 am
by Paul59
Maybe have a look at the AI scripts I did for the Dara_P scenario in the Age of Belisarius DLC.

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 10:48 am
by desicat
rbodleyscott wrote: Thu Apr 30, 2020 8:02 am
desicat wrote: Thu Apr 30, 2020 12:28 am I want to do kind of the same thing, but just a line breach instead of a triangle. The AI Team "0" has a code 4 to hold, and I want them to seek and destroy (16, 16+4=20) after the line is breached. This is what I have. Was I supposed to add; "int IfPlayerUnitIn"?

FUNCTION StartTurnPost(side)
{
int IfPlayerUnitIn

// Scenario-specific AI code goes here - you can look at some of the historical scenarios for examples.
if (side == 1)
{
IfPlayerUnitIn(18,33,24,33,1)==1)
{
MoveTeamCoord(1,0,-1,-1,20);
}
}
}
No. IfPlayerUnitIn() is a function call, not a variable.
Took it out and still does not work. Error message states; Failed to find IfPlayerUnitIn, did you predefine it?

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 11:41 am
by Paul59
desicat wrote: Thu Apr 30, 2020 10:48 am
rbodleyscott wrote: Thu Apr 30, 2020 8:02 am
desicat wrote: Thu Apr 30, 2020 12:28 am I want to do kind of the same thing, but just a line breach instead of a triangle. The AI Team "0" has a code 4 to hold, and I want them to seek and destroy (16, 16+4=20) after the line is breached. This is what I have. Was I supposed to add; "int IfPlayerUnitIn"?

FUNCTION StartTurnPost(side)
{
int IfPlayerUnitIn

// Scenario-specific AI code goes here - you can look at some of the historical scenarios for examples.
if (side == 1)
{
IfPlayerUnitIn(18,33,24,33,1)==1)
{
MoveTeamCoord(1,0,-1,-1,20);
}
}
}
No. IfPlayerUnitIn() is a function call, not a variable.
Took it out and still does not work. Error message states; Failed to find IfPlayerUnitIn, did you predefine it?

See my AI scripts in the Dara_P scenario, to see how to use IfPlayerUnitIn.

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 1:29 pm
by rbodleyscott
desicat wrote: Thu Apr 30, 2020 10:48 am
rbodleyscott wrote: Thu Apr 30, 2020 8:02 am
desicat wrote: Thu Apr 30, 2020 12:28 am I want to do kind of the same thing, but just a line breach instead of a triangle. The AI Team "0" has a code 4 to hold, and I want them to seek and destroy (16, 16+4=20) after the line is breached. This is what I have. Was I supposed to add; "int IfPlayerUnitIn"?

FUNCTION StartTurnPost(side)
{
int IfPlayerUnitIn

// Scenario-specific AI code goes here - you can look at some of the historical scenarios for examples.
if (side == 1)
{
IfPlayerUnitIn(18,33,24,33,1)==1)
{
MoveTeamCoord(1,0,-1,-1,20);
}
}
}
No. IfPlayerUnitIn() is a function call, not a variable.
Took it out and still does not work. Error message states; Failed to find IfPlayerUnitIn, did you predefine it?
That is because the syntax is wrong. The function is called PlayerUnitIn(), not IfPlayerUnitIn().

The line should read

Code: Select all

if (PlayerUnitIn(18,33,24,33,1)==1)
not

Code: Select all

IfPlayerUnitIn(18,33,24,33,1)==1)

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 6:49 pm
by desicat
Richard, That sort of worked - but then a error code asked for 7 parameters instead of 5.

if (PlayerUnitIn(18,33,24,33,1)==1)

So I looked at Pauls scenario and added the two zeros that he had;

if (PlayerUnitIn(18,33,24,33,0,0,1)==1)

Paul, I have no idea what those two 0's do - but it did run and let me open the editor. Can you tell me what they do? (In your bsf example thread you defined the 5 digits for MoveTeamCoord, but this appears to be different.

I hope to get time to playtest it in the next day or so. Thank you both for the help, I know you are busy.

Re: Counterattacking if a line is breached?

Posted: Thu Apr 30, 2020 11:28 pm
by Paul59
desicat wrote: Thu Apr 30, 2020 6:49 pm Richard, That sort of worked - but then a error code asked for 7 parameters instead of 5.

if (PlayerUnitIn(18,33,24,33,1)==1)

So I looked at Pauls scenario and added the two zeros that he had;

if (PlayerUnitIn(18,33,24,33,0,0,1)==1)

Paul, I have no idea what those two 0's do - but it did run and let me open the editor. Can you tell me what they do? (In your bsf example thread you defined the 5 digits for MoveTeamCoord, but this appears to be different.

I hope to get time to playtest it in the next day or so. Thank you both for the help, I know you are busy.
Sorry, at the moment I can't remember what those two 0s do. I did that script over two and a half years ago, I might have got it from one of the Pike and Shot scenarios, if I find it I will let you know.

Re: Counterattacking if a line is breached?

Posted: Fri May 01, 2020 6:59 am
by rbodleyscott
desicat wrote: Thu Apr 30, 2020 6:49 pm Richard, That sort of worked - but then a error code asked for 7 parameters instead of 5.

if (PlayerUnitIn(18,33,24,33,1)==1)

So I looked at Pauls scenario and added the two zeros that he had;

if (PlayerUnitIn(18,33,24,33,0,0,1)==1)

Paul, I have no idea what those two 0's do - but it did run and let me open the editor. Can you tell me what they do? (In your bsf example thread you defined the 5 digits for MoveTeamCoord, but this appears to be different.
When using a function you need to find the function definition to see what the parameters mean. In this case the function definition is in MoreScenarioTools.BSF

Code: Select all

FUNCTION PlayerUnitIn(x1, y1, x2, y2, excludeFoot, excludeMounted, excludeLights)
Which is hopefully self-explanatory.

In script-defined functions none of the parameters are optional, you must include them all or you will get the error message you did. Some engine-defined functions do have optional parameters, but even then if parameters 5, 6 and 7 were optional, and you wanted to use optional parameter 7, you would still need to include a value for optional parameter 5 and 6, otherwise how would the engine know you want the value to go to parameter 7 and not 5?

Note that, as discussed earlier in the thread, x2 must not be lower than x1, and y2 must not be lower than y1, otherwise the code won't be able to figure out the bounds of the rectangle. It could, of course, be re-coded to do so, but it is a long time since I wrote the code for that function, and it works perfectly well as long as you follow that rule.