drunkenjawa 11 Posted July 12, 2014 Hey guys I've been getting into the spawning side of scripting recently and noticed that there seem to be two main ways of spawning groups. One using a lot of 'createUnit' commands e.g.: _mygroup = Creategroup EAST; "O_Soldier_F" createUnit [getMarkerPos "spawn1",_mygroup,"this allowFleeing 0",random 1, "Private"]; "O_Soldier_F" createUnit [getMarkerPos "spawn1",_mygroup,"this allowFleeing 0",random 1, "Private"]; (This isn't my script, just using it as an example, as I'm at work and don't have access to my home computer). The "this allowFleeing 0" option in that script, as I understand it, is setting that units init. Basically I want to just use this part, to spawn a beanie and uniform on the soldier and that's about it, I'd like it to be applied to the whole group spawning. The other way that I can see, is by using the BIS_fnc_spawnGroup command, e.g.: _mygroup = [getmarkerpos "spawn1", EAST, ["O_Soldier_F", "O_Soldier_F"],[],[],[],[],[],180] call BIS_fnc_spawnGroup; (Again, not my script, it's more the formatting that's important for my question as opposed to the content) However I can't seem to find that any of these arguments used in the BIS_fnc_spawnGroup command, are actually for setting the init of the unit like with the createUnit command? Or was I wrong? What I'm attempting to do is put some ambient combat in my mission, where a small group of soldiers spawns, moves up to their waypoint (which I'll also need to learn how to do later hehe but there seem to be a lot of tutorials on that) and subsequently get slaughtered by the invincible AI that I have guarding the base. Then, they spawn in again after a few minutes and the same thing happens. Just to simulate the base being a real hotspot if anything else, but the key thing here is that they're wearing specific outfits, e.g. the uniform and hat. Would BIS_fnc_spawnGroup still be capable of that, or would I individually need to write each one out as in the 'createUnit' example to get this done? Either way I don't really mind, but the BIS_fnc_spawnGroup comand seems to be more efficient at least so if I could use that, that would be awesome. Share this post Link to post Share on other sites
Grumpy Old Man 3551 Posted July 12, 2014 BIS_fnc_spawnGroup is a horrible way to spawn groups if you care about performance. If you only plan to spawn a few groups it should be ok I guess, if there's constant spawning going on you might wanna refer to createUnit and add a performance sleep between each spawned unit. With this awesome performance sleep you can dynamically adjust the sleep to your fps, so in a best case you won't even be able to tell that the game is currently doing something. Which can be a good thing, everyone knows there's something happening when the fps are dropping all of a sudden. ;) As to your custom layout you could make a small .sqf file where you remove the headgear, uniform, and add your custom outfit. Just execute it on the entire group and you're set. 1 Share this post Link to post Share on other sites
wiggum2 31 Posted July 12, 2014 BIS_fnc_spawnGroup is most useful if you spawn already defined groups, like: _name = ["OIA_InfSquad","OIA_InfSentry","OIA_InfSentry","OIA_InfTeam","OIA_InfTeam"] call BIS_fnc_selectRandom; sleep 0.1; _grp = createGroup east; _grp = [_spawnPos, east, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> _name)] call BIS_fnc_spawnGroup; Share this post Link to post Share on other sites
SilentSpike 84 Posted July 12, 2014 With this awesome performance sleep you can dynamically adjust the sleep to your fps, so in a best case you won't even be able to tell that the game is currently doing something. Which can be a good thing, everyone knows there's something happening when the fps are dropping all of a sudden. ;) What do you mean by this exactly? Just a "sleep 1" between each spawn? It sounds relevant to something I'm currently working on. Share this post Link to post Share on other sites
Grumpy Old Man 3551 Posted July 12, 2014 What do you mean by this exactly? Just a "sleep 1" between each spawn? It sounds relevant to something I'm currently working on. By my old, dried out eyes, I totally forgot to add the link! 1 Share this post Link to post Share on other sites
drunkenjawa 11 Posted July 12, 2014 everyone knows there's something happening when the fps are dropping all of a sudden. ;) hah, too true - excellent point, and thanks for pointing out the sleep thing - that will come in handy I'm sure :D These will be pretty small groups at first, just till I get the hang of how much spawning it can take, till it starts to be noticeable something's happening. Might just try both anyway in a trial and error type fashion, once I get an hour or so to try :) Wiggum - thanks, that will definitely come in handy for later missions I think, where I don't need to strip the gear and replace it with other gear, and just able to use the pre defined groups. Share this post Link to post Share on other sites
SilentSpike 84 Posted July 12, 2014 By my old, dried out eyes, I totally forgot to add the link! Awesome link :) Not entirely sure I'm using it right though. Do you have an example? I can only assume FPSLIMIT is suppose to be the lower limit where you want the maximum delay to take effect. However if I plug in some numbers and calculate I'm getting a value nowhere near the max delay :P Share this post Link to post Share on other sites
Grumpy Old Man 3551 Posted July 12, 2014 Awesome link :)Not entirely sure I'm using it right though. Do you have an example? I can only assume FPSLIMIT is suppose to be the lower limit where you want the maximum delay to take effect. However if I plug in some numbers and calculate I'm getting a value nowhere near the max delay :P FPSMAX = should be the average fps you get when playing (best case: 60) FPSMIN = when fps is reaching this value the maxdelay will be the number you entered at maxdelay example: _AdditionalUnitCreationDelay = ((abs(50 - diag_fps) / (50 - 10))^2) * 1.337; sleep(_AdditionalUnitCreationDelay); my maxfps in editor is usually somewhere around 60, just to be sure I set it to 50 in the script. I don't want my fps to drop more than 10 frames when spawning units, so I set the FPSlimit to 10. Now when the fps drops down to 40 the maxdelay will be 1.337 seconds. When fps is at 50 the maxdelay will be 0. At least that's what I think it does. Cheers Share this post Link to post Share on other sites
SilentSpike 84 Posted July 12, 2014 (edited) Ah, that makes a bit more sense to me now. However the maxdelay value seems to be more of just a scale value to me. Using the example you gave if you had 40 fps you'd get a delay of 0.0835625 rather than 1.337. To get a delay of 1.337 you'd need to have 10 fps (I just calculated backwards and I guess answered my own question - looks like the limit does mean the lower limit) Edit: I am curious as to why abs is used, as that'd surely cause delay when the fps is above the upper limit set. Wonder how sleep handles negative values, if it doesn't freak out it'd probably be more effective to remove the abs. ---------- Post added at 14:41 ---------- Previous post was at 14:23 ---------- Seems like sleep handles negative values happily, just treats them like a 0. So it's actually better to remove the abs command unless there's a reason for it which I'm not seeing. Edited July 12, 2014 by SilentSpike Share this post Link to post Share on other sites
drunkenjawa 11 Posted July 12, 2014 Would the sleep command be of much use if I'm only spawning say, 10 units at a time, in a SP scenario? Or would that amount of units not make much difference? I guess it just comes down to the client computer specs in the case of a SP mission? Share this post Link to post Share on other sites
SilentSpike 84 Posted July 13, 2014 It could be useful. I've noticed pauses caused by spawning groups of 12 in one of my missions. Plus if the FPS is good then there won't be any delay anyway. Here's my current use of it: _additionalUnitCreationDelay = (((50 - diag_fps) / 20)^2) * 2; sleep(_additionalUnitCreationDelay); Anything above 50 will cause a delay of 0s. If you drop down to 30 you'll get a delay of 2s. 40 results in 0.5s. Share this post Link to post Share on other sites
drunkenjawa 11 Posted July 13, 2014 Yeah, it'd be better learning to do it this way first, I think, rather than having to come back to re-learn :) I will give it a go, thanks for your help! Share this post Link to post Share on other sites
drunkenjawa 11 Posted July 15, 2014 I have the spawning in pretty sussed now, however the units that I'm spawning in (CAF Agressors) have lost the sound on their weapons due to the bootcamp update. No biggy, I thought - I will just make it so they spawn with some fixed AK's from the @mas pack which has been updated. This is the code that I'm using to spawn the group: hint "creating 2nd group"; group2 = Creategroup EAST; "CAF_AG_me_t_AK74" createUnit [getMarkerPos "spawn2",group2,"this allowFleeing 0; this addWeapon {arifle_mas_ak_74m};",random 1, "Private"]; "CAF_AG_me_t_RPK74" createUnit [getMarkerPos "spawn2",group2,"this allowFleeing 0; this addWeapon 'LMG_mas_pkm_F'",random 1, "Private"]; "CAF_AG_me_t_AK74" createUnit [getMarkerPos "spawn2",group2,"this allowFleeing 0; this addWeapon {arifle_mas_fal}",random 1, "Private"]; "CAF_AG_me_t_AK47" createUnit [getMarkerPos "spawn2",group2,"this allowFleeing 0; removeAllWeapons this; this addWeapon {arifle_mas_fal}",random 1, "Private"]; "CAF_AG_me_t_PKM" createUnit [getMarkerPos "spawn2",group2,"this allowFleeing 0; this addWeapon 'LMG_mas_pkm_F'",random 1, "Private"]; As per the guide on createUnit here: https://community.bistudio.com/wiki/createUnit It says that I should be adding the weapons in {} which is fine. The units spawn ok, and proceed to follw their waypoints, they just don't have the new weapons, still stuck with the old ones. This also happens when I try and assign them new uniforms etc in the init section. It's like it's just ignored completely the init part and just spawns them as standard anyway. You can see the different variations of this that I've tried above, none work to give the npc a new weapon. Everything else does, like the random skill level (I assume), the group it's put into, the spawn marker it spawns at, etc. Any ideas what I'm doing wrong? Share this post Link to post Share on other sites
SilentSpike 84 Posted July 15, 2014 Try replacing the {} with apostrophes ' instead. Generally whenever there is code denoted by quotations rather than {} you need to replace any quotation marks in that code with either double quotations ""like so"" or apostrophes 'like so'. That said, I've always used this format of createUnit. Since it returns the unit object you can assign it to a variable and just perform actions with it from there. Share this post Link to post Share on other sites
drunkenjawa 11 Posted July 15, 2014 Thanks, turns out I was editing the previous versions script instead of the current version that I was working on, lol, hence why no changes were being seen. All sorted, the apostrophes worked fine (and was what I was originally using). Thanks for pointing out that other way though, will look into that once I finish banging my head against this wall :P Share this post Link to post Share on other sites