Jump to content
Sign in to follow this  
wenker

trigger for spawning

Recommended Posts

what is the script/ cmd line that i use to make a unit spawn once i get to the trigger?

Share this post


Link to post
Share on other sites

There's complications though.

Namely the fact that in order to spawn, they have to spawn to a preexisting group. The way around this is _spawnedUnit join grpNull which creates a new group. This is even further complicated by the fact that the created unit isn't returned when you createunit, meaning you have to figure out which one he is the hard way.

I recently wrote a script to spawn units for a mission for Special Ed. Feel free to look at this and either modify it to make it do what you want, or just to use as a general guideline. Hell, I don't care, even plagerise it in it's entirety. I wrote the damn things for the community, not for the women and fame.

The script is included in the reference variable powered unit reduction demonstration mission I posted a coulple of days ago. Look at the script entitled spawnGarrison.sqs.

Feel free to ask any questions you have as they come up.

Share this post


Link to post
Share on other sites
This is even further complicated by the fact that the created unit isn't returned when you createunit, meaning you have to figure out which one he is the hard way.

I think it is not a very hard way to get a variable pointing at the spawned unit by initializing a global variable in the init string of the createUnit function... it is no more complicated than if the function returned the unit.

You do either this when you only want to access the vehicle from the same scope only (a script for example):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_bemu = "BMP" createVehicle getmarkerpos "BDO_ruskibase"

or this when you want to access the vehicle from the global scope:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">BDO_bemu = "BMP" createVehicle getmarkerpos "BDO_ruskibase"

or this when creating units (now we must use a global variable):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"SoldierECrew" createUnit [getMarkerPos "BDO_ruskibase", BDO_geoutrobmp, "BDO_bmpdriver = this;removeallweapons this", 1, "sergeant"]

In the last example we get global access to the created unit via the BDO_bmpdriver variable.

Share this post


Link to post
Share on other sites
This is even further complicated by the fact that the created unit isn't returned when you createunit, meaning you have to figure out which one he is the hard way.

I think it is not a very hard way to get a variable pointing at the spawned unit by initializing a global variable in the init string of the createUnit function... it is no more complicated than if the function returned the unit.

You do either this when you only want to access the vehicle from the same scope only (a script for example):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_bemu = "BMP" createVehicle getmarkerpos "BDO_ruskibase"

or this when you want to access the vehicle from the global scope:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">BDO_bemu = "BMP" createVehicle getmarkerpos "BDO_ruskibase"

Only works with Vehicles, not with people.

or this when creating units (now we must use a global variable):

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"SoldierECrew" createUnit [getMarkerPos "BDO_ruskibase", BDO_geoutrobmp, "BDO_bmpdriver = this;removeallweapons this", 1, "sergeant"]

In the last example we get global access to the created unit via the BDO_bmpdriver variable.

But using global variable in itself is bad when it can be avoided.

Namely the fact that if you want multiple instances of the script to run at once, it can mess up the scripts if you don't make a new version for each instance.

The only moderatly safe way of doing that is to assign it to a global variable in it's init field, then before doing *anything else*, grab the unit in that variable and reassign it to something local. Basically, only using the global as a temporary holding cell.

You could also mess around with using a reference variable. I haven't tried this yet though so I don't have a full understanding of any complications involved.

Frankly, yes vehicles are easy to deal with. Units are not if you want your script to be well rounded.

The best ways I've found so far involve passing a dummy placeholder unit's group to the createunit command, then cycling through that group the figure out which unit is the new one. Grabbing him and placeing him in the local var, then reassigning him.

God only knows why this shit can't be avoided simply by doing this though:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_myVar = _unitTypeString createUnit [_spawnPos, _spawnGroup, _initString, _skill, _rankString]

Well, that's a suggestion based on current bis code, it would actually have to look like this if they implemented it:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_myVar = createUnit [_unitTypeString, _spawnPos, _spawnGroup, _initString, _skill, _rankString]

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  

×