mrpiipe 2 Posted November 14, 2013 (edited) I've been searching for the past 30 mins about this and haven't found anything about it. I'm still fairly new to Arma scripting and need some help. What I'm trying to do is using a laptop with addAction to spawn or remove a civilian in a predetermined location. For example Laptop-> Enable Civilians (Spawns 5 civilians in a specific location, they won't move or do anything at all) Laptop-> Disable Civilians (Removes the 5 civilians that were spawned in). And essentially do any of the 2 whenever necessary. Any help? Thanks. Thanks a lot to Wok, if you are looking for something about this look at the posts below. Edited November 14, 2013 by MrPiipe Share this post Link to post Share on other sites
wok 1 Posted November 14, 2013 You can spawn a civ with: _group = createGroup civilian; "C_man_polo_1_F" createUnit [position player, _group]; Not sure how to remove it, I think in arma 2 deletevehicle was used, may still work for A3. Share this post Link to post Share on other sites
mrpiipe 2 Posted November 14, 2013 Alright got it to spawn the unit, for some reason in the init section of the function I can't seem to be able to use "this disableAI "ANIM";" because it gives me an error everytime. Any ideas on how I can use it? Or any ideas on how to make the civ not move or not be afraid of bullets flying right next to him. Share this post Link to post Share on other sites
wok 1 Posted November 14, 2013 Alright got it to spawn the unit, for some reason in the init section of the function I can't seem to be able to use "this disableAI "ANIM";" because it gives me an error everytime. Any ideas on how I can use it? Or any ideas on how to make the civ not move or not be afraid of bullets flying right next to him. Try this (untested code): _group = createGroup civilian; "C_man_polo_1_F" createUnit [position player, _group, "this disableAI 'ANIM';"]; Share this post Link to post Share on other sites
mrpiipe 2 Posted November 14, 2013 Worked like a charm. New challenge lol: Right now I have it spawning like this: "C_man_1" createUnit [getMarkerPos "Civ1", _civ1Group,"Civ1 = this; this setDir 226; this disableAI 'ANIM'; this addAction ['Secure Hostage', 'deleteVehicle Civ1'] "]; Working perfectly when I spawn him and when I approach him to secure him, but, when I make another script were I delete all of the at the same time it doesn't work deleteVehicle Civ1; deleteVehicle Civ2; deleteVehicle Civ3; deleteVehicle Civ4; deleteVehicle Civ5; deleteVehicle Civ6; No idea why it's not working since it's pretty much the same code, looking if I made a grammar error or something but nothing.. Nevermind I made a grammatical error <.< Another thing, if I use the "Enable Civilians" twice it will spawn 2 civs right next to each other, is there any way to enclose the code in a "if" so that it only spawns new civs when the one that use to be there was deleted? Share this post Link to post Share on other sites
wok 1 Posted November 14, 2013 (edited) An if statement to check that could be something like: if( isnil('Civ1') ) then { /* createUnit code */ }: And also in the part of your code when you remove the unit you need to make Civ1 = nil; like this: this addAction ['Secure Hostage', 'deleteVehicle Civ1; Civ1 = nil;']; Edited November 14, 2013 by wok Share this post Link to post Share on other sites
mrpiipe 2 Posted November 14, 2013 Yup, didn't know "isnil" was a thing, was looking for something similar but couldn't find it :P Works like a charm, you are awesome Wok, thanks a lot. I will add you to the Thanks list for my CQB Training Facility when I release this update ;) Share this post Link to post Share on other sites
MulleDK19 21 Posted November 14, 2013 I was bored. // Variables prefixed with CS to avoid name clashes (CS = Civilian Spawner). CS_CivilianTypes = []; // Array containing all the possible types of civilians that will be used for spawning. This will be filled dynamically from the config files by the code below. CS_SpawnedCivilians = []; // An array containing all the civilians that have have been spawned by us. ////////// // Fill CS_CivilianTypes from config // Make the local variables private. private ["_civilianSide", "_cfgVehiclesConfig", "_cfgVehiclesConfigCount" ,"_config", "_isMan", "_sideIndex"]; _civilianSide = 3; // The civilian side index. _cfgVehiclesConfig = configFile >> "CfgVehicles"; // Get the CfgVehicles config. _cfgVehiclesConfigCount = count _cfgVehiclesConfig; // Count how many entries there are in CfgVehicles. for [{_i = 0}, {_i < _cfgVehiclesConfigCount}, {_i = _i + 1}] do { _config = _cfgVehiclesConfig select _i; // Get the vehicle at the current index. // We only want classes. if (isClass _config) then { _isMan = getNumber (_config >> "isMan"); // Get the value of the isMan property. // If it ain't zero, this is a man (soldier or civilian). if (_isMan != 0) then { _sideIndex = getNumber (_config >> "side"); // Get the index of the side the man belongs to. // If the man is on the civilian side, add him to CS_CivilianTypes. if (_sideIndex == _civilianSide) then { CS_CivilianTypes set [count CS_CivilianTypes, configName _config]; } } }; }; // Fill CS_CivilianTypes from config ////////// /** * Function to get a random element from the CS_CivilianTypes array. * * Parameters: * None. * * Returns: * string: the element retrieved from the CS_CivilianTypes array. * * Example: * // Prints 30 random civilians in a hint. * _text = "Civilian types:"; * for [{_i = 0}, {_i < 30}, {_i = _i + 1}] do * { * _text = format ["%1\n%2", _text, call CS_fnc_getRandomCivilianType]; * }; * * hint _text; **/ CS_fnc_getRandomCivilianType = { CS_CivilianTypes select (floor random count CS_CivilianTypes); }; /** * Spawns the specified amount of civilians at the "civilians_spawn_point" marker. * * Parameters: * _this: the number of civilians to spawn at the marker. * * Returns: * Nothing. * * Example: * 10 call CS_fnc_spawnCivilians; // Spawns 10 civilians at the "civilians_spawn_point" marker. **/ CS_fnc_spawnCivilians = { // Make the local variables private. private ["_amountToSpawn", "_spawnPosition", "_civilianGroup", "_civilianType", "_civilian"]; // Get the number of civilians to spawn from the parameter passed to this function. _amountToSpawn = _this; // Get the position to spawn them at. _spawnPosition = getMarkerPos "civilians_spawn_point"; // Create a group for the civilians. _civilianGroup = createGroup civilian; // Repeat _amountToSpawn times. for [{_i = 0}, {_i < _amountToSpawn}, {_i = _i + 1}] do { // Pick a random civilian type from the CS_CivilianTypes array. _civilianType = call CS_fnc_getRandomCivilianType; // Spawn the civilian as part of the created group, at the spawn position. _civilian = _civilianGroup createUnit [_civilianType, _spawnPosition, [], 0, "NONE"]; // Make the civilian stop moving. doStop _civilian; // Add the spawned civilian to the CS_SpawnedCivilians array. CS_SpawnedCivilians set [count CS_SpawnedCivilians, _civilian]; }; }; /** * Removes all civilians spawned by the CS_fnc_spawnCivilians function. * * Parameters: * None. * * Returns: * Nothing. * * Example: * call CS_fnc_removeAllCivilians; **/ CS_fnc_removeAllCivilians = { // Iterate each spawned civilian. { // Delete the iterated civilian. deleteVehicle _x; } forEach CS_SpawnedCivilians; // Clear the array. CS_SpawnedCivilians = []; }; // Add some actions to the laptop to allow spawning and removing civilians. laptop addAction ["Spawn 10 civilians", { 10 call CS_fnc_spawnCivilians; }]; laptop addAction ["Spawn 20 civilians", { 20 call CS_fnc_spawnCivilians; }]; laptop addAction ["Spawn 30 civilians", { 30 call CS_fnc_spawnCivilians; }]; laptop addAction ["Remove civilians", { call CS_fnc_removeAllCivilians; }]; Share this post Link to post Share on other sites
mrpiipe 2 Posted November 14, 2013 Looks really good but what I have is simple and does the job like a charm, I only need to spawn 6 civilians and delete them if necessary. But, I appreciate your work and hopefully this can come in handy for somebody else, thanks Share this post Link to post Share on other sites