Jump to content
Sign in to follow this  
1para{god-father}

Advice on Spawn Function

Recommended Posts

I am using the below , which spawns OK but it only spawns 1 Group no matter how many Calls I use , can I not use it like that ?

If not how ?

Thanks

ini

god_Infspawn1 = compile (preprocessFileLineNumbers "scripts\spawninf1.sqf");

[] execVM "SpawnAI.sqf";

spawninf1.sqf

_marker = _this select 0;
while {SpawnEnemies} do {
_randomsquad=["OIA_InfSquad_Weapons","OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"]	call BIS_fnc_selectRandom;
_spos= [getmarkerpos _marker,random 360,[250,600],false,2] call SHK_pos;
_Grp1 = [_spos, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _randomsquad)] call BIS_fnc_spawnGroup;
      [(units _Grp1) select 0, _marker,"track","nowait","showmarker","noslow","delete:",120] execVM "scripts\ups.sqf";  
waitUntil {{alive _x} count (units _Grp1) == 0};       
};

SpawnAI.sqf

///Spawn 4 groups

["CAPBase1"] call god_Infspawn1;
sleep .5;
["CAPBase1"] call god_Infspawn1;
sleep .5;
["CAPBase2"] call god_Infspawn1;
sleep .5;
["CAPBase2"] call god_Infspawn1;

Share this post


Link to post
Share on other sites

As long a you have checked SpawnEnemies is still true, then maybe because you have called the script once and it is already running - stopped at the waituntil - but don't quote me on that.

try changing it to a function and enclose the _marker = select 0; within it.


Fnc_Spawn_Enemies = {
_marker = _this select 0;
while {SpawnEnemies} do 
{
_randomsquad=["OIA_InfSquad_Weapons","OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"]	call BIS_fnc_selectRandom;
_spos= [getmarkerpos _marker,random 360,[250,600],false,2] call SHK_pos;
_Grp1 = [_spos, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _randomsquad)] call BIS_fnc_spawnGroup;
      [(units _Grp1) select 0, _marker,"track","nowait","showmarker","noslow","delete:",120] execVM "scripts\ups.sqf";  
waitUntil {{alive _x} count (units _Grp1) == 0};       
};

};

["CAPBase1"] call Fnc_Spawn_Enemies;

Share this post


Link to post
Share on other sites

Thanks Mikie,

Still no Joy only get the first group ? i have left SpawnEnemies as true for now in my INI so not changing it at all

Any other ideas

As long a you have checked SpawnEnemies is still true, then maybe because you have called the script once and it is already running - stopped at the waituntil - but don't quote me on that.

try changing it to a function and enclose the _marker = select 0; within it.


Fnc_Spawn_Enemies = {
_marker = _this select 0;
while {SpawnEnemies} do 
{
_randomsquad=["OIA_InfSquad_Weapons","OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"]	call BIS_fnc_selectRandom;
_spos= [getmarkerpos _marker,random 360,[250,600],false,2] call SHK_pos;
_Grp1 = [_spos, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _randomsquad)] call BIS_fnc_spawnGroup;
      [(units _Grp1) select 0, _marker,"track","nowait","showmarker","noslow","delete:",120] execVM "scripts\ups.sqf";  
waitUntil {{alive _x} count (units _Grp1) == 0};       
};

};

["CAPBase1"] call Fnc_Spawn_Enemies;

Edited by psvialli

Share this post


Link to post
Share on other sites

maybe something like

_counter = 0;
_number = X;                  //Insert Number
while { _counter < _number} do {
_randomsquad=["OIA_InfSquad_Weapons","OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"]	call BIS_fnc_selectRandom;
_spos= [getmarkerpos _marker,random 360,[250,600],false,2] call SHK_pos;
_Grp1 = [_spos, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _randomsquad)] call BIS_fnc_spawnGroup;
      [(units _Grp1) select 0, _marker,"track","nowait","showmarker","noslow","delete:",120] execVM "scripts\ups.sqf";
_counter = _counter + 1;
};

btw do you want them to respawn once dead?

Share this post


Link to post
Share on other sites

you tried it without the waituntil? call it with a spawn and add a sleep just to check...

Share this post


Link to post
Share on other sites

Its because your using call for each group, you need to either spawn or exeVM so each one is a new thread.

It would be better if you called (all dependant on what else youve got happening/mission flow) the SpawnAI.sqf. SpawnAI.sqf then spawns seperate threads for each group and returns to Init todo what ever else.

At the moment a seperate thread is being made for SpawnAI this then calls ["CAPBase1"] call god_Infspawn1; which waits at the end untill the groups dead it never advances past this point so you never get another group.

init

setupGroups = compile (preprocessFileLineNumbers "scripts\SpawnAI.sqf");

SpawnEnemies = true;

[] call setupGroups;

SpawnAI

///Spawn 4 groups

//create 4 separate threads, one for each group
["CAPBase1"] execVM "scripts\spawninf1.sqf";
["CAPBase1"] execVM "scripts\spawninf1.sqf";
["CAPBase2"] execVM "scripts\spawninf1.sqf";
["CAPBase2"] execVM "scripts\spawninf1.sqf";

spawninf1 (for testing, without ups or SHK_pos)

_marker = _this select 0;
while {SpawnEnemies} do {
_randomsquad=["OIA_InfSquad_Weapons","OIA_InfSquad","OIA_InfSquad_Weapons","OIA_InfTeam","OIA_InfTeam_AT"]	call BIS_fnc_selectRandom;
//_spos= [getmarkerpos _marker,random 360,[250,600],false,2] call SHK_pos;
_Grp1 = [getmarkerpos _marker, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _randomsquad)] call BIS_fnc_spawnGroup;
      //[(units _Grp1) select 0, _marker,"track","nowait","showmarker","noslow","delete:",120] execVM "scripts\ups.sqf";  
waitUntil {{alive _x} count (units _Grp1) == 0};       
};

Share this post


Link to post
Share on other sites

From WIKI - I didnt even know that - cheers Larrow.

Functions executed using call are run within the executing instance, which waits for the result of the function. Unlike scripts, functions halt all other game engine processes until the function has completed its instructions. This means functions run faster than scripts, and the result of functions is immediate and unambiguous. It can also mean that if a function takes too long to run it will have an adverse effect on game play - large functions or CPU intensive functions can cause the game to seize up until it completes. When creating a functions you want the function to be short and sweet to achieve the best results.

Functions may also be executed using spawn, but then the function result is not accessible, making it behave more like a procedure. Spawned functions will run asynchronously or alongside the executing instance. This helps prevent large CPU intensive functions from seizing up the game.

Share this post


Link to post
Share on other sites

Ahhhh thanks will test it out !

Yahhhhhhh working apart from the UPS there seems to be an issue now with that , it seems that only 1-2 group work the rest just stand there and the track marker flashed from one to the other like they are the same group number ?

I have a 1 sec sleep between the spawn but still no joy

Any idea 's

Edited by psvialli
tested

Share this post


Link to post
Share on other sites

Works fine here, only thing ive changes in your script is

_spos= [getmarkerpos _marker,random 360,[0,360],false,[2,100]] call SHK_pos;

Option 3 you had set as 250,600. This is degrees of rotation from marker position, 250 -> 600 leaves you a 10 degree arc at roughly WSW not to spawn in? is this actually what you were going for?

Option 5 according to the readme is meant to hold an array of [option, distance]

  1. 0 = no road positions
  2. 1 = road position, random position if no roads found
  3. 2 = road position, empty array if no roads found

Using '2' in options is going to return an empty array if there are no roads found, which will cause you problems passing this to spawnGroup.

TEST MISSION if you need it

Edited by Larrow

Share this post


Link to post
Share on other sites

What about this

Script 1: spawn_start.sqf

if (!isserver) exitwith {};

InfGroup = creategroup east;
_soldierArray = ["O_Soldier_TL_F","O_Soldier_AR_F","O_Soldier_GL_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_F","O_Soldier_AR_F","O_Soldier_GL_F","O_Soldier_F","O_Soldier_AR_F","O_Soldier_GL_F","O_Soldier_AR_F","O_Soldier_GL_F","O_Soldier_F"];

_spawnPos = getMarkerPos "spawnstart";    // Variables and names can of course be changed
_targetpos = getMarkerPos "target";          // Variables and names can of course be changed

while {alive trg} do {             // You could use Public Variables etc for trg aswell, i just used a unit because it works, though Public Variables are better
//action 
_spawnVM = [_spawnPos,_soldierArray,"",0.2,_targetpos] execVM "spawn_Inf.sqf";
sleep 5;
waitUntil {(count units InfGroup) < 8};       // Changeable to your liking
sleep 15;
};

Script 2: Spawn_Inf.sqf

if (!isserver) exitwith {};

//[spawn,TypeList,Init,Skill,Dest] execVM "spawn_start.sqf";
_spawn = _this select 0;
_group = InfGroup;
_typeunits = _this select 1;
_init = _this select 2;
_skill = _this select 3;
_loc = _this select 4;


//Spawn Soldiers
_counter = 0;
_number = count _typeunits;
while { _counter < _number} do {
(_typeunits select _counter) createUnit[_spawn, _group, _init, _skill, "CORPORAL"];
_counter = _counter + 1;
};

sleep 1;


_wp = _group addWaypoint [_loc, 5];
_wp setWaypointSpeed "FULL";
_wp setWaypointFormation "DIAMOND";
_wp setWaypointType "SAD";                // You might want to use another type, or leave it out if you're using UPSMON

And before i forget, this is not completely made/written by me, i think it already exists somewhere in the forums. Or at least something similar.

hope it helps

Edited by mantls

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  

×