I have code so they build Command and Structure Factory, but i don't how i code so they will take the new Structure Factory and build new buildings.
Here is a code i have done with time trigger.
buildGroup2 = CreateBuildingGroup(Player[1]);
buildGroup2.SetRect(MAP_RECT(12+31, 108-1, 28+31, 114-1));
buildGroup2.TakeUnit(ConVec3);
buildGroup2.TakeUnit(ConVec4);
CreateTimeTrigger(1, 0, 28000, "Base2");
SCRIPT_API void Base2()
{
buildGroup2b = CreateBuildingGroup(Player[1]);
buildGroup2b.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
buildGroup2b.TakeAllUnits(buildGroup2);
buildGroup2b.TakeUnit(SF);
buildGroup2b.RecordBuilding(LOCATION(191+31, 23-1), mapCommandCenter, mapNone);
buildGroup2b.RecordBuilding(LOCATION(191+31, 26-1), mapStructureFactory, mapNone);
buildGroup2b.RecordBuilding(LOCATION(197+31, 22-1), mapVehicleFactory, mapNone);
}
Create a time trigger that fires every 10 ticks that checks if the AI Player has a Structure Factory at the specified location and assigns it to the Build Group if found.
/* Assuming you have some kind of Save Data struct */
struct SaveData()
{
Unit AI_SF2;
Trigger CheckSecondSF;
...
};
SaveData SD;
...
/* In the Base2 callback function */
{
SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}
...
SCRIPT_API void AI_SFCheck()
{
/* Let's use an enumerator */
Unit curUnit;
PlayerBuildingEnum unitEnum(AI Player Number, mapNone);
while (unitEnum.GetNext(curUnit) )
{
/* Check if this is the unit we want (make sure it's an SF and in the right spot) */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location() == LOCATION(191+31, 26-1) ) )
{
/* We've found it! Record it and destroy this trigger. */
SD.AI_SF2 = curUnit;
SD.CheckSecondSF.Destroy();
}
}
}
This is the part where I mention I just wrote that and it's completely untested. It probably should work, but let me know if you need help with it.
Oh. Oops.
/* Replace this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location() == LOCATION(191+31, 26-1) ) )
/* With this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )
Tell me if it works now.
As for the SaveData struct, check out my tutorials for more info.
Oh. Oops.
/* Replace this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location() == LOCATION(191+31, 26-1) ) )
/* With this line */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )
Tell me if it works now.
As for the SaveData struct, check out my tutorials for more info.
Here is my code i have done
/* Generic Example */
/* Define the struct */
struct structType
{
/* Stuff goes here */
}; /* NOTE: You MUST have that semi-colon after the struct definition */
/* Declare the struct */
structType structName;
/* OP2-specific Example */
struct SaveData
{
/* Triggers */
Trigger Meteor, /* Meteor time trigger */
CheckSecondSF,
Vortex; /* Vortex time trigger */
/* AI Units */
Unit AI_CC, /* AI Command Center */
AI_SF2, /* AI Structure Factory */
AI_VF; /* AI Vehicle Factory */
/* AI FightGroups */
FightGroup LynxRush, /* Microwave Lynx Rush attack group */
Defenses; /* Base defense group */
/* Misc. Data */
int numAI; /* AI player number */
};
SaveData SD;
/* In the Base2 callback function */
{
SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}
/* Usage */
SCRIPT_API void AI_SFCheck()
{
/* Let's use an enumerator */
Unit curUnit;
PlayerBuildingEnum unitEnum(1, mapNone);
while (unitEnum.GetNext(curUnit) )
{
/* Check if this is the unit we want (make sure it's an SF and in the right spot) */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )
{
/* We've found it! Record it and destroy this trigger. */
SD.AI_SF2 = curUnit;
SD.CheckSecondSF.Destroy();
}
}
i got two error
1>.\Main.cpp(772) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(804) : fatal error C1075: end of file found before the left brace '{' at '.\Main.cpp(778)' was matched
What do I have wrong here?
Dont understand what i need to change in this code
SaveData SD;
...
/* In the Base2 callback function */
{
SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}
...
:o
(...?)
I have delete the code i have done and copy your text again.
/* Assuming you have some kind of Save Data struct */
struct SaveData()
{
Unit AI_SF2;
Trigger CheckSecondSF;
...
};
SaveData SD;
...
/* In the Base2 callback function */
{
SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
}
...
SCRIPT_API void AI_SFCheck()
{
/* Let's use an enumerator */
Unit curUnit;
PlayerBuildingEnum unitEnum(AI Player Number, mapNone);
while (unitEnum.GetNext(curUnit) )
{
/* Check if this is the unit we want (make sure it's an SF and in the right spot) */
if ( (curUnit.GetType() == mapStructureFactory) && (curUnit.Location().x == 191+31) && (curUnit.Location().y == 26-1) )
{
/* We've found it! Record it and destroy this trigger. */
SD.AI_SF2 = curUnit;
SD.CheckSecondSF.Destroy();
}
}
}
And got all this errors in Visual C++ 2008 Express Edition
1>.\Main.cpp(735) : error C2059: syntax error : ')'
1>.\Main.cpp(736) : error C2143: syntax error : missing ';' before '{'
1>.\Main.cpp(736) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(743) : error C2079: 'SD' uses undefined struct 'SaveData'
1>.\Main.cpp(745) : error C2059: syntax error : '...'
1>.\Main.cpp(748) : error C2143: syntax error : missing ';' before '{'
1>.\Main.cpp(748) : error C2447: '{' : missing function header (old-style formal list?)
1>.\Main.cpp(752) : error C2059: syntax error : '...'
1>.\Main.cpp(755) : error C2143: syntax error : missing ';' before '{'
1>.\Main.cpp(755) : error C2447: '{' : missing function header (old-style formal list?)
The "..." means "your own code goes here". I don't want to write
int InitProc()
{
Player[0].GoEden();
}
Since that implies the only thing that should be in InitProc is the GoEden call, whereas this
int InitProc()
{
...
Player[0].GoEden();
...
}
implies that you need to put some of your own code in there.
Here is my code.
Unit ConVec3, ConVec4;
TethysGame::CreateUnit(ConVec3, mapConVec, LOCATION(15+31, 113-1), 1, mapCommandCenter, 3);
x.DoSetLights(1);
TethysGame::CreateUnit(ConVec4, mapConVec, LOCATION(17+31, 113-1), 1, mapStructureFactory, 3);
x.DoSetLights(1);
First, they wait in the main base
buildGroup2 = CreateBuildingGroup(Player[1]);
buildGroup2.SetRect(MAP_RECT(12+31, 108-1, 28+31, 114-1));
buildGroup2.TakeUnit(ConVec3);
buildGroup2.TakeUnit(ConVec4);
Then after, they will go to the next area.
SCRIPT_API void Base2()
{
buildGroup2b = CreateBuildingGroup(Player[1]);
buildGroup2b.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
buildGroup2b.TakeAllUnits(buildGroup2);
buildGroup2b.RecordBuilding(LOCATION(191+31, 23-1), mapCommandCenter, mapNone);
buildGroup2b.RecordBuilding(LOCATION(191+31, 26-1), mapStructureFactory, mapNone);
buildGroup2b.RecordBuilding(LOCATION(197+31, 22-1), mapVehicleFactory, mapNone);
}
They build Command Center and Structure Factory, but ConVecs will not record Structure Factory and build next building on the list.
Now i got it, it works now at last! :D
SD.buildGroup2 = CreateBuildingGroup(Player[1]);
SD.buildGroup2.SetRect(MAP_RECT(12+31, 108-1, 28+31, 114-1));
SD.buildGroup2.TakeUnit(SD.ConVec3);
SD.buildGroup2.TakeUnit(SD.ConVec4);
SD.buildGroup2.SetDeleteWhenEmpty(1);
CreateTimeTrigger(1, 1, 1000, "Base2a");
CreateTimeTrigger(1, 1, 13000, "Base2");
SD.CheckSecondSF = CreateTimeTrigger(1, 0, 10, "AI_SFCheck");
SCRIPT_API void Base2a()
{
Unit ConVec3 ,ConVec4, SF2;
SD.buildGroup2b = CreateBuildingGroup(Player[1]);
SD.buildGroup2b.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
SD.buildGroup2b.RecordBuilding(LOCATION(191+31, 23-1), mapCommandCenter, mapNone);
SD.buildGroup2b.RecordBuilding(LOCATION(191+31, 26-1), mapStructureFactory, mapNone);
SD.buildGroup2b.TakeAllUnits(SD.buildGroup2);
SD.buildGroup2b.TakeUnit(SD.SF2);
}
SCRIPT_API void Base2()
{
Unit ConVec3 ,ConVec4, SF2;
SD.buildGroup2c = CreateBuildingGroup(Player[1]);
SD.buildGroup2c.SetRect(MAP_RECT(185+31, 19-1, 194+31, 28-1));
SD.buildGroup2c.TakeAllUnits(SD.buildGroup2b);
SD.buildGroup2c.TakeUnit(SD.SF2);
SD.buildGroup2c.RecordBuilding(LOCATION(196+31, 22-1), mapVehicleFactory, mapNone);
}
SCRIPT_API void AI_SFCheck()
{
// Let's use an enumerator
Unit SF2;
PlayerBuildingEnum unitEnum(1, mapNone);
while (unitEnum.GetNext(SF2) )
{
// Check if this is the unit we want (make sure it's an SF and in the right spot)
if ( (SF2.GetType() == mapStructureFactory) && (SF2.Location().x == 191+31) && (SF2.Location().y == 26-1) )
{
// We've found it! Record it and destroy this trigger.
SD.SF2 = SF2;
SD.CheckSecondSF.Destroy();
}
}
}
You need to Create a group after the StructureFactory is done with a TimeTrigger.
What?
You should be able to create a group anywhere before first being used. Only the record unit part needs to assign a handle to an actually existing entity.
Has found a way that you meant, a code that works that way, thx to Sirbomber, Flashy and more. from various topics i got a combination of codes that works. :)
Here is the solution.
SCRIPT_API void Red_SFCheck()
{
  // Let's use an enumerator
  IUnit RSF1;
  PlayerBuildingEnum unitEnum(2, mapNone);
  while (unitEnum.GetNext(RSF1) )
  {
    // Check if this is the unit we want (make sure it's an SF and in the right spot)
    if ( (RSF1.GetType() == mapStructureFactory) && (RSF1.Location().x == 28+31) && (RSF1.Location().y == 31-1) )
  {
      switch(RSF1.GetBusy())
        {
          case ctMoDevelop:
          case ctMoUnDevelop:
          case ctMoDismantle:
            break;
        default:
        // We've found it!  Record it and destroy this trigger.
        SD.RSF1 = RSF1;
        CreateTimeTrigger(1, 1, 50, "RedBase1");
        SD.CheckFirstSF.Destroy();
      }
    }
  }
}