[aps]gnat 28 Posted February 15, 2005 Theres a little info in the forum on this, but not enough for me to fill in the gaps. As many of you may know, creating a new group without an existing soldier is problematic. Where I'm caught is this is Addon scripting .... makes it worse ..... but I'll settle for something that works in normals scripts anyway ! The problem: I have a group that starts with a initialised addon (ie commander, driver, gunner), I want to create an extra guy and join him to the group ..... sounds simple ? No ... because theres a problem, the AI commander issues the new guy with weird orders straight away that stuffs up the new guys roll !!!grrrrrrr So the way to avoid this seems assign him to his own group, place him as a gunner in another unit, settle him, then JOIN him to the commanders group. CREATEUNIT a guy to a totally non-initialised Group seems impossible (nice one BIS ) so the next best thing is maybe start him on the main group, break him off, move and assign him his role, them join him back to the main group ........ *sigh* Another way is do the above for 1 guy, createunit another guy to join his new group, then delete the first guy .... *double sigh* So to that ends ..... why wont this code work? Specificly the dynamic naming of the man for starters; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_TankCommander = commander _tank _group = group _TankCommander _r = random 1000 _r = _r - _r % 1 _tmpname = call format ["man%1",_r] "SoldierWSaboteur" createunit [getpos myM113,_group, format ["%1 = this", _tmpname], 0.7, "PRIVATE"] ~0.1 [_tmpname] join grpNull; _newGroup = group _tmpname; "SoldierWSaboteur" createunit [getpos myMX113, _newGroup,"", 0.7, "PRIVATE"] deletevehicle _tmpname _newGunner = (Units _newGroup) Select (Count Units _newGroup - 1) _newGunner assignasgunner myM113 _newGunner MoveInGunner myM113 [_newGunner] join _group The error on the first Creatunit is; Error Type Any, expected String (cant read rest, if any) Long winded I know, but its kickin my horse-mule cross breed. Share this post Link to post Share on other sites
raedor 8 Posted February 15, 2005 it's because of this line i think.<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_tmpname = call format ["man%1",_r] try this:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"SoldierWSaboteur" createunit [getpos myM113,_group, call format ["man%1 = this", _r], 0.7, "PRIVATE"]; call format ["_tmpname = man%1", _r] and if that does not work you have to call the whole line...<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call format [{"SoldierWSaboteur" createunit [getpos myM113,_group, "man%1 = this", 0.7, "PRIVATE"]; _tmpname = man%1}, _r] not tested, though. Share this post Link to post Share on other sites
[aps]gnat 28 Posted February 15, 2005 cool raedor, that last one worked .... but now this bit doesnt work so hence the second createunit doesnt fire; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> [_tmpname] join grpNull; _newGroup = group _tmpname; seems the "_newGroup" is not valid, no error, just the creatunit does actual create anything. (and yes, the error "myMX113" is just a post error) Share this post Link to post Share on other sites
raedor 8 Posted February 15, 2005 what do you get with<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_newGroup = group _tmpname; hint format ["%1", _newGroup] or does it work after you corrected the MX113? Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 15, 2005 I dont think Raedors new code line works: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call format [{"SoldierWSaboteur" createunit [getpos myM113,_group, "man%1 = this", 0.7, "PRIVATE"]; _tmpname = man%1}, _r] I had issues with several brackets in a call format parameter. How about this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">"SoldierWSaboteur" createunit [getpos myM113,_group, "", 0.7, "PRIVATE"] ~0.1 _tmpsoldier = (units _group) select ((count units _group) - 1); call format["%1 = %2",_tmpname,_tmpsoldier]; [_tmpname] join grpNull; _newGroup = group _tmpname; Not tested, hope this helps. Share this post Link to post Share on other sites
[aps]gnat 28 Posted February 15, 2005 ( said: )rStrangelove @ Feb. 16 2005,01:37)]I dont think Raedors new code line works: Your right Dr Strangelove, in my haste I saw that a man was being spawned, not neglected to notice he didnt belong to any group. As for your code I get an error on the; <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call format["%1 = %2",_tmpname,_tmpsoldier]; bit. Something about Scalar blah blah = Alpha Black:5 Unknown operator bool 5 is relevant, cuz he would be the 5th soldier of my group. hmmmm ..... Share this post Link to post Share on other sites
[aps]gnat 28 Posted February 16, 2005 duh (delete stupid lack of sleep bit)...... Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 16, 2005 ([APS said: Gnat @ Feb. 15 2005,23:56)]As for your code I get an error on the;<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call format["%1 = %2",_tmpname,_tmpsoldier]; bit. Something about Scalar blah blah = Alpha Black:5 Â Unknown operator bool 5 is relevant, cuz he would be the 5th soldier of my group. Scalar means the variable _tmpname is not initialized and has no value at all. I thought _tmpname is: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_r = random 1000 _r = _r - _r % 1 _tmpname = call format ["man%1",_r] Well, it seems it's not "man5". Check this with this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">hint format["Tmpname: %1 _r = %2",_tmpname,_r] If you get "Tmpname: scalar bla.. _r = 5 (whatever)" replace the call format line with this: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">call format ["_tmpname = man%1",_r] Share this post Link to post Share on other sites
[aps]gnat 28 Posted February 16, 2005 Well ........ some success .... sort of ! Â BTW raedon ......... that Call Format is a VERY usefull function ! Â thx I can now create NEW groups off an existing group, but I have found the root cause of my problem. When joining a new "createunit" soldiers to a Commander who is sitting in a vehicle WITH SPARE CARGO SLOTS, that %$#%$# Commander WILL NOT let the new soldier be assigned to another vehicle !!!! Â So ........... more research, on a new topic ! Anyhow .... heres the sample code for creating a new soldier to a new non-pre-existing group. Here only for info because as-is its not that useful, just a sum of lessons learnt. Note: the new group identifer name "newGroup" MUST be global to work (for some reason), local variables dont allow the "Createunit" to function. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _TankCommander = commander _tank _group = group _TankCommander _r = random 1000 _r = _r - _r % 1 call format [{"SoldierWSaboteur" createunit [getpos myM113,_group, "man%1 = this", 0.7, "PRIVATE"]}, _r] call format [{[man%1] join grpnull}, _r] call format [{newGroup = group man%1}, _r] "SoldierWSaboteur" createunit [getpos myM113, newGroup,"", 0.7, "PRIVATE"] ~0.1 call format [{deletevehicle man%1}, _r] ~1 _newGunner = (Units newGroup) Select (Count Units newGroup - 1) ~1 [_newGunner] join _group ~1 _newGunner assignasgunner myBoat [_newGunner] OrderGetIn TRUE ~1 _newGunner MoveInGunner myBoat Hope it helps someone. Cheers. Share this post Link to post Share on other sites
[aps]gnat 28 Posted February 16, 2005 Oops .... sorry Dr Strangelove ....... we posted very similar times ............ thx for your help. Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 16, 2005 No problem mate. Â More info for you: AI groups - if the last unit in a group gets shot, it takes exactly 30sec until he looses reference to the group. His body becomes a normal object (without AI). The group will stay active, but empty. - if the last member is deleted via deleteVehicle (before he looses reference to the group), the empty group also stays active. - if the last member joins another group (before he looses reference to the group), the original group is deleted and becomes <Nullgroup>. Share this post Link to post Share on other sites
bn880 5 Posted February 16, 2005 I don't believe these statements are exactly true. I don't think the 30s is a constant, I also do not think the group is deleted after the last member is moved out, it has not been my experience. Another issue is that groups which remain empty for too long, become invalid/broken. Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 16, 2005 (bn880 @ Feb. 16 2005,17:36) said: Another issue is that groups which remain empty for too long, become invalid/broken. I made an example mission to test all these scenarios, i could send you a link via PM if you want. Be my guest. In this mission it always takes exactly 30sec. However, i dunno if that's because there aren't many soldiers / groups, maybe the delay longer the bigger the whole mission gets. I can't comment on your last statement as it never happened to me yet. Are you sure an emtpy group is destroyed over time ? I needed to be sure about these things because i'm working on a 'Cleaner script' which joins dead soldiers into empty gamelogic groups so the bodies don't loose their references. You can specify how many dead bodies you want in your battle. If the numbers of bodies reach the barrier the script deletes the dead so the gamelogic groups can take new bodies. Not finished yet. Share this post Link to post Share on other sites
bn880 5 Posted February 16, 2005 ( said: )rStrangelove @ Feb. 16 2005,12:00)] (bn880 @ Feb. 16 2005,17:36) said: Another issue is that groups which remain empty for too long, become invalid/broken. I made an example mission to test all these scenarios, i could send you a link via PM if you want. Be my guest. In this mission it always takes exactly 30sec. However, i dunno if that's because there aren't many soldiers / groups, maybe the delay longer the bigger the whole mission gets. I can't comment on your last statement as it never happened to me yet. Are you sure an emtpy group is destroyed over time ? I needed to be sure about these things because i'm working on a 'Cleaner script' which joins dead soldiers into empty gamelogic groups so the bodies don't loose their references. You can specify how many dead bodies you want in your battle. If the numbers of bodies reach the barrier the script deletes the dead so the gamelogic groups can take new bodies. Not finished yet. I have a lot of experience with createUnit, an example mission does not cut it for me. There are many variances you will notice depending on load, MP games etc. Remember I created the EnemyStack at CoC, and AI On Demand system. I have spent weeks on both trying to figure out issues inculding the broken group one, and yes, it is real. I do not need to see your proof then, but thanks, I know you mean well. Share this post Link to post Share on other sites
crashdome 3 Posted February 16, 2005 ( said: )rStrangelove @ Feb. 16 2005,11:00)] (bn880 @ Feb. 16 2005,17:36) said: Another issue is that groups which remain empty for too long, become invalid/broken. I made an example mission to test all these scenarios, i could send you a link via PM if you want. Be my guest.  In this mission it always takes exactly 30sec. However, i dunno if that's because there aren't many soldiers / groups, maybe the delay longer the bigger the whole mission gets. I can't comment on your last statement as it never happened to me yet. Are you sure an emtpy group is destroyed over time ? I needed to be sure about these things because i'm working on a 'Cleaner script' which joins dead soldiers into empty gamelogic groups so the bodies don't loose their references. You can specify how many dead bodies you want in your battle. If the numbers of bodies reach the barrier the script deletes the dead so the gamelogic groups can take new bodies. Not finished yet. Couldn't you just keep adding the dead body reference to the end of an object array and delete from the beginning as needed? Or am I missing something about these references? Are you saying that the actual object reference of a dead unit can change after it has already been considered a dead unit? or would this idea work?: in init.sqs: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">GlobalDeadBodies = [] MaxDeadBodies = 100 addBodies = preprocessfile "addBodies.sqf" function "addBodies.sqf": <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//Adds a list of bodies to end of global array and deletes from beginning if necessary //call using: [deadGuy1,deadGuy2,etc..] call addBodies private ["_x","_extra"] GlobalDeadBodies = GlobalDeadBodies + this; if (count GlobalDeadBodies > MaxDeadBodies) then {  _extra = MaxDeadBodies - GlobalDeadBodies;  _x = 0;  while {_x < _extra} do  { deleteVehicle GlobalDeadBodies select _x;    GlobalDeadBodies = GlobalDeadBodies - [GlobalDeadBodies select _x];    _x = _x + 1;  }; }; I admit this could look alot better, but ultimately this should add bodies to end of array and delete any extra bodies from beginning of array automatically to fit the desired maximum count. EDIT: OOps.. forgot to add deletevehicle command...fixed Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 17, 2005 (bn880 @ Feb. 16 2005,18:42) said: I have a lot of experience with createUnit, an example mission does not cut it for me. Â There are many variances you will notice depending on load, MP games etc. Â Remember I created the EnemyStack at CoC, and AI On Demand system. Â I have spent weeks on both trying to figure out issues inculding the broken group one, and yes, it is real.I do not need to see your proof then, but thanks, I know you mean well. Â It's ok then. And i'm really thankful for your info, because (as you said) it takes a lot of time and sometimes concidence to notice how things behave. We scripters are like scientists, we see something, develop a theory and wait for something that turns it all upside down so we can develop a new theory. (lol - am i really talking about a game that is 3 years old ?) @CrashDome: The point is that i want to use a single group for ai respawns, not <grpNull> for every respawn. Simply because you create a new group and OpF has only 64 for each side. After 64 respawns the respawn scripts normally tend to stop functioning, freezing or crashing your OpF, or wahtever. Dead soldiers are still members of their group. If you don't shift them over to another (gamelogic) group, you can't spawn new soldiers into the same group. Exept you delete the dead men at once, which i don't want. I'd like them to stay there for a couple of minutes. Share this post Link to post Share on other sites
crashdome 3 Posted February 17, 2005 I thought dead units belong to grpNull? Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 18, 2005 Not immediately. Right after the death, the bodies still belong to their group, until OpF changes them to objects. You can see it when you show info about a dead soldier in a hint for example. First he's "Alpha Black:1" or so, after a certain delay he becomes an object (cant remeber the foreign expression now). With 1 unit in a group, it will be empty after about 30sec or so, depending on mission & maybe system. With more units, it takes longer to get an empty group because OpF changes the references one at a time only. For 12 men group you may wait up to 10min until it's clear. And you'll have to wait until its empty before you can respawn 12 new units into the group again. Therefore i shift them over to other groups that aren`t used with normal units by OpF - the gamelogic groups. Share this post Link to post Share on other sites
crashdome 3 Posted February 20, 2005 Have you tried:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit join grpNull instead? The object reference (in this case '_unit') will still hold a valid reference after the join command. You can still delete the body after a time delay by using the same object reference as long as you pass it out of the script. EDIT: While I do not disbelieve your 30sec rule in your tests, I question why that happens. In my experience, I have had dead units removed from the current group by simply joining others. Perhaps before the join or respawn OFP engine accelerates the removal of dead units. I know of your issue... I say this because I had a script that allowed for helicoptors to dynamically extract and insert units into battle. If the group 'died' before helo arrival I had the problem where the helo would wait for dead units. I simply used a (! alive) check just-in-case, so I have seen the problem of dead units remaining. However, my script which replaced those units (same group - but back at base) worked flawlessly. I guess spawning into those groups perhaps removed the dead units much faster?? ANOTHER EDIT: I am reminded of my tests about creating groups long ago. I have a script in my SOW package that allows for group management. You can take units and give them new groups or converge several into one (12 max of course). In my experience, after 64 groups, OFP ignores any calls for more groups. However, after more are cleared (via join command or death) OFP engine seemed to reuse old ones just fine for me? Share this post Link to post Share on other sites
bn880 5 Posted February 20, 2005 Yeah CrashDome you basically have the right idea except the one thing that's missing: join grpNull puts them in another "sequential" group. I think when they are dead they auto join the civilian side (make a new group if necessary), but it may be another group of their side, I forget. This is why he is using a GL group to put them into. Groups in OFP are a real headache. Share this post Link to post Share on other sites