ChickenBandit 1 Posted September 18, 2013 I'm trying to spawn a civilian in every church within 2000m distance of the player's starting position. I've written a script for it, and it doesn't throw any errors when I launch the mission but the units do not spawn. I've included my code below, any idea as to what I'm doing wrong? house_positions = []; buildings = nearestObjects [player, ["House"], 2000]; { if((typeOf _x) in ["Land_Chapel_Small_V2_ruins_F", "Land_Chapel_Small_V1_ruins_F", "Land_Chapel_Small_V2_F", "Land_Chapel_Small_V2_ruins_F", "Land_Chapel_V1_F", "Land_Chapel_V1_ruins_F", "Land_Chapel_V2_F", "Land_Chapel_V2_ruins_F"]) then { _pos = getPosATL _x; house_positions = house_positions + [_pos]; }; } foreach buildings; { _x spawn { if ((count buildings) > 0) then { _church = buildings select 0; if ((typeOf _church) in ["Land_Chapel_Small_V2_ruins_F","Land_Chapel_Small_V1_ruins_F","Land_Chapel_Small_V2_F","Land_Chapel_Small_V2_ruins_F","Land_Chapel_V1_F","Land_Chapel_V1_ruins_F","Land_Chapel_V2_F","Land_Chapel_V2_ruins_F"]) then { _group = createGroup west; _char = "C_man_hunter_1_F" createUnit [_x, _group]; }; }; }; } forEach house_positions; Share this post Link to post Share on other sites
tpw 2315 Posted September 18, 2013 I think you need to make sure you have a centre before you can create a group of that type. Anyway, this code works and it's a bit simpler too: churches = ["Land_Chapel_Small_V2_ruins_F", "Land_Chapel_Small_V1_ruins_F", "Land_Chapel_Small_V2_F", "Land_Chapel_Small_V2_ruins_F", "Land_Chapel_V1_F", "Land_Chapel_V1_ruins_F", "Land_Chapel_V2_F", "Land_Chapel_V2_ruins_F"]; nearchurches = nearestObjects [position vehicle player,churches,2000]; _centerc = createCenter civilian; hintsilent format ["%1",count nearchurches]; { _group = creategroup civilian; _char = "C_man_hunter_1_F" createUnit [(getposatl _x), _group]; } forEach nearchurches; Share this post Link to post Share on other sites
kylania 568 Posted September 18, 2013 [s][color="#FF0000"]_char =[/color][/s] "C_man_hunter_1_F" createUnit [(getposatl _x), _group]; That's the OFP version of createUnit which does not return anything, so _char will be undefined. In order to capture the unit you'd need to use createUnit array instead: _char = _group createUnit ["C_man_hunter_1_F", (getposatl _x), [], 0, "FORM"]; Share this post Link to post Share on other sites
tpw 2315 Posted September 18, 2013 [s][color="#FF0000"]_char =[/color][/s] "C_man_hunter_1_F" createUnit [(getposatl _x), _group]; That's the OFP version of createUnit which does not return anything, so _char will be undefined. In order to capture the unit you'd need to use createUnit array instead: _char = _group createUnit ["C_man_hunter_1_F", (getposatl _x), [], 0, "FORM"]; Thanks for that Kylania, very helpful! Share this post Link to post Share on other sites