Edit for the MD staffers: I'm going to at some point update this into .sqf syntax, which should also hopefully make it save everything so fast that it can be used in the actual "End" trigger (as louiscar noted was a problem). When I've done that I'll update this post properly (with a readme and example mission, hopefully). Edit2: See last post for latest version (in .sqf format) + demo campaign.
edit: forgot to "saveVar" the cleared vehiclepool after every load, so the removed/destroyed vehicles weren't actually removed >_< fixed the loadveh.sqs now. <- caused another problem, fixed too. Should work now >_<
In my current mission-thingee I'm making, I felt the need to create some scripts which would allow me to dynamically save vehicles from mission to mission, so I spent some time and quickly coded up these two scripts. They're not the A and O of vehicle-saving scripts, but I found them useful enough to be posted here anyway. Feel free to try them out and see if you find any errors.
And yes, there're endless amounts of tweaking that can be done to add functions and remove functions, and speaking of functions it'd probably look good as a .sqf as well (I'm old skool .sqs, myself
). Ah well, without further ado, here be the scripts (no example...er...campaign at this time. Although it doesn't need a campaign to be tested, although I have tested it in a campaign and it DOES work).
How:
The scripts use a global variable named RUG_SavedVehicles which store a number of things about each vehicle, namely its name, its damage level, its position and its facing. These are added into arrays in the RUG_SavedVehicles variable, which is then saved via SaveVar for future missions. The array in RUG_SavedVehicles is emptied at the end of every loadVeh.sqs, to avoid it filling up with duplicates. The current setup requires the vehicles to be within a certain area in which they'll be saved. They'll either load on their last known location or on pre-set markers ("parking lot"). You can also determine exactly what types of vehicles are affected by consulting your local cfgvehicles list (so you can have "landvehicle" or just "Car" etc). Note that it might grab destroyed vehicles (which might load exploding and taking out everything
).
They're fairly easily set up, so it shouldn't be a problem for people who know what they're doing. Anyway...here's the basic setup:
Make a center, name it something (a trigger works fine, and gives you a good approximation of the affected areas. The radius is determined with the nearObjects command). Then place another trigger with whatever condition you want (the "mission ending" variable is generally good), and execute the saveveh.sqs from there:
[parkinglot, 50, ["Car", "Tank"], 5]exec "saveVeh.sqs
explanation:
parkinglot = the center
50 = meters around center that vehicles are saved
["car", "tank"] = array with all the different vehicle types that are saved; can be as specific as necessary or as broad and necessary. Might cause problems on the veryvery general level, so "LandVehicle" is pretty good if you just want pretty much everything saved that goes on land.
5 = the maximum number of vehicles saved. Just make it some insane number if you want to save everything.
Then the loadveh.sqs: This one is considerably easier, all you need really is to run it (at the start of the mission, preferably), but you do have some options as well. Here's the basic syntax:
[["marker1", "marker2"], 180, RUG_SavedVehicles]exec "loadVeh.sqs"
explanations:
["marker1", "marker2"] = an array of markers upon which the vehicles randomly spawn (if you don't want them to spawn on their last location from the saveVeh.sqs)
180 = a "global direction", basically all the vehicles will have this direction on spawn. If you want them to retain their original saved direction, make this number -1.
RUG_SavedVehicles = this is just supposed to be RUG_SavedVehicles ^^
Note that both of these scripts have some hint-commentary at the end which tells the number of saved/loaded vehicles as well as their types. Also they will comment if there're no vehicles to load/save. These can be edited out easily enough.
Enjoy!
Wolfrug out