Home   Help Search Login Register  

Author Topic: Spawning an infinite number of groups with createunit  (Read 1435 times)

0 Members and 1 Guest are viewing this topic.

Offline RKurtzDmitriyev

  • Former Staff
  • ****
I'm trying to a write a script for a mission* that will spawn AI units, both enemy and friendly, out of sight of the player(s). To minimize CPU strain, this script must spawn new groups as old groups die. It should be able to spawn a theoretically infinite number of units, depending on how long the mission goes on. I thought that this wouldn't be so difficult, but I've run into a few stumbling blocks.

The problem stems mostly from the fact that createunit requires an existing group to work. Ways I have attempted to write this script:

(1) Spawn new units into groups that just died.
Problem: If not all units in the dead group were reported dead by members of its side, the engine may refuse to spawn a complete squad, because the number of units in a group cannot exceed 12.

(2) Spawn units into the group of a "dummy" hidden safely away, then make the dummy join grpNull.
Problem: It seems that you can only join grpNull so many units. When you make a units join grpNull, a new identity (such as Charlie Black) is given to it. Once all the group names from Alpha Black to Kilo Pink have been taken up, units refuse to join grpNull. Although it takes 77 groups created per side to exceed this limitation, the mission(s) I make using this script might well break this barrier. I'd like some assurance that that won't happen. So...

(3) Delete the dead bodies of groups that just died, then spawn new units into those groups. Now complete squads are guaranteed to spawn, because it seems that deleted units are "reported dead."
Problem: This will look cheesy if players can see it. I'm trying to make a mission that gives the player the feeling that he's in a huge battle, but without the computer strain that usually accompanies such missions. This mission shouldn't feel arcade-ish.

I can think of a few more avenues I might try, but I'd be curious to know if anyone has found a quick way to circumvent the limitations described above.

*a completely new one, not Village DePacification, though I'm working on that one too.
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
Re: Spawning an infinite number of groups with createunit
« Reply #1 on: 23 Feb 2010, 19:20:41 »
Unsure if this will work, but I'll try.

Code: [Select]
_player = getPos player

_alpha = [units alpha]
_bravo = [units bravo]
_charlie = [units charlie]
_delta = [units delta]

_alphac = 1
_bravoc = 1
_charliec = 1
_deltac = 1

#bigloop
loon1 join alpha
loon2 join bravo
loon3 join charlie
loon4 join delta

"SoldierWB" createUnit [getMarkerPos "alpha", alpha,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "alpha", alpha,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "alpha", alpha,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "alpha", alpha,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "alpha", alpha,"", 0.5, "PRIVATE"]

"SoldierWB" createUnit [getMarkerPos "bravo", bravo,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "bravo", bravo,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "bravo", bravo,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "bravo", bravo,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "bravo", bravo,"", 0.5, "PRIVATE"]

"SoldierWB" createUnit [getMarkerPos "charlie", charlie,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "charlie", charlie,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "charlie", charlie,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "charlie", charlie,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "charlie", charlie,"", 0.5, "PRIVATE"]

"SoldierWB" createUnit [getMarkerPos "delta", delta,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "delta", delta,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "delta", delta,"", 0.5, "PRIVATE"]
"SoldierWB" createUnit [getMarkerPos "delta", delta,"", 0.5, "PRIVATE"]
~0.5
loon1 join grpNull
loon2 join grpNull
loon3 join grpNull
loon4 join grpNull
~2
leader alpha doMove _player
leader bravo doMove _player
leader charlie doMove _player
leader delta doMove _player

#checker
~3
_alphac = count _alpha
_bravoc = count _bravo
_charliec = count _charlie
_deltac = count _delta
~3
? (_alphac == 0 && _bravoc == 0 && _charliec == 0 && _deltac == 0) : goto "bigloop"
~0.5
goto "checker"

To use it you have to have markers "alpha", "bravo", "charlie", "delta", then place a officer with "alpha = group this" and "this setDammage 1" in his init and place officer for each group with corresponding "bravo = group this", etc.

I hope that helped,
Krieg
« Last Edit: 23 Feb 2010, 19:29:08 by Krieg »
If you see a light at the end of the tunnel, then it's probably an enemy tank.

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Spawning an infinite number of groups with createunit
« Reply #2 on: 24 Feb 2010, 04:10:21 »
Heres a segment out of my patrol replacement script in the kolgujev contract. Any spawned unit(s) require an existing group. You can do as Kreig just stated and place a unit, identify his group name and then kill him off(I prefer deletion to just remove the dead body) Any unit then created in that group will follow the waypoints set out for the first deleted group or those kia.(If you have assigned them waypoints)

The below script will check the number of units in a group and then spawn additional units until the total listed number is met. In this case...3. If you require an entire group, simply up that number to 12. It also adds a killed eventhandler which runs a deletion script to remove the dead body. It setpositions each spawned unit to a marker called "patrolmarker". This as well as the group name can be changed to fit your needs of course.
Code: [Select]
#patrol1start
_alpha = {alive _x} count units patrol1
? _alpha == 3 : goto "patrol2start"
#create1
_NUMBERS = 20
_NUMB = Random _NUMBERS
?(_numb < 1)  : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 1)  and (_numb <= 2) ) : "soldierElaw" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 2)  and (_numb <= 3) ) : "soldierEMG" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 3)  and (_numb <= 4) ) : "soldierEG" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 4)  and (_numb <= 5) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 5)  and (_numb <= 6) ) : "soldierEMedic" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 6)  and (_numb <= 7) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 7)  and (_numb <= 8) ) : "soldierESniper" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 8)  and (_numb <= 9) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 9)  and (_numb <= 10) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 10) and (_numb <= 11) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 11) and (_numb <= 12) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 12) and (_numb <= 13) ) : "soldierESniper" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 13) and (_numb <= 14) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 14) and (_numb <= 15) ) : "soldierElaw" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 15) and (_numb <= 16) ) : "soldierEMG" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 16) and (_numb <= 17) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 17) and (_numb <= 18) ) : "soldierEG" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
?( (_numb > 18) and (_numb <= 19) ) : "soldierEMedic" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "corporal"]
?( (_numb > 19) and (_numb <= 20) ) : "soldierE" createUnit [getMarkerPos "PatrolMarker", patrol1,"this AddEventHandler [{Killed},{_this exec {scripts\deletehandler.sqs}}]", 1, "private"]
~.01
goto "patrol1start"

The coed box autoreturned the code above, splitting the lines into two. If you use it, make sure all the code appears behind each question mark.

You will not have to order the units back into formation since the leader will do this automatically. And they will automatically know the information that any of the other group members have reported such as enemy position, until the information expires of course.

Below is the code for the deletehandler script called from the killed eventhandler. It has a 10 second loop and a distance check. Both of which can obviously be tweaked to your needs.
Code: [Select]
_unit = _this select 0
_unit removealleventhandlers "killed"

#loop
?(player distance _unit >= 400): deletevehicle _unit; exit
~10
goto "loop"

Hope it helps.

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: Spawning an infinite number of groups with createunit
« Reply #3 on: 24 Feb 2010, 13:24:45 »
Thanks guys, I will have to look into this. :)
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)