splatsh 10 Posted August 5, 2009 (edited) Can someone give me a bit of code to check if all in my Razor Team is alive, and if one of them is dead, then a replacement men (Of the same kind of the dead one) I have named them p0, p1, p2, p3, p4, p5. I could do this??? // check_squad.sqf if (!(alive p1)) then { //Create p1 men; server execVM "squad\create_p1.sqf" } else { // NOTHING; }; if (!(alive p2)) then { //Create p2 men; server execVM "squad\create_p2.sqf" } else { // NOTHING; }; if (!(alive p3)) then { //Create p3 men; server execVM "squad\create_p3.sqf" } else { // NOTHING; }; if (!(alive p4)) then { //Create p4 men; server execVM "squad\create_p4.sqf" } else { // NOTHING; }; if (!(alive p5)) then { //Create p5 men; server execVM "squad\create_p5.sqf" } else { // NOTHING; }; I dont have any check on p0, that is the player, and when he dies, the game is over... Then I run this code above once I have completed a task when completed, then run "check_squad.sqf" Or how can I do it in a better way? Edited August 6, 2009 by splatsh Share this post Link to post Share on other sites
norm6669 10 Posted August 5, 2009 (edited) _array = [P1, P2, P3, P4]; for [{_i=0}, {_i < count _array}, {_i=_i+1}] do { if (!(alive (_array select _i))) then { (_array select _i) execVM squad\create.sqf }; }; And in the create.sqf script, _this will have the value of the unit to replace... P1, P2, etc... You really need to learn about array and "batch processing" when you want to apply the same code to a batch of units... There is no need to copy the same code over and over. To choose the unit type in you create.sqf, you could use a case statement... something like: switch (_this) do { case "P1": {_UnitType = "USMC_Soldier"}; case "P2": {_UnitType = "USMC_Soldier_GL"}; case "P3": {_UnitType = "USMC_Soldier_AR"}; }; Edited August 5, 2009 by norm6669 Share this post Link to post Share on other sites
galzohar 31 Posted August 5, 2009 The above suggestions are even more useful for when you want some of the code that runs to be the same for every soldier, so that you don't have to write (and more importantly - debug and/or update when you want to change something) multiple times. Share this post Link to post Share on other sites
doomanchu 11 Posted August 5, 2009 Instead of having them respawn after a task has been completed, is there a way for it to check if they are alive every 45 seconds? Share this post Link to post Share on other sites
splatsh 10 Posted August 5, 2009 Thanks, this is the way, but need to check over it. When I run this code for testing with a trigger the whole game is freezing and then craching. I have copied your code. // check_squad.sqf _array = [P1, P2, P3, P4]; for [{_i=0}, {_i < count _array}, {_i=_i+1}] do { if (!(alive (_array select _i))) then { (_array select _i) execVM squad\create.sqf }; }; // create.sqf switch (_this) do { case "P1": {_UnitType = "FR_Cooper"}; case "P2": {_UnitType = "FR_Sykes"}; case "P3": {_UnitType = "FR_Rodriguez"}; case "P4": {_UnitType = "FR_OHara"}; }; _unit = _UnitType createUnit [getMarkerPos "spawn",group player]; I am going too look and try to get it to work, but I cant code this so good, so thanks I am going to need some help. ---------- Post added at 11:19 AM ---------- Previous post was at 10:03 AM ---------- I need more help with that... I need to name every unit to its name it have, and get the gear they have. for example: FR_cooper name: p1 init field: [this] exec "gear\p1.sqs" Then I need every unit to join player as soon as possible. If I do it manualy for one man it look like this: _this = createCenter west; _center_0 = _this; _group_0 = createGroup _center_0; _this = _group_0 createUnit ["FR_Cooper", [(getMarkerPos "squad_spawn") select 0,(getMarkerPos "squad_spawn") select 1,10], [], 3, "FORM"]; _this setVehicleInit "[this] exec ""gear\p1.sqs"""; _this setVehicleVarName "p1"; p1 = _this; [p1] join player; So how to get in all that for every squad member (p1, p2, p3, p4) in this "case" thing you have, and if 2 squad members is dead, do I get 2 men then? Share this post Link to post Share on other sites
kiptanoi 10 Posted August 6, 2009 _array = [P1, P2, P3, P4]; for [{_i=0}, {_i < count _array}, {_i=_i+1}] do { if (!(alive (_array select _i))) then { (_array select _i) execVM squad\create.sqf }; }; And in the create.sqf script, _this will have the value of the unit to replace... P1, P2, etc... You really need to learn about array and "batch processing" when you want to apply the same code to a batch of units... There is no need to copy the same code over and over. To choose the unit type in you create.sqf, you could use a case statement... something like: switch (_this) do { case "P1": {_UnitType = "USMC_Soldier"}; case "P2": {_UnitType = "USMC_Soldier_GL"}; case "P3": {_UnitType = "USMC_Soldier_AR"}; }; How to get all this to work, I need to know that to. Share this post Link to post Share on other sites
Inkompetent 0 Posted August 6, 2009 Try to change the (_array select _i) execVM squad\create.sqf to [(_array select _i)] execVM "squad\create.sqf" Share this post Link to post Share on other sites
kiptanoi 10 Posted August 6, 2009 (edited) Try to change the (_array select _i) execVM squad\create.sqf to [(_array select _i)] execVM "squad\create.sqf" Ok, but this create page then, how should that one look like? I mean... this is what I have now. _group_3 = createGroup West; _this = _group_3 createUnit ["FR_Cooper", [(MarkerPos "area1") select 0,(MarkerPos "area1") select 1,10], [], 3, "NONE"]; _unit_5 = _this; _this setVehicleVarName "p1"; p1 = _this; _this setVehicleInit "[this] exec ""gear\p1.sqs"""; _this setUnitAbility 0.90000002; [p1] join p0; p1=false; and that code create a single unit, right. then I could change "FR_Cooper" to _UnitType to get the right type, but that is still make one single unit, how to create as many as its needs in one time with the code above. (if 2 or 3 squad members are killed) ---------- Post added at 09:31 AM ---------- Previous post was at 08:44 AM ---------- Error Missing ; check_squad2.sqf, line 9 _array = [p1, p2, p3, p4]; for [{_i=0}, {_i < count _array}, {_i=_i+1}] do { if (!(alive (_array select _i))) then { (_array select _i) execVM squad\create.sqf }; }; ---------------------------------------------------------------------- test2 Error Missing ; check_squad2.sqf, line 9 _array = [p1, p2, p3, p4]; for [{_i=0}, {_i < count _array}, {_i=_i+1}] do {; if (!(alive (_array select _i))) then {; (_array select _i) execVM squad\create.sqf; }; }; Edited August 6, 2009 by Kiptanoi Share this post Link to post Share on other sites
Inkompetent 0 Posted August 7, 2009 (edited) To start with _this is a reserved variable. I don't know if it's possible to use it as you do, and even if it is, it's a very ugly way of coding. _this is used to point at the parameters the script is fed with, like for example _unit = _this select 0; It should never be used for anything else. I can't really see why you use _unit_5 = _this; at all, since you never use _unit_5 again in the script. I'd even stretch to say that any uses of both _this and _unit_5 are meaningless since you copy it all into the variable p1 just a couple of lines further down anyway (although I might be wrong since I've never created named units by script) and make it like: _group_3 = createGroup West; p1 = _group_3 createUnit ["FR_Cooper", [(MarkerPos "area1") select 0,(MarkerPos "area1") select 1,10], [], 3, "NONE"]; p1 setVehicleVarName "p1"; p1 setVehicleInit "[this] exec ""gear\p1.sqs"""; p1 setUnitAbility 0.90000002; [p1] join p0; p1=false; And I still think you should change the (_array select _i) execVM squad\create.sqf; to [(_array select _i)] execVM "squad\create.sqf" since your execVM isn't formatted correctly. Should look like: _array = [p1, p2, p3, p4]; for [{_i=0}, {_i < count _array}, {_i=_i+1}] do { if (!(alive (_array select _i))) then { [(_array select _i)] execVM "squad\create.sqf"; }; }; You can't ever EVER put a semicolon after a '{' since that bracket STARTS a section of code instead of ends it, while a semicolon tells the engine that it is the end of a command. Edited August 7, 2009 by Inkompetent Share this post Link to post Share on other sites