Author Topic: Repeating Units?  (Read 2532 times)

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Repeating Units?
« on: February 20, 2006, 11:23:48 AM »
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


Code: [Select]
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();
}

Code: [Select]

int InitProc()
{
int i;

CreateTimeTrigger(1,1,2000,3000,"CreateTanks");
  CreateTimeTrigger(1,1,4000,"Attack");

return 1; // return 1 if OK; 0 on failure
}
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Repeating Units?
« Reply #1 on: February 20, 2006, 12:09:58 PM »
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:

Code: [Select]
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
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Repeating Units?
« Reply #2 on: February 20, 2006, 12:39:35 PM »
well I will give it a try and I will see if I run into anymore problems.

and it looks like if I want to keep from having a de-synchronising problem with the time between entering the map and attacking, all I need to do is to change the first part of the code so its not random anymore. Which is not that big of a deal to me.

And setting it so that the units coming in will never cease even when passing the magic number of 127 by following what you have said and deleting the group after they are dead.  Might make it more unstable right?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Repeating Units?
« Reply #3 on: February 20, 2006, 01:26:39 PM »
Let me tell you this: i have found some unaxplainable bugs in mission 3 of renegades.. first it took me a couple of WEEKS to figure out i was going over the 127 ScStubs.. and i didn't have any repeating stuff like that. I just had a LOT of groups and Triggers going. That's when i started the Events project (see wiki pages).

Othe then that.. outpost has problems with groups: when u want to remove a single unit from a group u'd use: grp1.RemoveUnit(u).. BUT if the unit wasn't IN the group in the first place, op2 crashes.. just to name 1 of those op2-bugs.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Repeating Units?
« Reply #4 on: February 20, 2006, 01:48:21 PM »
hmm okay I will keep that in mind.


I might have a question for you about this type of stuff in a few minutes depending on if the way I've got it works
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Repeating Units?
« Reply #5 on: February 20, 2006, 02:04:12 PM »
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

Code: [Select]

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();
}




Code: [Select]

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
« Last Edit: February 20, 2006, 02:05:25 PM by spirit1flyer »
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Repeating Units?
« Reply #6 on: February 20, 2006, 02:43:23 PM »
You're not deleting the group. in the long run, this will be your saviour.
Not deleting the group will crash op2 after about 2706~11070 timemarks (give or take a 1), coz thats when you end up with stub #127. This is assuming you have no other triggers or groups.

If you DO put in that SetDeleteWhenEmpty(1), the game will even crash sooner, because the trigger that sets the fightgroup to attack-mode is run from outside the other trigger. They should be linked from within as i have explained: the one calls the other.
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Repeating Units?
« Reply #7 on: February 20, 2006, 02:58:47 PM »
so if I link them from within as you say, it should not stop running?

and do you want to beta test it?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter