Home   Help Search Login Register  

Author Topic: Saving vehicles in a campaign (saveVeh.sqs & loadveh.sqs) (ACCEPTED)  (Read 3872 times)

0 Members and 1 Guest are viewing this topic.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
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.  :good:

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  :P). 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 :P).

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
« Last Edit: 03 Feb 2008, 18:37:03 by Loyalguard »
"When 900 years YOU reach, look as good you will not!"

Offline Arkon

  • Members
  • *
Re: Saving vehicles in a campaign (saveVeh.sqs & loadveh.sqs)
« Reply #1 on: 14 Jul 2007, 00:25:00 »


Hi Wolfrug,

Bleedin marvelous!!

Just what Iv'e bin looking for - it'l take a while to understand completely what's going on, but this will fill one large
loophole in my campaign - not sure what to do if its a boat though :)

Anyway, thanks again, I'll get back to you with some results soon...

Arkon






Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Saving vehicles in a campaign (saveVeh.sqs & loadveh.sqs)
« Reply #2 on: 14 Jul 2007, 12:28:15 »
If it's a boat, just use the appropriate entry in the http://www.ofpec.com/COMREF/armavehicles.php cfgvehicles tree->

Quote
Ship Class Vehicles:

All
AllVehicles
Ship
SmallShip
BigShip
BuoySmall
BuoyBig
Boat
RHIB
RHIB2Turret
Zodiac
Zodiac2
PBX

You can use singular cfgvehicle entries just as well as overarching ones (all ships - all rhibs - all zodiacs, etc).

 :good:

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline louiscar

  • Members
  • *
  • I'm a llama!
Re: Saving vehicles in a campaign (saveVeh.sqs & loadveh.sqs)
« Reply #3 on: 15 Jul 2007, 03:36:43 »
Hi Wolfrung,

I was looking at your scripts and thought I'd mention a small observation. In the save script you are saving the array inside the loop rather than after it. I would imagine this would work either way but I'm sure it's only necessary to do it once when the array is fully compiled.

Other than that nice script, I've just added a bit more code to detect if the player is in one of the vehicles and pass that across as this is needed in our campaign.
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Saving vehicles in a campaign (saveVeh.sqs & loadveh.sqs)
« Reply #4 on: 15 Jul 2007, 17:09:49 »
 :D Right you are louiscar. As I said : not the A and O of saving/loading vehicles in a campaign, more of something I put together over an evening because I got randomly inspired. I've already edited the loadveh.sqs twice to fix some things, so it's not, as mentioned, entirely perfect. Much more effective than using a pre-defined global variable would probably also be to make it into a .sqf file which would output the finished array, which you could then save and put into the loading sequence. Yep yep.

 :cool2: If anyone makes any big improvements to these scripts, feel free to post. Sharing is good!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline louiscar

  • Members
  • *
  • I'm a llama!
Re: Saving vehicles in a campaign (saveVeh.sqs & loadveh.sqs)
« Reply #5 on: 17 Jul 2007, 09:19:56 »
Curiously after setting up a campaign test I found that RUGsavedVehicles was not being saved at all when I moved the line below the loop. I haven't figured this out. I had made a few additions to id a vehicle that the play may be in and added a small amount of extra code to pass the name of the vehicles across.


When moving your saveVar line back into the loop it appears to save ok but I wasn't getting any vehicles created still.  Logical though my obervation appeared to be it's not so logical that the saveVar isn't working after the loop, Perhaps a clue is the hint line isn't being produced when running the campaign verison I don't know .

I thought perhaps it's probably something I had done after mucking about with the code so I restored your original code to see this work and although it does it only seems to save one vehicle of 3 present. Again I've not figured this out yet or why my version fails to restore anything.

-------------------------------
Edit
-------------------------------

It looks like the above problems occured because I ran the script from the activation of an END trigger. It appears that the script gets cut short at some point in it's loop. This was a real frustrating one. Separating the save script using another trigger cured both the saveVar line outside the loop and the existence of only one vehicle out of 3. Obviously there's a limit to how long a script can run in an end trigger.



« Last Edit: 17 Jul 2007, 13:34:25 by louiscar »
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Updated!

I've updated the script into .sqf format, added some slight functionality (as per Spooner's suggestions), made it more complicated  :whistle: but hopefully more generally useful. Also I've made a little "demo campaign" since Spooner wanted it, and added a readme. It should be ready for Ed.Depot submission now!  :)

The readme:

Quote
Scripts by Wolfrug
Released at OFPEC.com
For ArmA versions 1.08 ->

From commented scripts:


saveVeh.sqf:

By Wolfrug 13.7.2007 - converted to .sqf 23.10.2007.
Outputs an array of all saved vehicles, which can be put into a global array and also saved from campaign mission to campaign mission. _center is a unit (or a trigger/logic object) from which the _area is calculated. All the cfgvehicle-types found in the _types array are saved -> up to the number determined in _max. Since saveVeh.sqf is a function, you need to first prepare it using something like this: RUG_SavingVehicles = compile loadFile "saveVeh.sqf"
After that call the script (using the precompiled variable), and save the array into a global variable that you then save using saveVar: RUG_SavedVehicles=[parkinglot, 50, ['Car', 'Tank'], 5] call RUG_SavingVehicles; saveVar 'RUG_SavedVehicles'' (with the single quotes replaced by real quotes). This will save up to 5 vehicles that are either 'Car' or 'Tank' class in a 50 meter radius around the object named parkinglot. Remember to use saveVar to save the array!"

loadVeh.sqf:

By Wolfrug 13.7.2007 - changed to .sqf format on 23.10.2007.
Loads vehicles from the global array. _positions is an array of markers (if [], they will spawn on their last location), globaldir determines the direction of all loaded vehicles (if -1 they will retain the direction they had when saved) and _nameArray should be whatever array of saved vehicles you want to load (as created through saveVeh.sqf). Sample: nil=[['marker1', 'marker2'], 180, RUG_SavedVehicles]execVM 'loadVeh.sqf' -> spawns the vehicles facing due south randomly on 'marker1' and 'marker2'. Exhange all single quotes for real quotes!"

Example:

in init.sqs, first precompile the .sqf function for later use.

SAVEVEH=compile loadFile "saveVeh.sqf";

then, when you want to save the vehicles, use something like:

FirstArray = [saveArea1, 20, ["LandVehicle"], 10] call SAVEVEH;

This will fill the global variable FirstArray. You can also add many such arrays. For instance

_Array1 = [Player, 20, ["LandVehicle"], 10] call SAVEVEH;
_Array2 = [saveArea1, 20, ["Plane", "Tank"], 3] call SAVEVEH;

SavedVehicles = _Array1 + _Array2;
saveVar "SavedVehicles";


Now, when you want to load these vehicles, simply invoke loadveh.sqf, which is considerably easier to use:

nil=[[], -1, SavedVehicles] execVM "loadveh.sqf";

That will load all the vehicles in the SavedVehicles array, facing their original directions and keeping their original locations.

Notes:

The script will NOT save destroyed vehicles that have stopped smoking! It will however save vehicles that were just destroyed (still burning), and when these are loaded again they will still be destroyed. By default the script maintains position, direction, damage level and fuel level (not fuel or ammo CARGO however, since there are no commands to find these out). Also, there are no commands to find out the weapon and magazine cargo of each vehicle, and since each vehicle is recreated in loadVeh, if they by default have magazines or weapons in their cargo, these will also be recreated (for instance RACS Landrovers and Ammo trucks have plenty of ammo in their cargo space). Only way to bypass this is to, after invoking loadVeh.sqf, clear the magazine and weapon cargo of all the recreated vehicles.

With the new ArmA commands of, for instance, vehicleVarName, SetVehicleVarName it MIGHT be possible also to save things such as the vehicle's editor-placed names. This could allow for some more dynamicness with this command, however I have not tested it in a campaign environment. Feel free to try it out as you wish!

Have fun!

Wolfrug.

Scripts (inside demo campaign) attached.

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Although I believe that the code works, I couldn't get the campaign to work (I pboed the directory and moved them to the ArmA campaigns directory). I drove 4 cars actually inside the warehouse and spoke to Vincento but he didn't say anything to me and I didn't move to the next mission (odd, since reading the code, he should say something whether I finish the mission or not). You don't really need such a complicated mission to demonstrate the code though, since it isn't for playing; it is for testing and seeing how to integrate the scripts into your own missions . e.g. the extra civilians aren't needed and Vincento could be in the warehouse, not the docks (why make me walk?). You could even get away with a car-park filled with the vehicles at the start and you can move them about before talking to Vencento and moving the campaign along. But anyway, that isn't as important as the fact the campaign didn't seem to work ;P
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Well, I tested it -without- PBO'ing it (it runs fine as a folder inside the campaign directory), and it worked then. The problem is with the ending trigger, which I didn't bother to figure out so I simply "force-ended" it (using, dah, forceEnd) after talking to Vincento. I don't actually know how to make a campaign either, I simply copy-pasted the description.ext from ADCS by Tacrod and changed the mission names.  :dunno:

And I threw it together over a very little bunch of time anyway, so it's not that advanced. :D Oh well. If you can't get it to work as a not-pbo, then I guess I'll have to remake it. Sigh. Teach ya to make scripts for campaigns!  :dry: But anyway: it WORKS. 'onest.

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
I tried it again with just the plain files in the campaigns folder, but again Vincento had an action on him, but using it had no effect. *shrugs*

It isn't the scripts being tested that are at fault, as far as I can tell, but rather that nothing happens when you talk to the Boss man (he doesn't say anything or stop the mission).
« Last Edit: 25 Oct 2007, 22:26:41 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)