Victory object

Post Reply
orgit
Lance Corporal - Panzer IA
Lance Corporal - Panzer IA
Posts: 17
Joined: Wed Oct 23, 2019 10:37 am

Victory object

Post by orgit »

Hi,
I am looking for some help.
I am working on a small campaign and I am at my second mission.
I have placed three objective (called A-B-C) that are in player hand (wolf army).
I need to write on the editor a script that if the enemy (player one - ork) get the objective B they get the victory.
If they get A and/or C the game goes on.
Any help?.
Thanks

The script is similar to that of the mission Hollow Hills in stormclaw: a Rhino get on the objective tile x, y and win, but I need the opposite; whatever enemy units get on the objective tile x, y win the game.
FUNCTION Tick(side)
{
int i;
int DeadCount;
int RetreatCount;
int id;
int winterfang;
int object;


if (GetGlobal("RhinoCount") < 3)
{
for(i=0; i<GetUnitCount(0); i++)
{
//63,54
StartWorkString();
GetUnitTypeString(GetUnitTypeIndex(i));
if (StringCompare(GetWorkString(), "Rhino") == 1)
{
if (IsUnitValid(i) == 1)
{
if (GetUnitX(i) == 63 && GetUnitY(i) == 54)
{
AddVizFunctionCall("EndBattle", 0);
}
}

}
}
}

}
I have tried this but does not work:
FUNCTION StartTurn(side)
{
if (side == 1)
{
VictoryConditions() ;
}
}
FUNCTION VictoryConditions()
{
int i;
int id ;

for(i=1; i<GetUnitCount(1); i++)
{
id = GetUnitID(1, i) ;
if (IsUnitValid(i) == 0)
{
if (GetUnitX(i) == 47 && GetUnitY(i) == 35)
{
AddVizFunctionCall("EndBattle", 1);
}
}
}
}
pipfromslitherine
Site Admin
Site Admin
Posts: 9693
Joined: Wed Mar 23, 2005 10:35 pm

Re: Victory object

Post by pipfromslitherine »

+ The unit count starts at 0, not 1.
+ It looks like you are only checking the position if the IsUnitValid check returns 0, meaning it is an invalid unit.
+ It looks like you are using i as the param for the GetUnitX etc, but IIRC you need to use the id which you get above.

Cheers

Pip
follow me on Twitter here
orgit
Lance Corporal - Panzer IA
Lance Corporal - Panzer IA
Posts: 17
Joined: Wed Oct 23, 2019 10:37 am

Re: Victory object

Post by orgit »

First of all, thanks for your reply.
I am trying to put on maps only things that I can do but this time I am stucked and looking at the vanilla mission code is not so simple for me.
I hope on your patience.
So,
1) I would like to know if I need some other script line for what I want to achieve, or what I
wrote should be enough? I have tried to apply your answer but...... :cry:

2) "+ The unit count starts at 0, not 1."
- like this? for(i=0; i<GetUnitCount(0); i++)

3) "+ It looks like you are only checking the position if the IsUnitValid check returns 0, meaning it
is an invalid unit."
- I do not know if this line that I wrote is required and/or correct. I would like just say that if
side 1 (AI player) goes on tile x,y win, if the side is 0 (human player) get the objective but
not the victory.

4) "+ It looks like you are using i as the param for the GetUnitX etc, but IIRC you need to use the
id which you get above."
- like this? if (GetUnitX(id) == 47 && GetUnitY(id) == 35)

Thanks in any case.
A_Wal_
Corporal - Strongpoint
Corporal - Strongpoint
Posts: 65
Joined: Tue Jul 30, 2019 5:22 pm

Re: Victory object

Post by A_Wal_ »

orgit wrote: Mon Oct 02, 2023 4:11 pmlike this? for(i=0; i<GetUnitCount(0); i++)
Yes.
orgit wrote: Mon Oct 02, 2023 4:11 pmI do not know if this line that I wrote is required and/or correct. I would like just say that if side 1 (AI player) goes on tile x,y win, if the side is 0 (human player) get the objective but not the victory.
if (IsUnitValid(i) != 0) means if unit i valid check = false, so only if the unit is invalid.
orgit wrote: Mon Oct 02, 2023 4:11 pmlike this? if (GetUnitX(id) == 47 && GetUnitY(id) == 35)
Yes.
Try this.

Code: Select all

FUNCTION StartTurn(side)
{
int i;
int id;

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

			if (IsUnitValid(id) != 0)
			{
				if (GetUnitX(id) == 47 && GetUnitY(id) == 35)
				{
					AddVizFunctionCall("EndBattle", 1);
				}
			}
		}
	}
}
Post Reply

Return to “Sanctus Reach Mods and Scenario Design”