Jump to content

Sign in to follow this  
Bagel

Creating a new group with createunit

Recommended Posts

Having read all the posts on this subject, I cannot find a definitive answer. My question is simple, how do I create a unit without having a group already in existence.

I am working on a dynamic vietnam campaign and want to create new groups of VC when certain conditions are met. right now I can only createunit when I have an existing unit on the map already, then createunit joins the existing group.

I have tried using the init field in createunit with no success, any definitive answer with actual code sample would be appreciated, not just conceptual guessing as I have seemed to find in my searching.

Thanks

Share this post


Link to post
Share on other sites

Many have reported to use the grpnull for the group. I have never tried this myself, instead I use a soldier on the map and do the 'ole mygroup = group this and I have the units I create join this group. This way you can give the leader some of the more intelligent waypoints such as Guard and Hold or SAD.

I haven't been able to figure out how to give a unit one of these more intelligent waypoints through script without writing some lengthy routine.

Hoz

Share this post


Link to post
Share on other sites

Here's a trick someone mentioned to me. I'll do the honors of formalizing it and making it supereasy:

In the mission editor, place in an out-of-the-way location a unit on the map (like a VC soldier). Select him, hit control-c, and control-v to paste.

Paste as many units as virtual groups you want to reserve for createunit.

Now create a trigger big enough to cover those. Make it:

East (or whatever) Present Once

Time to activation: make it 2 seconds or so across the boards just to make sure it fills up so:

Min: 2 Max: 2 Avg: 2

On Activation:

EmptyGroupListEast = []; {EmptyGroupListEast = EmptyGroupListEast + (Group _x); deletevehicle _x} ForEach ThisList; EmptyGroupIndex = 0

Now when you create unit, use EmptyGroupListEast select EmptyGroupIndex for the group name. Then increment EmptyGroupIndex, and you're done.

Share this post


Link to post
Share on other sites

Thanks guys , after an hour or so , the best solution I got to work was creating one soldier with Alpha = group this in the init.

I then add a soldier to the group with

"soldierWB" createunit [pos,alpha,"me=this"]

I then remove soldier from group with:

[me] join grpnull

I then create the next couple of units with

"soldierWB" createunit [pos,group me]

I then have a new group ready to deploy.

Thanks for all the help!

Share this post


Link to post
Share on other sites

I mentioned this somewhere else a while ago, but its worth saying again.

If you make your guy with the group name in his init, put a "deletevehicle this" in his init as well. Then you have an empty group (and no unit on map at mission start / load), and if you assign waypoints to that one guy, new units spawned into that group will follow those waypoints.

Share this post


Link to post
Share on other sites

Im sorry, but for those that claim using grpNull to split one group into more just does not seem to work. I have tested this over and over in many different ways. It does not work.

Here is one of the many ways i tried which is similar to what ppl in the forum have claimed:

Create a soldier with this in the init:

init=ePilots = group(this);deletevehicle this

this will create a virtualy empty group for use

Use the group to create your units:

[gLogic, ePilots]script.sqs

============================================

_glchpprspwn = _this select 0

_grp = _this select 1

"SoldierE" createUnit [getpos _glchpprspwn, _grp, "eMan1 = this", 1, "PRIVATE"]

"OfficerE" createunit [getpos _glchpprspwn, _grp, "eMan2 = this", 1, "LIEUTENANT"]

"SoldierE" createUnit [getpos _glchpprspwn, _grp, "eMan3 = this", 1, "LIEUTENANT"]

;;Supposedly this will release him from previous group

[eMan3] join grpNull

;;Then use the new guy to create new a group

_paragrp = group eMan3

"SoldierEG" createunit [getpos _glchpprspwn, _paragrp, "eMan4 = this", 1, "PRIVATE"]

"SoldierEMG" createUnit [getpos _glchpprspwn, _paragrp, "eMan5 = this", 1, "PRIVATE"]

"SoldierELAW" createunit [getpos _glchpprspwn, _paragrp, "eMan6 = this", 1, "PRIVATE"]

"SoldierEAA" createUnit [getpos _glchpprspwn, _paragrp, "eMan7 = this", 1, "PRIVATE"]

"SoldierEG" createunit [getpos _glchpprspwn, _paragrp, "eMan8 = this", 1, "PRIVATE"]

=============================================

Maybe this has something to do with MP in 1.75 and up, but it does not work! When I tell the _paragrp to move or eject from a chopper, everybody jumps or moves including the previous group. I wish Bohemia would just create a new script command that lets you create units without having to group. This is annoying. Although I have found a workaround, it still requires work outside the script and limits your ability to create fully plugable scripts.

This is really the only way i have found to create empty groups. Just create a soldier with this in the init:

init=GroupName1 = group(this);deletevehicle this

if you need another group, just create another soldier with the same init and different group name:

init=GroupName2 = group(this);deletevehicle this

Then, pass the groups into your script to create soldiers in seperate groups using 'createunit'.

Here is a sample script using the groups. Just exec it in the init of an object on the map. I used GameLogic.

glSpawn is GameLogic placed on the map

[glSpawn, GroupName1, GroupName2]CreateTwoGroups.sqs

==================================

_glchpprspwn = _this select 0

_pilotgrp = _this select 1

_paragrp = _this select 2

;;be sure groups are created

~5

"SoldierE" createUnit [getpos _glchpprspwn, _pilotgrp, "eMan1 = this", 1, "PRIVATE"]

"SoldierE" createUnit [getpos _glchpprspwn, _paragrp, "eMan5 = this", 1, "PRIVATE"]

===================================

Notice the init line for createUnit. You can still access individual soldiers using a global reference, eManX, and setting the object equal to it.

Anyways, if anybody finds a better way Im all ears. Until then I just dont think it will be possible to create a unit without having a group in existence. I hope this answers your question Begal. I feel your pain. I see alot of copy and paste in the forums and ppl quoting others. Its hard to find good sample code that works. I am sure you have tried this place http://www.ofpec.com. I have found some good references there. Goodluck!

Share this post


Link to post
Share on other sites

Something that I find endlessly amazing:

You can use gamelogic as a groupleader, but you can camcreate the gamelogic.

I stumbled on this by mistake, and I can't believe no one else has discovered this.

I think you can also use createvehicle for a gamelogic...

Here's what I'm struggling with (and I'm having a ew problems)

I'm working on a dynamic unit making system so that the first unit created is unit1, the second is named unit2, using the call command and format.. It seems to be working, and it works fine with vehicles... I'll post my script in another thread.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×