Hi, this is a cut & past from the flashpoint1985 forum.
http://www.flashpoint1985.com/cgi-bin/ikonboard301/ikonboard.cgi?s=3e4b4a7a150cffff;act=ST;f=7;t=27119Hi. Here is a script I wrote that takes everything in a list and deletes it, it then waits for a condition and re-creates everything. I have used this to lay out a huge amount of enemies and then make nice waypoints for all of them. Then when the player gets close or something, they just spawn in. The problem is you
cannot name objects or make them In Cargo or have low fuel or any other little thing. They are made generic.
init.sqs
requiredVersion "1.85"
titleCut ["", "BLACK IN", 3]
Soldier = ["OfficerE", "SoldierEMG", "SoldierEG", "SoldierELAW", "SoldierEMedic", "SoldierESaboteurPipe", "SoldierEAT", "SoldierECrew", "BMP", "T72", "UAZ", "Ural", "SoldierEB"]
unitcreate = loadFile "unitcreate.sqf"
unittype = loadFile "unittype.sqf"
I had to write my limited stupid little typeOf function because typeOf is only in 1.91. When we all go to 1.91 I will use this instead. unittype is my version of typeOf. I only bothered to include the types I used in my mission.
units.sqs
;Script by Doolittle
?not local Server : exit
_thisList = _this select 0
_condition = _this select 1
_vehicletype = []
_crewtype = []
_pos = []
_group = []
_i = 0
#type
_obj = _thisList select _i
_vehicletype = _vehicletype + [[vehicle _obj] call unittype]
_crew = []
"_crew = _crew + [[_x] call unittype]" forEach crew _obj
_crewtype = _crewtype + [_crew]
_pos = _pos + [getPos _obj]
_group = _group + [group _obj]
"deleteVehicle _x" forEach crew _obj
deleteVehicle _obj
_i = _i + 1
?_i < count _thisList : goto "type"
@triggerUnits == _condition
_i = 0
#create
~1
_crew = _crewtype select _i
?_vehicletype select _i == _crew select 0 : [_vehicletype select _i, _pos select _i, _group select _i] call unitcreate; goto "count"
_vehicle = (_vehicletype select _i) createVehicle (_pos select _i)
_vehicle addEventHandler ["Killed", {_this exec "killed.sqs"}]
_obj = [_crew select 0, _pos select _i, _group select _i] call unitcreate
_obj moveInDriver _vehicle
?count _crew < 2 : goto "count"
_obj = [_crew select 1, _pos select _i, _group select _i] call unitcreate
_obj moveInGunner _vehicle
?count _crew < 3 : goto "count"
_obj = [_crew select 2, _pos select _i, _group select _i] call unitcreate
_obj moveInCommander _vehicle
#count
_i = _i + 1
?_i < count _vehicletype : goto "create"
That was where all the magic happens. Note I am having problems correctly deleting everything.
unittype.sqf
private ["_i", "_obj", "_type"];
_obj = _this select 0;
_i = 0;
while "_i < count Soldier" do {
_type = Soldier select _i;
if (_type countType [_obj] > 0) then {_i = count Soldier};
_i = _i + 1;
};
_type
unitcreate.sqf
private ["_type", "_pos", "_group"];
_type = _this select 0;
_pos = _this select 1;
_group = _this select 2;
Unit = [];
_type createUnit [_pos, _group, "Unit = this", 0.55, "MAJOR"];
Unit setBehaviour "SAFE";
Unit setCombatMode "RED";
Unit setSpeedMode "LIMITED";
Unit addEventHandler ["Killed", {_this exec "killed.sqs"}];
Unit
That function creates a "generic" soldier (with its own type of course).
killed.sqs
?not local Server : exit
_obj = _this select 0
~300
_obj removeAllEventHandlers "Killed"
deleteVehicle _obj
Do that so that bodies aren't laying everywhere.
An example mission can be found at
http://www10.brinkster.com/dbircsak as
co14do_fourshilkas.zip. Note that I have at least one copy of each object that is never deleted. I put them off on some island.
This gets rid of the annoying pause/delay you get when createUnitting something.If you use these scripts please mention "Vehicle/Unit Spawn Script by Doolittle" or something. This took a lot of time to make and test. Thanks!
Doolittle