Jump to content

Recommended Posts

### THIS THREAD HAS BEEN CLOSED, THERE IS NO ANSWER HERE. IF YOU WANT ANSWERS ASK ME DIRECTLY. ###

Hello everyone.
So, I'm currently building my own persistent survival simulation and I've managed to save both inventory gear and position of players onto the server side without using any 3rd party databases to achieve this.
Now my question is this, how do I save vehicles persistently so they remain on the map with their gear stored, fuel remaining etc etc, still intact after server restart using the fn_Savestat?

I have no code for this as I have no idea what may work or may not.
I've spend months trying to get several scripts to work and I've even tried to tweak them myself but to no avail.

If anyone can help me with this, I'd be very gradeful.

Kind regards
- Revixy.

Share this post


Link to post
Share on other sites

You will need a database of sorts how else are you going to retain data on the vehicles?

Share this post


Link to post
Share on other sites
19 minutes ago, Poppadomus said:

You will need a database of sorts how else are you going to retain data on the vehicles?

Same way I'm retaining the data without for players and their position using the fn_savestat.
Unless that's completely impossible for vehicles for some reason?

Any help would be appreciated.

Share this post


Link to post
Share on other sites
4 minutes ago, Poppadomus said:

How are you doing it for players and their pos?

I'm using the "call fn_savestat;"
then providing the information required in the savefuncs.sqf file.
Figured it could be possible to do the same for vehicles since player entities and vehicle entities ain't much different.

Anyone know how?

Share this post


Link to post
Share on other sites

You need to be very careful with persistent vehicles, there will be too many to save at once. Having the server save player stats every x seconds is fine as there probably aren't more than 80/100 players at any given time. With vehicles, there could potentially be hundreds or thousands on the map. The best way to persistently save them is to have certain events trigger a save (i.e. exiting a vehicle, damaging a vehicle, altering the inventory). It is unrealistic to have a server save every vehicle that it can detect with nearestObjects

Share this post


Link to post
Share on other sites
16 minutes ago, MrCopyright said:

You need to be very careful with persistent vehicles, there will be too many to save at once. Having the server save player stats every x seconds is fine as there probably aren't more than 80/100 players at any given time. With vehicles, there could potentially be hundreds or thousands on the map. The best way to persistently save them is to have certain events trigger a save (i.e. exiting a vehicle, damaging a vehicle, altering the inventory). It is unrealistic to have a server save every vehicle that it can detect with nearestObjects

Yea I had that in mind, over tasking the server by saving every second for possibly so many vehicles would be mad.
My question is just, how do I execute this and get it to work? As stated, I've been unable to figure out how to make it work, so if anyone knows how to by leaving a script for the required files that would be great. 
Thanks for the link for the nearestObjects btw.
I've read through it already though and simply just don't have the experience to know how to syntax it correctly to save it with the "call fn_savestat;" so I can call the "call fn_loadstat;" when needed on initserver.sqf.
Any guidance to do this, would be greatly appreciated.

Thanks again.

Share this post


Link to post
Share on other sites
12 minutes ago, MrCopyright said:

Where did you obtain the saving function from, is it a part of a save system?

I made extensive searches on the topic and figured it out on my own through that.
I believe most of the code I learned from was found on this forum as well, from others who were asking for help with setting up servers for existing mods.
I simply looked through the code provided and only took what I required.
I should mention that I am educated in the C# language so it's not difficult for me to read.
Just a bit much to look through and get to understand when there's no clear indication on what does what until I figured it out.

If I'm getting this right, it's suppose to look like this right?
_vehicles = vehicles;
nearestObjects [player, ["_vehicles",[_owner,_type,_pos,_dir,_fuel,_damage,_inVeh,_vehID]], 200] call fn_SaveStat; 
or should I use "getposworld" for this?
obviously, saving on exit vehicle instead would be preferable, so I'd be happy with that.

Share this post


Link to post
Share on other sites

Your use of the nearestObjects command is incorrect; it returns an array of objects that match the refining parameters. It is with that array that you would proceed to save each vehicle's stats with forEach, for example. However, I would advise against that method, as previously mentioned, because the server's performance will greatly decrease as more and more vehicles are created. Perhaps you could try to create a 'nearestObjects' vehicle save system and later improve it to a less strenuous version that only saves when needed. In Arma, you learn better when you create a system as you understand the functionality behind it more.

 

Here is a very brief example of what that save system may look like:

_vehicleArray = nearestObjects [[0,0,0], ["Car"], 5000]; // This command will only retrieve cars that are 5000m from the bottom left corner of the map

{
  [] call fn_SaveStat; // I am unsure of how your function works so you will need to pass the desired information to it, such as damage, fuel etc.
} forEach _vehicleArray;

 

Share this post


Link to post
Share on other sites
2 hours ago, MrCopyright said:

Your use of the nearestObjects command is incorrect; it returns an array of objects that match the refining parameters. It is with that array that you would proceed to save each vehicle's stats with forEach, for example. However, I would advise against that method, as previously mentioned, because the server's performance will greatly decrease as more and more vehicles are created. Perhaps you could try to create a 'nearestObjects' vehicle save system and later improve it to a less strenuous version that only saves when needed. In Arma, you learn better when you create a system as you understand the functionality behind it more.

 

Here is a very brief example of what that save system may look like:


_vehicleArray = nearestObjects [[0,0,0], ["Car"], 5000]; // This command will only retrieve cars that are 5000m from the bottom left corner of the map

{
  [] call fn_SaveStat; // I am unsure how your function works so you will need to pass the desired information to it, such as damage, fuel etc.
} forEach _vehicleArray;

 

I haven't defined anything yet, the only things that are defined are of course the player stats structure, the inventory structure etc.
This looks very promising. Never thought of it this way.
I did realize that my code was off the second you posted from before.
So how do I get fuel, damage etc on player exit or maybe on server shutdown even?
As far as I know, the "getout" command isn't used for that, it's suppose to be to order units to exit a vehicle, not to detect when right?

Again, thx for the help so far this means more than you can imagine.

Update:
I've tried pretty much everything and nothing seems to work.
If anyone could guide me with a script that isn't incomplete, that would be amazing.

Just to provide some code, here is what I have, but still ain't working.

save.sqf ( which is repeated every so often. )
_vehicleArray = nearestObjects [[0,0,0],["car"], 100000]; // ( < - I set it to 100000 to test if it was working. )
{
  ["vehicleinfo", [_owner,_type,_pos,_dir,_fuel,_damage,_inVeh,_vehID]]] call fn_SaveStat; // ( < - by all means change the defined statistics to help sort this problem of mine out. )
} forEach _vehicleArray;

This was posted in initserver.sqf
 ["vehicleinfo"] call fn_LoadStat;

So what's wrong here?

Note:
_owner,_type,_pos,_dir,_fuel,_damage,_inVeh,_vehID
These statistics are defined in the savefunchs.sqf, but as far as I know they may not function as intended.
So better just use complete new defined statistics with their own functions if anyone is so kind to help me.

Again, thx in advance.

Share this post


Link to post
Share on other sites

Sorry, I assumed you knew the commands to retrieve the fuel and so forth. It's okay, we can start from the beginning. First of all, you're going to need to bookmark this page, it's like the Holy Bible of scripting. It contains every single command that exists for the Arma 3 engine:

https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

 

If you do not have a save system, I would strongly recommend iniDBi. I use it because it's lightweight, isn't resource intensive on the server (unless you make it intensive) and the response times between the client and the server are lower than if you used an external SQL database. All of the saved files are stored on the server itself, so if you hosted the mission, the files would be stored on your computer. Once iniDBi is placed in the server's installation directory, you'll need to run it as a mod. If you do not know how to do this, let me know.

 

Place this line of code in your mission's init.sqf file:

if (isServer) then {
  call compile preProcessFile "\iniDBi\init.sqf";
};

 

Here is another brief example of how you could use iniDBi to save vehicle stats:

_vehicleArray = nearestObjects [[0,0,0], ["Car"], 5000];

dataArray = [];
{
  _classname = typeOf _x;
  _position = getPos _x;
  _direction = getDir _x;
  _damage = damage _x;
  _fuel = fuel _x;
  
  dataArray pushBack [_classname, _position, _direction, _damage, _fuel];
} forEach _vehicleArray;

["Vehicles", "Data", "Cars", dataArray] call iniDB_write;

 

And this is how you would load the stats of each vehicle:

_dataArray = ["Vehicles", "Data", "Cars", "ARRAY"] call iniDB_read;

{
  _classname = _x select 0;
  _position = _x select 1;
  _direction = _x select 2;
  _damage = _x select 3;
  _fuel = _x select 4;

  _vehicle = _classname createVehicle _position;
  _vehicle setDir _direction;
  _vehicle setDamage _damage;
  _vehicle setFuel _fuel;

  sleep 0.01;
} forEach _dataArray;

 

 

Share this post


Link to post
Share on other sites

You could just learn how to script yourself, get use to the engine command and furthermore learn how inidb works or another extention which allows saving. Such as EXTDB3.

Share this post


Link to post
Share on other sites

I use inidbi2 for persistence, but I am very interested to see where this goes. Personally I prefer not using addons/mods if I don't need them. I would love to see if we can actually gain true mission persistence on a dedicated server without inidbi. Curious what happens after restarts and how the information gets loaded back into the mission.

 

Fire

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, MrCopyright said:

Sorry, I assumed you knew the commands to retrieve the fuel and so forth. It's okay, we can start from the beginning. First of all, you're going to need to bookmark this page, it's like the Holy Bible of scripting. It contains every single command that exists for the Arma 3 engine:

https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3

 

If you do not have a save system, I would strongly recommend iniDBi. I use it because it's lightweight, isn't resource intensive on the server (unless you make it intensive) and the response times between the client and the server are lower than if you used an external SQL database. All of the saved files are stored on the server itself, so if you hosted the mission, the files would be stored on your computer. Once iniDBi is placed in the server's installation directory, you'll need to run it as a mod. If you do not know how to do this, let me know.

 

Place this line of code in your mission's init.sqf file:


if (isServer) then {
  call compile preProcessFile "\iniDBi\init.sqf";
};

 

Here is another brief example of how you could use iniDBi to save vehicle stats:


_vehicleArray = nearestObjects [[0,0,0], ["Car"], 5000];

dataArray = [];
{
  _classname = typeOf _x;
  _position = getPos _x;
  _direction = getDir _x;
  _damage = damage _x;
  _fuel = fuel _x;
  
  dataArray pushBack [_classname, _position, _direction, _damage, _fuel];
} forEach _vehicleArray;

["Vehicles", "Data", "Cars", dataArray] call iniDB_write;

 

And this is how you would load the stats of each vehicle:


_dataArray = ["Vehicles", "Data", "Cars", "ARRAY"] call iniDB_read;

{
  _classname = _x select 0;
  _position = _x select 1;
  _direction = _x select 2;
  _damage = _x select 3;
  _fuel = _x select 4;

  _vehicle = _classname createVehicle _position;
  _vehicle setDir _direction;
  _vehicle setDamage _damage;
  _vehicle setFuel _fuel;

  sleep 0.01;
} forEach _dataArray;

 

 

7 hours ago, MrCopyright said:

@FireWalker you can always use profileNamespace if you wish to keep things unmodded. 


As stated, I'm looking for a script that doesn't use any database structure.
So the commands you gave me ain't of much use since they require inidbi, unless I can tweak it to work with fn_savestat; without the use of any databases such as inidbi.
Not that I don't appreciate the effort you put into it to share it with me though.

Again, thx for the help so far, if you could try and give me some code that works with for instance profilenamespace as you described, which I know work for profile saving, that would be great.
Since I don't know how to do this for vehicles.
I should add that I'm not saving profile information that way, since they will get saved in the arsenal locally and can be altered by the users there if using profilenamespace for inventory gathering.
Just isn't secure enough. 
And the uiNamespace only works while the server is running, once the server is shutdown, all data is lost.
As you can see, I've done my research.

I should note, that I did try and use IniDBi and use your code, but nothing happened using it.
Again, I prefer to save everything without any database use.
Thx again in advance.
 

9 hours ago, Heisen_a said:

You could just learn how to script yourself, get use to the engine command and furthermore learn how inidb works or another extention which allows saving. Such as EXTDB3.

It's not that I haven't tried.
I wouldn't ask if it wasn't because I wanted a simple approach to executing something without the need of having to setup a database structure and so forth every time I need to either relocate it or pickup the project later, as I've done with this over the past several years.
It's the easy to setup easy to use that matters to me.
The easier it is, the quicker my users of my missions/scenarios can enjoy themselves without any hassle.

Share this post


Link to post
Share on other sites

Why are you so opposed to using database mods? There must be a reason for it. They are robust and the benefits far outweigh the negatives.

Share this post


Link to post
Share on other sites
5 hours ago, MrCopyright said:

Why are you so opposed to using database mods? There must be a reason for it. They are robust and the benefits far outweigh the negatives.

It is as stated, that I prefer to be able to simply drop the mission/scenario and just launch it, rather than having to deal with database related environments.
The same thing can be asked of anyone else using the database systems really, why the databases if it can be done without and work just as fine?
The reason is that I don't know how to set them up and in the future I will forget again and to be honest the easier it is, the more can be used even by amatures who've never scripted before.
( As I plan to put my mission files as open source when it's done for others to pick up and do whatever they want with it. )
So if I have the mission stored then everything is all set to go without having to worry about the rest, not to mention that there is absolutely no help on the topic when it comes to using databases either.
And with the amount of time I've spend on trying to figure everything out I'd rather just be able to plug and play, instead of plug and pray.
I wouldn't be asking for help either, if I could find the information else where as I wouldn't want to waste anyone's time on something that is possible to find easily.

If you could help setup the code so we can close this case, I'd be very appreciative. 

Share this post


Link to post
Share on other sites

Can you provide your fn_savestat function? I need to be able to see what parameters the function takes before I can write the code.

Share this post


Link to post
Share on other sites

Well, Revixy does have a somewhat valid point. I'm not a great scripter by any means and it took me quite awhile to get my persistent missions working and they aren't saving "everything" exactly how I want. There isn't a great tutorial on how to set up inidbi or the others, I had to do a lot of bashing. It works flawlessly for my needs, but wasn't "easy" for me to do. Code34 even says himself that the databases are for advanced users, not beginners or occasional scripters.

 

Time is also a contributing factor when it comes to learning the database systems. I don't have much available.

 

That is why I'm also interseted in a more basic/simpler system.

 

I'm certainly going to be following this thread and playing with the saveStat function myself.

 

Fire

  • Like 1

Share this post


Link to post
Share on other sites
17 minutes ago, MrCopyright said:

Can you provide your fn_savestat function? I need to be able to see what parameters the function takes before I can write the code.

I was under the impression that it was a bis function, but I havent found documentation on it. 

Share this post


Link to post
Share on other sites

If you put your mind to it, iniDB really isn't that hard to implement. You run the addon, you add a line to your init.sqf file and then you are free to use the write/read functions. The hardest part is separating the locality of the server and the clients. Ensure that you have the x64 version of iniDBi if you are using the x64 version of Arma 3.

  • Like 1

Share this post


Link to post
Share on other sites

I agree with that. IniDbi has been bullet proof since I got it running. And I can use what I've already done as a template for future missions.

 

But I'm still curious about other methodology also.

 

Fire

Share this post


Link to post
Share on other sites
2 hours ago, MrCopyright said:

If you put your mind to it, iniDB really isn't that hard to implement. You run the addon, you add a line to your init.sqf file and then you are free to use the write/read functions. The hardest part is separating the locality of the server and the clients. Ensure that you have the x64 version of iniDBi if you are using the x64 version of Arma 3.

I disagree.
It's not that simple, if it was I would already be able to do so.
So let me just make this clear, I'm not interested in databases.
If you want to help me make it possible without then please do so, if you want to try and force me to change and use inidbi then, please don't waste your time nor mine.
I'm sorry if that came out direct.
But I can't use the fact that it seems you're stalling the matter.
I need a solution that doesn't involve databases, not an argument and or debate on whether I should use databases or not.
And since there's no code anywhere that seems to indicate to do what I'm looking for, this is the reason I'm here.
I want to make it simple for everyone once the code is done, so everyone can just use it, amatures or pro's alike.
If someone knows how to use databases and want to change the code to support that instead, it's not going to be hard for them, now is it?

  • Like 1

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×