I am using this code to create a group of tanks but its not repeating itself.
How do I get it so it will?
I should be able to use just a line of code now, I know a lot more then I used to so I don't need step by step instructions "I hope" <_<
I am starting to understand other people's code posted in the Wiki :P
FightGroup grp1;
SCRIPT_API void CreateTanks()
{
Unit u;
grp1=CreateFightGroup(Player[1]);
grp1.SetRect(MAP_RECT(30,8,34,12));
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,2),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,4),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
}
SCRIPT_API void Attack()
{
grp1.DoAttackEnemy();
}
int InitProc()
{
int i;
CreateTimeTrigger(1,1,2000,3000,"CreateTanks");
CreateTimeTrigger(1,1,4000,"Attack");
return 1; // return 1 if OK; 0 on failure
}
Two things:
first, to answer your question... this would solve your problem:
CreateTimeTrigger(1,0,2000,3000,"CreateTanks");
CreateTimeTrigger(1,0,4000,"Attack");
The second param in any trigger determines wether it will be fired once (1) or continuously (0).
...if not for the next thing: (sorry)
Your code will work fine on the first run: the group will be created, and after timetrigger "Attack" fires, they will be set to attack-mode. However, ...
Timer 1 fires after 20~30 marks. Timer 2 fires after precisely 40 marks (so,,, 10~20 later). Once Timer 1 has fired, it will again start counting, and fire at the same interval again (20~30 marks later) and it will de-synchronise with Timer2.
Example: when you create the "CreateTanks" timer, OP2 sets an exact time, for example 2500 ticks (could be anything between 2000~3000 btw). So: Timer1 fies at mark 35 and timer2 at mark 40.
The next time the tiemr1 (CreateTanks) fires is at mark 50. The second time that timer2 fires is at mark 80.
Now you get what i'm saying ?
The other is: you keep creating new groups, without destroying them. Outpost has 127 ScStubs for you to use. Each timer or group is 1 stub. If you want it to work the way u want, you should add DeleteWhenEmpty(1) to your group, which lets op2 delete the group you've created once all those units in that specific group are dead, freeing up the stub.
Still this won't solve the desync.
In order to solve that, you need to change the code to something like this:
SCRIPT_API void CreateTanks()
{
Unit u;
grp1=CreateFightGroup(Player[1]);
grp1.SetRect(MAP_RECT(30,8,34,12));
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,2),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,4),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
grp1.SetDeleteWhenEmpty(1);
CreateTimeTrigger(1,1,1000,"Attack");
}
This time, make sure the 2nd param of the trigger is 1, since this trigger only needs to fire once for this particular group.
I hope this helps, although i'm unsure if it solves the problem 100%. it may still crash in the long run
okay it seems to be working fine, But can you tell me if this code will cause problems a long way into the game?
oh and I think I am ready to test this one so if you think the code will work, do you want to beta test it? or any other person that knows if this will work can beta test it too
FightGroup grp1;
SCRIPT_API void CreateTanks()
{
Unit u;
grp1=CreateFightGroup(Player[1]);
grp1.SetRect(MAP_RECT(30,8,34,12));
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,2),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,3),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,1),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
TethysGame::CreateUnit(u,mapLynx,LOCATION(158,4),1,mapMicrowave,SouthWest);
grp1.TakeUnit(u);
}
SCRIPT_API void Attack()
{
grp1.DoAttackEnemy();
}
CreateTimeTrigger(1,1,2000,"CreateTanks");
CreateTimeTrigger(1,0,2200,9000, "CreateTanks");
CreateTimeTrigger(1,0,2100,"Attack");
return 1; // return 1 if OK; 0 on failure