Home   Help Search Login Register  

Author Topic: Delete groups, Then createunit them  (Read 2046 times)

0 Members and 1 Guest are viewing this topic.

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Delete groups, Then createunit them
« on: 13 Feb 2003, 09:09:23 »
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=27119

Hi.  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
Code: [Select]
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
Code: [Select]
;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
Code: [Select]
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
Code: [Select]
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
Code: [Select]
?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

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:Delete groups, Then createunit them
« Reply #1 on: 13 Feb 2003, 12:39:32 »
This is seriously cool. The possibilities are endless.

Quote
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.

Ok, so you mean that if you createUnit a new object, and there is not already another object of the same type in the mission, there is a pause.

If an object of the same type is already in the mission, there is no pause.

Is that correct?
Bohemia Interactive Simulations

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:Delete groups, Then createunit them
« Reply #2 on: 13 Feb 2003, 17:07:28 »
Quote
Ok, so you mean that if you createUnit a new object, and there is not already another object of the same type in the mission, there is a pause.

If an object of the same type is already in the mission, there is no pause.

Is that correct?

Yeah snYpir,

at least this is what SUMA said at BIS forum, when the
discussion about delay/lag while creating units, came up.

But when i was using createunit in combination with
ordinary East soldiers (where already have been lots
of them on the map), i didn't notice any decrease of the
pause, the game does (0.5 up to 1 sec's or so).

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted

Offline Doolittle

  • Contributing Member
  • **
  • _this select 0
Re:Delete groups, Then createunit them
« Reply #3 on: 02 Apr 2003, 07:40:39 »
Hey, I've upgrade http://www.ofpec.com/editors/resource_view.php?id=461.  Now enemy vehicles can be spawned in....and even enemies inside vehicles as cargo (like a truck full of soldiers).

Doolittle

esti_the_big

  • Guest
Re:Delete groups, Then createunit them
« Reply #4 on: 28 Apr 2003, 21:28:47 »
HiI people,

The mission I'm working on could use this script really well, as there are huge amounts of units on the map. Unfortunatly, I don't know how to port this script to my mission, I'm not that good a scripter that I know whats actually going on with the script. is there any sort of tutorial on how using this script?

before I forget it,
This script can also be used for sp missions with a lot of enemies to win performance, can it?
« Last Edit: 28 Apr 2003, 21:30:00 by esti_the_big »