OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Trexian on 10 Jan 2009, 05:58:52

Title: Placing units during loading
Post by: Trexian on 10 Jan 2009, 05:58:52
I did some quick searches but didn't find anything, so apologies if I should have searched harder. :)

I have a kind of mission that starts out setting a bunch of groups dynamically.  I have it set up to start placing in the init.sqf.  Alas, the mission starts, and it spends the next 3-5 minutes placing all these groups. :(  Is there some way to more front-load it so it runs during the loading screens - like manually placed units do?

TIA.
T
Title: Re: Placing units during loading
Post by: Tyger on 10 Jan 2009, 06:08:04
How are you creating the groups? Can you post some code?
Title: Re: Placing units during loading
Post by: Trexian on 10 Jan 2009, 16:18:13
Sure.

Perhaps I should also mention that I'm running this in one script, where it loops through this each time it creates a group.  I was going to split this into a different script, and have it called basically each time through the loop, thinking that might be faster.  Anyway, the codi-ness...

Code: [Select]
_grpSpawn = createGroup _troopSide;
sleep .1;
_groupSize = (floor (random 4)) + 3;

for [{_g = 1}, {_g <= _count}, {_g = _g + 1}] do
{
switch (_g) do
{
case 1:
{
_rndTroop = floor (random _aCount);
_troopSel = _tempSide select _rndTroop;
_aiSpawn1 = _grpSpawn createUnit [_troopSel, _posSpawn, [], 5, "NONE"];
_grpSpawn selectLeader _aiSpawn1;
_aiSpawn1 setRank "LIEUTENANT";
_aiSpawn1 setSkill .7;
};

case 2:
{
_rndTroop = floor (random _aCount);
_troopSel = _tempSide select _rndTroop;
_aiSpawn2 = _grpSpawn createUnit [_troopSel, _posSpawn, [], 5, "NONE"];
_rand = ceil (random 3);
_aiSpawn2 setRank (JTD_RelStr_Ranks select _rand);
_aiSpawn2 setSkill ((random 1) / 2);
};
 .
 .
 .
*and so on, with the same body of case 2 being used, except for incrementing _aiSpawn#

Basically, I have an array (_tempSide) that has the names of the potential members of the group and _trooSel selects from the array that member.

If there's a better way, I'm open to it!  :clap:

Edit:
HOLY carp.  One of those things where you don't see the problem until you post it.  :doh:  See that loop for groupsize using _count?  Welllll... that's a whole different freaking "count."  A much bigger one than the groupsize.  And, I didn't have a hint to tell me that I'd surpassed the number of cases.  That's what it was struggling with.

I guess I am still curious, though. :)
Title: Re: Placing units during loading
Post by: Tyger on 10 Jan 2009, 20:13:03
Well, if the "count" was greater than the group size, the loop would have been running extraneously for much longer, causing delays. Depending on how much larger the "count" was, it could be as long as you saw. Have you run the script with the appropriate group size? Was the time better?
Title: Re: Placing units during loading
Post by: Trexian on 10 Jan 2009, 20:27:00
Oh yeah - MUCH better.  Acceptably better, even. :)

But, for future reference, is there any way to do stuff script-wise as the game is loading?  Or does it need an intro cut scene or something?
Title: Re: Placing units during loading
Post by: Tyger on 10 Jan 2009, 20:35:07
When you want something to be executed before the mission starts, execute it in the init.sqf. The init.sqf technically executes before the mission briefing. So in this case, in your init.sqf use:
Code: [Select]
[myparams] spawn compile preprocessfile "myscript.sqf";

Title: Re: Placing units during loading
Post by: Trexian on 10 Jan 2009, 21:19:06
Ah... interesting.

I have an initialization script to get stuff ready for later scripts that kinda branch off of it, and I trigger that from the init.  But, to be more effective, I should "layer" them, I guess, so each of them is set off from the init?
Title: Re: Placing units during loading
Post by: Tyger on 10 Jan 2009, 21:36:26
I think, if I read it correctly, then yes, that's what I would do. Any variable and script initialization - basically anything you're trying to "set up" for later, I would run from the init.sqf. For instance, in my typical init.sqf, I have a section for initializing variables, calling scripts for dynamic content, core scripts that run the entire mission, etcetera.

On of the biggest reasons for using the init.sqf is to make sure that all of your variables and such for later on exist. If they are not initialized before a script runs, the effects can be hard to trace back to the problem.

By putting all of that stuff in the init.sqf, you don't need to execute/define a lot of stuff in game because the init.sqf is automatically executed by ArmA.

Hope that helps.
Title: Re: Placing units during loading
Post by: Trexian on 10 Jan 2009, 21:53:11
Perfect, actually.   :clap:  :good:
Title: Re: Placing units during loading
Post by: Tyger on 11 Jan 2009, 06:05:14
Glad to help! :)