Doolittle 0 Posted February 13, 2003 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 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">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" <span id='postcolor'> 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 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">;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" <span id='postcolor'> That was where all the magic happens. Â Note I am having problems correctly deleting everything. unittype.sqf </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">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 <span id='postcolor'> unitcreate.sqf </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">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 <span id='postcolor'> That function creates a "generic" soldier (with its own type of course). killed.sqs </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">?not local Server : exit _obj = _this select 0 ~300 _obj removeAllEventHandlers "Killed" deleteVehicle _obj <span id='postcolor'> Do that so that bodies aren't laying everywhere. An example mission can be found here 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 Share this post Link to post Share on other sites
Doolittle 0 Posted February 23, 2003 Hi, I dunno if anyone can help me, but I am having problems getting above said script to work. I wonder, basically I could have say 5 scripts in wait state (@) on the Server. Do they at any time stop running? Like does @ only run 100,000 times and then abort? Are scripts unable to hold their memory for a long time? The scripts are holding semi-big arrays of information to use later to spawn everyone in, do they lose this information if not used? Ack I have to go. I post more later. Doolittle Share this post Link to post Share on other sites
Lt_Damage 0 Posted February 23, 2003 Hey Doolittle why do you put the units on an island? They may aswell serve some purpose beyond stopping the delay caused by spawning, put them amongst the spawned troops in the area, there is really no reason they need to be seperate. Also I use a trigger/script combo that creates a group of east soldiers and they will follow a waypoint very easily. You can tell spawned units to get into vehicles easy too, I had a mission where I created a unit and his init can be specified as part of the CreateUnit script, and I put MoveInDriver in here. I *think* this has been changed sincee 1.85 though, you used to be able to create a unit with a name however I have noticed the last time I tried this it was generating an error. I really hope it hasn't been changed because it was very handy. I had a Tank platoon builder made totally with triggers that would build an M1A1, build it's crew, and move the crew into it, and then send it off on a waypoint, it could roll them out as long as you had spare groups. I'll check with BIS whether the naming thing has changed for create unit.. Oh, i've found the code I used: Two triggers, one activates after the other: First build M1A1: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> tanky = "M1Abrams" createVehicle getmarkerpos "tankFactory" Builds the M1A1 at that marker "tankFactory"<span id='postcolor'> Second, build the crew and insert into tank: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> "tankdriver = "SoldierWCrew" createUnit [getMarkerPos "barracks", groupAlpha,"this MoveinDriver tanky", 0.5, "MAJOR"];tankcommander = "SoldierWCrew" createUnit [getMarkerPos "barracks", groupAlpha,"this MoveinCommander tanky", 0.5, "CAPTAIN"];tankgunner = "SoldierWCrew" createUnit [getMarkerPos "barracks", groupAlpha,"this MoveinGunner tanky", 0.5, "MAJOR"] <span id='postcolor'> This used to work, I watched the tanks roll out with crew, but I can an error now since 1.85 I'm pretty sure thats when it stopped working Share this post Link to post Share on other sites
Lt_Damage 0 Posted February 23, 2003 This is from the comref: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE"> type createUnit unitInfo Operand types: type: String unitInfo: Array Compatibility: Version 1.34 required. Type of returned value: Nothing Description: Create unit of given type . Format of unitInfo is: [pos (Position),group (Group), init (String), skill (Number), rank (String)] Note: init, skill, and rank are optional, default values are "", 0.5, "PRIVATE". Example: "SoldierWB" createUnit [getMarkerPos "barracks", groupAlpha] <span id='postcolor'> Now as you can see you can specify all sorts of settings for the unit you create, so this would optimally be done in a script. Problem is I swear you used to be able to name them too.., This would be handy for spawning a named tank, and using a spawned unit's init to MoveInDriver TankName.. so an all in one spawning system basically. Share this post Link to post Share on other sites
Doolittle 0 Posted February 23, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">tankdriver = "SoldierWCrew" createUnit [getMarkerPos "barracks", groupAlpha,"this MoveinDriver tanky", 0.5, "MAJOR"];<span id='postcolor'> createUnit doesn't return anything unfortunately (unlike createVehicle). So tankdriver is null. Yes I am doing exactly what you are suggesting. I make my map like any other mission, by placing soldiers and tanks and waypoints for each group. Then I put triggers that cover a certain area and any enemy in that area is "remembered" and then deleted (the waypoints stay). Then when the player gets near I recreate everyone & every vehicle. It works perfect when it works, but I'm having an error somewhere I'm working on now. I am installing OFP on another computer and I will just run a dedicated server from it and then log in with my other computer to work out the server/client issues. It's impossible to check this stuff just on one system (right?). Lt_Damage, thanks for the suggestions though! Doolittle Share this post Link to post Share on other sites
Lt_Damage 0 Posted February 24, 2003 Suma can help me out here, you USED to be able to name the units you create, because I had a mission that relied on it, was played many times, and now doesn't work. Yes you definately need to test in a dedicated server environment, I have made many missions that work nicely on my system but once on the dedicated server it just goes mental. Share this post Link to post Share on other sites
Doolittle 0 Posted February 26, 2003 I have five scripts running on the server with @ in them. They seem to "not respond" after an extended amount of time. What is happening here? Is a script 'exec'ed for a certain amount of time and then removed from memory?? Doolittle Share this post Link to post Share on other sites
Guest jacobaby Posted March 1, 2003 run your 5 scripts with a counter attached and a wait of 0.001 the script doesnt "stop" at the @ command, in that it is still checking for the event required, so you may as well make it a looper. Share this post Link to post Share on other sites
Chronicles 0 Posted March 2, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">tankdriver = "SoldierWCrew" createUnit [getMarkerPos "barracks", groupAlpha,"this MoveinDriver tanky", 0.5, "MAJOR"]<span id='postcolor'> for strange reason , in my 1.46 version createUnit does nothing, in fact i never remember being able to make it work. But , if you use createVehicle for the crew members too it works in my 1.46 version , so give it a try in your Resistance version Share this post Link to post Share on other sites
Doolittle 0 Posted March 21, 2003 Okay, I finally got this baby working! Â I did a different approach as far as "setting them off". http://www.ofpec.com/editors/resource_view.php?id=461 Here is what it looks like in the map editor: You basically place all your units with waypoints, etc. Â Then you put a trigger over them that deletes them all and then respawns them in when someone enters the trigger area. Note: I gave up on trying to spawn a crew inside vehicles, so notice I am only using soldiers and no manned vehicles. I use GET IN waypoint instead. Doolittle Share this post Link to post Share on other sites
Guest jacobaby Posted March 21, 2003 Doolittle. In another thread regarding setidentitiy it was shown that you CAN name the units after all. If you use "name = this" as the init part of the array you then have a name Thanks to the guy who figured that out. My thoughts are to create a progressive naming function so that names are not repeated and could maybe be infinite. I wont have time to do it with the addons etc we are doing, but if somebody can come up with a script to sequentially name units it would be very useful. TJ Share this post Link to post Share on other sites
Doolittle 0 Posted March 21, 2003 The guy that came up with that was me (I think). Lookit how my unitcreate.sqf thing works, first post for this topic. To sequentially name units, the Chain of Command mines does this: Â call format ["mine%1", _n] gives you mine1, mine2, mine3, etc. Doolittle Share this post Link to post Share on other sites
Doolittle 0 Posted April 1, 2003 Okay, I've released a new version... What's new: - Enemy can spawn with different weapons (like HKG3, UZI, FAL, etc.) - Enemy will SURRENDER if they have taken a lot of damage - You can now place units like vehicles or trucks with soldiers in their cargo and they will all be re-created correctly What this script will do is createVehicle the vehicle, then createUnit the units that should be in that vehicle & move them in that vehicle. It even moves soldiers or whatever into the cargo if they were InCargo to begin with. Doolittle Share this post Link to post Share on other sites
Pimmelorus 0 Posted January 9, 2004 WHAAAAAA, Just what I was looking for. Thnx guys (Doolittle especially)! Pimmelorus ZEUS OFP community Share this post Link to post Share on other sites
terox 316 Posted January 11, 2004 Shouldnt be Doolittle, should be Doolot and a rank i think for this great coop system maybe Maj Doolot Share this post Link to post Share on other sites
Junker 0 Posted January 11, 2004 I have tried this script and it was cool but it does lag the server at the beginning ALOT. Is there any way you can remove the units 1 by 1 so it doesny pause the players for 10 seconds and create MASS LAG Share this post Link to post Share on other sites
Pimmelorus 0 Posted January 11, 2004 Thnx fot that warning. I guess you have to give control to the players only when all server side stuff has finished (communicate using PublicVariables; if that takes 10 secs, so be it...). Until then I will stick the players in a cutscene that does not end until the server has donw its intensive tasks. Thnx for the reply, Pimmelorus ZEUS OFP community Share this post Link to post Share on other sites