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);
}
}
}
}
Victory object
-
- Site Admin
- Posts: 9663
- Joined: Wed Mar 23, 2005 10:35 pm
Re: Victory object
+ 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
+ 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
Re: Victory object
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......
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.
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......

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.
Re: Victory object
Yes.
if (IsUnitValid(i) != 0) means if unit i valid check = false, so only if the unit is invalid.
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);
}
}
}
}
}