Home   Help Search Login Register  

Author Topic: How do servers save players info for games like Sahrani life and evolution?  (Read 10218 times)

0 Members and 1 Guest are viewing this topic.

Offline D007

  • Members
  • *
I would really like to add this capability to games I make and host.
Could someone please point me in the right direction?

I spent like 5 hours looking for things regarding this issue, but either im blind.
Or there just isn't much about it XD.

I just want to save players money and nothing else.
I hope thats not to to hard.

so yea.. anyone got a link,script, editable mission? lol.. anything..
a direction you can point me in to get what I'm looking for maybe?
I'd appreciate it.. thank you.

Offline ModestNovice

  • Members
  • *
I HAVE BEEN LOOKING for this FOR EVER as well, yet no luck either  :dunno:


I have had a look in Evo, but this relies on an Array.

The only big thing I know is :
OnPlayerConnected...

has something to do with it.

Code: [Select]
_name = _this select 0;//Get the name of the player to find stats
pscore = 0;//Set Score to 0
_max = count scores;//Count the score from the array
_i = 0;//Set sumthin here xD

//_i less then the count from array, add to your score
while {_i < _max} do {_unit = scores select _i;if (_unit == _name) then {pscore = (scores select (_i+1))};_i = _i + 2;}

allvar = [end,opar,osom,ocay,oort,ocor,obag,oobr,oepo,omas,opit,odol,lives];
allvar_packed = str (allvar);


Spooner? Mandoble? Wolfrug?

Any ideas?
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline D007

  • Members
  • *
yep..lol...

All I have been able to find out is that you need another folder that is saved independently of the game.
A folder that is not part of arma but arma uses it for saves.
So when the server restarts, they use that folder again and it initiates the get player Id script and so forth.

I herad that there may be problems with duplicated Id's however making two people with the same id's information overwrite each others when they log on.
I wish people could be more willing to help people like us out..lol..
I mean why make such an awesome script then hang onto it just for yourself and your maps?
Pretty selfish if you ask me.
everything I make goes to a pbo then armaholic or anyone who even asks me.. hell I'll even email people who ask me for things personally..
I know someone has a script all written out and directions on where to put what folders and how to reference them etc etc etc..
but their just holding onto it..
all that animosity between great maps and great mission makers is just hurting the arma community..
wish more people would be less selfish.
but I'll keep digging and If i ever do see anything I will let ya know asap.



« Last Edit: 03 Sep 2008, 00:29:28 by D007 »

Offline ModestNovice

  • Members
  • *
appreciate it.

Will do the same  ;)
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline D007

  • Members
  • *
Can anyone maybe point us in the right direction on how to do this? lol.
Would very much appreciate it. :)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
You are both asking entirely different questions:
* DaChevs: How to save a player's data between player logins in a single mission, as used by Sahrani Life and Evolution. For a start, it is usual to set the mission as persistent ("persistent=1;" in description.ext) so that the mission won't end if all the players logged off. Otherwise, when you returned later, the data would have been lost anyway when the server started the mission the second time. This is best done with publicVariable as you suspected. There is no absolute connection with onPlayerConnected, though you could use that to help determine when a new player has connected. There isn't a simple "plug-and-play" script for doing this, or I would give it to you. I never got around to doing it for SPON Money, or I would point you in that direction ;P

* D007: How to save data between different missions, including when a mission is restarted on a server. For this, look towards ArmALib but be aware that this requires an exe running on the server, so is not generally useful for most mission developers, unless they have a dedicated server to use for it (that is why I've not even bothered looking at it...).

Quote from: D007
I mean why make such an awesome script then hang onto it just for yourself and your maps?
Pretty selfish if you ask me.

Well, for one, you are asking about between-mission recording, not between-logins-in-the-same-mission recording. Nevertheless, people making missions like SL and Evo write their scripts specifically for those missions and it can be a non-trivial to unhook these scripts and port them across to other missions. As someone who writes generic scripts, I can tell you that there is at least twice as much work involved in making, documenting and releasing a script which will work in any mission compared to making one that will only work for you in your own mission. However, there is nothing stopping you backwards engineering how they did it, and replicating that, or even asking the authors.
« Last Edit: 24 Aug 2008, 19:14:41 by bedges »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
These mods both use DSTS to save data server side. This external app is great for many applications. I have used it to dump position data from artillery to calculate trajectories.

Added event handler to artillery that calls this script:
Code: [Select]
_missile = nearestObject [vehicle player, _this select 4];
if (isNull  _missile)  exitWith {};
g_type = typeOf _missile;

g_wdir =  (_this select 0) weaponDirection (_this select 1);
g_theta = (g_wdir select 0) atan2 (g_wdir select 1);
g_phi = 90 - acos (g_wdir select 2)/sqrt((g_wdir select 0)^2+(g_wdir select 1)^2+(g_wdir select 2)^2);
g_initialpos = [(getPosASL vehicle player) select 0, (getPosASL vehicle player) select 1, 0];

hint format ["%1\n%2\n%3 %4", velocity _missile, g_type, g_theta, g_phi];

g_time = [];
g_wind = [];
g_vel = [];
g_vectorUp = [];
g_vectorDir = [];
g_pos = [];
g_time = [];
while {not isNull  _missile} do
{
   g_time = g_time + [time];
   g_vel = g_vel + [velocity _missile];   
//   g_wind = g_wind + [wind];   
//   g_vectorUp = g_vectorUp + [vectorUp _missile];   
//   g_vectorDir = g_vectorDir + [vectorDir _missile];
   g_pos = g_pos + [getPosASL _missile];   
   sleep 0.01;
};
hint format ["%1", count g_pos];
[] exec "writedata.sqs"

writedata.sqs
Code: [Select]
_data = format ["#%1 %2 %3 %4",g_type,g_theta,g_phi,g_initialpos]
_result = loadfile format ["::FILE WRITE ""C:\TEMP\TEST04.TXT"" ""FALSE"" ""%1""", _data]
_n = count g_pos
_i = 0
#loop
   _data = format [" %1  ", g_time select _i]
   _str = format [" %1 %2 %3 ", g_pos select _i select 0, g_pos select _i select 1, g_pos select _i select 2]
   _data = _data + _str
   _str = format [" %1 %2 %3 ", g_vel select _i select 0, g_vel select _i select 1, g_vel select _i select 2]
   _data = _data + _str
;   _str = format [" %1 %2 %3 ", g_wind select _i select 0, g_wind select _i select 1, g_wind select _i select 2]
;   _data = _data + _str
;   _str = format [" %1 %2 %3 ", g_vectorUp select _i select 0, g_vectorUp select _i select 1, g_vectorUp select _i select 2]
;   _data = _data + _str
;   _str = format [" %1 %2 %3\n", g_vectorDir select _i select 0, g_vectorDir select _i select 1, g_vectorDir select _i select 2]
;   _data = _data + _str
   _i=_i+1
   _result = loadfile format ["::FILE WRITE ""C:\TEMP\TEST04.TXT"" ""TRUE"" ""%1""", _data]
~0.00001
if (_i < _n) then {goto "loop"}
hint "done"
Because ArmA caches sqf scripts, you must use sqs scripts, or a sqf hack described on the DSTS forum. The applications are limitless. For example Spooner could hook it into his logger and dump an actual log file. The only hitch IIRC is whether you can detect via script that DSTS is available. A try-catch block could be used to do this.
« Last Edit: 24 Aug 2008, 21:23:26 by Mr.Peanut »
urp!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Yes, DSTS is a system that predated ArmALib, but is pretty limited in comparison. I didn't realise that SL and Evo had implemented DSTS hooks in the standard mission though (Certainly, most people playing those missions won't be doing it on DSTS-equipped servers and will just be using the simple publicVariabled data recording). Sorry for misleading there...

try-catch doesn't work as you'd expect. Catch only catches variables that you have thrown manually via throw. It has nothing to do with ArmA's internal error system.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline ModestNovice

  • Members
  • *
ah right, I suspected, and actually found this DSTS but really had no idea how to use it. But, only one question is, since it writes a file into a folder, isnt possible for someone to go in there and change the value, and when they connect they have billions of dollars??? :scratch:


Whoops! ...Stupid DaChevs, the files would be on the server  :-[
« Last Edit: 25 Aug 2008, 00:38:09 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline D007

  • Members
  • *
You are both asking entirely different questions:
* DaChevs: How to save a player's data between player logins in a single mission, as used by Sahrani Life and Evolution. For a start, it is usual to set the mission as persistent ("persistent=1;" in description.ext) so that the mission won't end if all the players logged off. Otherwise, when you returned later, the data would have been lost anyway when the server started the mission the second time. This is best done with publicVariable as you suspected. There is no absolute connection with onPlayerConnected, though you could use that to help determine when a new player has connected. There isn't a simple "plug-and-play" script for doing this, or I would give it to you. I never got around to doing it for SPON Money, or I would point you in that direction ;P

* D007: How to save data between different missions, including when a mission is restarted on a server. For this, look towards ArmALib but be aware that this requires an exe running on the server, so is not generally useful for most mission developers, unless they have a dedicated server to use for it (that is why I've not even bothered looking at it...).

Well, for one, you are asking about between-mission recording, not between-logins-in-the-same-mission recording. Nevertheless, people making missions like SL and Evo write their scripts specifically for those missions and it can be a non-trivial to unhook these scripts and port them across to other missions. As someone who writes generic scripts, I can tell you that there is at least twice as much work involved in making, documenting and releasing a script which will work in any mission compared to making one that will only work for you in your own mission. However, there is nothing stopping you backwards engineering how they did it, and replicating that, or even asking the authors.


Lol I'm sure you looked at sahrani lifes files then.
I have, extensively.. they made that mission and the files there in intentionally hard to decipher.
Their file system and referencing system are so in depth.
that if you didn't start as a mission maker for that mission, it will take you a week just to find out what the layout is like and how to access things in any sort of timely manner..lol

City life was however very kind in their methods :).
thank you city life..lol..

I spent weeks looking at those SL files. XD..
Believe me it's not that I haven't tried to reverse engineer it..
I wouldn't be here asking the "how do i" question If I hadn't first tried to do it myself.
I know a lot of people come here and just ask people to write scripts for them but that's not the way I work.

If I ask any question here, you can bet for at least 24 hours of actual work time.
I have tried to get that particular script working lol..
Usually more like 2 days pass before I ask anyone anything.
way I see it is if you don't rack your brain learning it, you will never retain the info you learned anyway.
getting info easy, just lets you forget it easy. :P..

saving info just for one mission, until the server restarts, would be just fine for starters though..
I'm just trying to make it easy servers who get the missions my brother and I make.
So they and I, can easily incorporate the save script.
It's just a great piece of rpg

But I have checked forms and biki and wiki and Bi and comref and and..lol..
I'm just stumped..


Thanks for all the hard work you must of put into the spon script by the way.
Huge benefit things like that give the community.
Works like a charm for Quarantine Unleashed.
and you didn't horde it all for yourself..lol..

thank you guys very much for your insight.
I Will look into all of these methods..
If anyone has a script that might show an example I'd sure appreciate it but np if not.
We'll just wee what we can see.
« Last Edit: 25 Aug 2008, 10:12:42 by D007 »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Might be I was wrong about Sahrani Life, but I am fairly certain Evo was made in part  as a demonstration of DSTS. Without an external app you cannot safeguard persistent data if the server goes down.

@Spoon:
Quote
try-catch doesn't work as you'd expect. Catch only catches variables that you have thrown manually via throw. It has nothing to do with ArmA's internal error system.
How is it used if it is not used for error trapping?

@D007:If you want data saved between logins for a continuous mission, you first need to decide what data you want saved. You then create an array for each player holding the name of the player and the data you want. You then make another larger array containing all the arrays for each player. You will have two such arrays. One for the players connected, and one for players who have disconnected. According to the ComRef the onPlayerDisconnected passes a variable _name to the script called, which I presume is the players name (but I have not tested this). So whenever a player disconnects you remove the subarray with their data from the players connected array, and add it to the players disconnected array. When that player reconnects you do the opposite. When a new player connects you add a new entry for them in the player connected array.

In your init.sqf you call a script only on the server. That means this script will only be run once, on the server, when the mission is first started. This script creates the player connected array, and fills it with your initial values for each player and publicVariables it.

The final step is to make sure the the player connected array is synchronised between all clients and the server. Since the publicVariable command now works with strings and arrays, I think all you need to do is publicVariable the player connected array each time it is change either on the server or on a client. Overuse of the publicVariable command can cause network lag, so make sure you use it only when required.

This is how I would approach the situation. External apps like ArmALib and DSTS need only be run on the server. They allow data storage in an SQL type database. Even if using them you would need to build a system to manage, synchronise and save your data.

Final word. If your data is not shared between clients (e.g. Bob does not need to know how much money Karl has) you don't need to publicVariable the whole player connected array, but you have to create a way for each client to update their data on the server within the player connected array. This adds another level of complication.

This probably does not help much, and writing it I see the need for such a system to be submitted to ofpec. But it won't be by me...  :whistle:

« Last Edit: 25 Aug 2008, 16:10:49 by Mr.Peanut »
urp!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
It isn't useful for managing ArmA's internal errors, but it could be used to make your own error management system:
Code: [Select]
try
{
    // Do stuff
    if (not (_fish in _allowedValuesOfFish)) then { throw "Bleh! Fish is not right!" };
    // Do more stuff, which will not happen if something is thrown before this.
}
catch
{
   hint _exception;
};

This is actually exactly the way try/catch/throw works in vanilla C/C++. It is only in higher level languages, such as C#, Java or Python, or when C/C++ is extended (e.g. to Visual C++ or Borland C++) that exception management works as you are probably used to.

I'm sure the original Evo pre-dated DSTS (or at least had nothing to do with it), though I'd not be surprised if the the latest official, or third-party, versions used DSTS, since true persistence in Evo would be a good example of what you can achieve with DSTS.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline D007

  • Members
  • *
wow thats more to sink my teeth into than I realized.  ???

I'll have to give it a shot.. Just trying to save spon's cash really is all.
Will be an adventure for sure..lol..
At least I have an understanding of the depth
and necessities I need to look into.

If there are any scripters who might want to help with this for Quarantine Unleashed,
I'd sure appreciate it.
It's something I could learn to do.
I'm sure in time and by looking at existing files.
But learning from scratch is going to take a bit of time.
All of my time is currently consumed by updating the new releases :(.

Worse comes to worse I'll get into it when I can
and situate it for Quarantine Unleashed.
V1.1 coming out very soon, with lots of good new stuff.

But that's a bunch of great info.
Thank you :).


Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Well, I started to poke around at this and realised half the crap I was trying to do was already in SPON_CORE(i.e. updated arrays of players, players' names, unique ids). At that point I stopped. Spooner could easily throw something like this together (i.e. mission persistent player data array with keyword index) in no time.
« Last Edit: 26 Aug 2008, 02:23:03 by Mr.Peanut »
urp!

Offline ModestNovice

  • Members
  • *
rofl  :D

Spooner, you got some splainin to do!

jkjk, yeh, the DSTS is not that bad, but how do install the exe on my server????

And he says something about like Net 1.1, or DSTS will not work, BUT he doesnt even say what Net is  :weeping:
Im so confused... :(
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley