Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Development save tent.

Newbie Spellweaver
Joined
May 17, 2014
Messages
62
Reaction score
9
Today we will try to make the save function tents in the source code Dayz SA.

We already have a function to save the character in module gameStateExt.cpp:

PHP:
GameValue DBServerSaveCharacter(const GameState *state, GameValuePar oper1)
{
  if (!GetNetworkManager().IsServerOwner())
  {
    state->AccessError("dbServerSaveCharacter");
    return false;
  }

  if (oper1.GetType() == GameObject)
  {
    Object *obj = GetObject(oper1);
    Person *person = dyn_cast<Person>(obj);
    if (!person) return false;

    int dpnid;
    if (GetNetworkManager().IsServer())
    {
      dpnid = person->GetRemotePlayer();
      if (dpnid == AI_PLAYER) return false;
    }
    else
    {
      dpnid = 2; // BOT_CLIENT
      if (person != GWorld->PlayerOn()) return false;
    }

    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();

    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSave(document, allocator);

    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);

    RString request = buffer.GetString();

    RString url/*, attrib*/;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save");
//    BuildPlayerUID(attrib,uid);

    return GetNetworkManager().DBSave(url.Data(), dpnid, request);
  }
  else
  {
    DoAssert(oper1.GetType() == GameArray);
    const GameArrayType &array = oper1;
    if (!CheckSize(state, array, 2)) return false;
    if (!CheckType(state, array[0], GameString)) return false;
    if (!CheckType(state, array[1], GameObject)) return false;

    RString uid = array[0];
    Person *person = dyn_cast<Person>(GetObject(array[1]));
    if (!person) return false;

    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();

    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSave(document, allocator);

    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);

    RString request = buffer.GetString();

    RString url, attrib;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save");
    BuildPlayerUID(attrib,uid);

    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  }
}

Copy and rename.

PHP:
GameValue DBServerSaveObject(const GameState *state, GameValuePar oper1)
As you can see in you can pass a function as an object or an array. I am interested in the array. Near the tent unlike the character's no UID, and it should be organized scripts Dayz when creating a tent. We will call the function by passing it an array with two elements: string IDtent and object tent. Delete unnecessary from a function.

PHP:
GameValue DBServerSaveObject(const GameState *state, GameValuePar oper1)
{
    
  if (!GetNetworkManager().IsServerOwner())
  {
    state->AccessError("dbServerSaveCharacter");
    return false;
  }
    
  if (oper1.GetType() == GameArray)
  {    
    
    DoAssert(oper1.GetType() == GameArray);
    const GameArrayType &array = oper1;
    if (!CheckSize(state, array, 2)) return false;
    if (!CheckType(state, array[0], GameString)) return false;
    if (!CheckType(state, array[1], GameObject)) return false;

    RString uid = array[0];
    Person *person = dyn_cast<Person>(GetObject(array[1]));
    if (!person) return false;

    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();

    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSave(document, allocator);

    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);

    RString request = buffer.GetString();

    RString url, attrib;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save");
    BuildPlayerUID(attrib,uid);

    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  }
}

The next step. We need to change the type of the object being saved. It is defined by the line:
PHP:
  Person *person = dyn_cast<Person>(GetObject(array[1]));

Little digging in the source code, we will find the type of object that we need. Write down it. I'm not even going to change the variable names. (a bit lazy)

PHP:
InventoryItem *person = dyn_cast<InventoryItem>(GetObject(array[1]));

Now everything will be stored objects of type InventoryItem. We go further. It retains the status of an "alive", for the tent don't need it. For comment.

PHP:
 //document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);

We were lucky and the class "InventoryItem" also has the function "JSONSave". And here we almost don't want anything to change, but I still its copy and changed (write below).

PHP:
   person->JSONSaveTent(document, allocator);

To distinguish requests the preservation of the character from the query save the tents are changing so:
PHP:
    BuildServerRequest(ESERVLET_CHARACTER,url,"save_obj");

And correct this feature on their:

PHP:
    BuildObjectUID(attrib,uid);

Ultimately, should we would get something like this:
PHP:
GameValue DBServerSaveObject(const GameState *state, GameValuePar oper1)
{
    
  if (!GetNetworkManager().IsServerOwner())
  {
    state->AccessError("dbServerSaveCharacter");
    return false;
  }
    
  if (oper1.GetType() == GameArray)
  {    
    
    DoAssert(oper1.GetType() == GameArray);
    const GameArrayType &array = oper1;
    if (!CheckSize(state, array, 2)) return false;
    if (!CheckType(state, array[0], GameString)) return false;
    if (!CheckType(state, array[1], GameObject)) return false;
    
    RString uid = array[0];

    InventoryItem *person = dyn_cast<InventoryItem>(GetObject(array[1]));
    if (!person) return false;
    
    JSONDocument document;
    document.SetObject();
    JSONAllocator& allocator = document.GetAllocator();
    
    // keep some members outside to be consistent with Load
    document.AddMember("model", cc_cast(person->GetType()->GetName()), allocator);
    //document.AddMember("alive", person->Brain() && person->Brain()->LSIsAlive() ? 1 : 0, allocator);
    person->JSONSaveTent(document, allocator);
    
    JSONBuffer buffer;
    JSONWriter writer(buffer);
    document.Accept(writer);
    
    RString request = buffer.GetString();

    RString url, attrib;
    BuildServerRequest(ESERVLET_CHARACTER,url,"save_obj");
    BuildObjectUID(attrib,uid);
    
    return GetNetworkManager().DBSave(url.Data(),attrib,request);
  } 
  else
  {
    return false;
  }
}

Sorry for my English, used the online translators.
Для русскоязычных людей могу это же изложить на русском, для большей понятности.

p.s.I will not answer questions: how to compile or give an EXE server. Sorry.
 
Newbie Spellweaver
Joined
May 17, 2014
Messages
62
Reaction score
9
We are beginning to publish their modifications of the server exe.


You can learn more at:
 
Newbie Spellweaver
Joined
May 17, 2014
Messages
41
Reaction score
4
Mizev
Thank you saving works. but not with fists hitting melee attacks or other
 
Newbie Spellweaver
Joined
May 17, 2014
Messages
62
Reaction score
9
take away the comment two lines in brain_player_server.fsm (modules_dayz.pbo)
 
Newbie Spellweaver
Joined
May 17, 2014
Messages
62
Reaction score
9
That's not all. I just gave an example to understand this people. There's still a need to write a 5-6 functions, but it will work. On this basis, there are already several servers with saves tents
 
Newbie Spellweaver
Joined
May 25, 2014
Messages
14
Reaction score
0
That's not all. I just gave an example to understand this people. There's still a need to write a 5-6 functions, but it will work. On this basis, there are already several servers with saves tents
Well then,I'd better wait if someone could release a full tutorial of tent saving or a tent saving exe:) By the way,is that 0.47 takes up more memory of the server?Because my server crash more often than 0.46 version.
 
Newbie Spellweaver
Joined
May 29, 2014
Messages
66
Reaction score
6
Yes, some of us are not very good in dev so could someone share an already modified package ?

Just a question : does it means that external saving system (like with wamp or node.js) is not necessary anymore ?
 
Newbie Spellweaver
Joined
Jul 25, 2014
Messages
15
Reaction score
0
Friend gameStateExt.cpp where I can get this file, I buscandoloe days and do not get to make that modification, another question that exe lasts 30 days would be paid as payment for one month not last ??
 
Newbie Spellweaver
Joined
Jan 6, 2014
Messages
12
Reaction score
0
Help help help I have an error At compilation the ERROR goes In person-> JSONSaveTent (document, allocator); And BuildObjectUID (attrib, uid);

Помогите пожалуйста у меня при компиляции выскакивает ошибка связана с JSONSaveTent (document, allocator); и BuildObjectUID (attrib, uid);



2>gameStateExt.cpp(17254): error C2039: 'JSONSaveTent' : is not a member of 'InventoryItem'
2> d:\v1.4.4\lib\Inventory/inventory.hpp(239) : see declaration of 'InventoryItem'
2>gameStateExt.cpp(17264): error C3861: 'BuildObjectUID': identifier not found
 
Newbie Spellweaver
Joined
Nov 29, 2014
Messages
40
Reaction score
8
I'm assuming gameStateExt.cpp is going with the compiling resource code for the server EXE right?
 
Newbie Spellweaver
Joined
Dec 30, 2014
Messages
12
Reaction score
2
Где можно скачать сурс код?

Where can I download source code?
 
Newbie Spellweaver
Joined
Nov 29, 2014
Messages
40
Reaction score
8
Today we will try to make the save function tents in the source code Dayz SA.

Mizev, can you answer to this question:
How exactly the DBServerSaveObject is called and what value does it return?


Array
DBServerSaveObject string
Array DBServerSaveObject Bool
Array DBServerSaveObject Anything
 
Newbie Spellweaver
Joined
May 17, 2014
Messages
62
Reaction score
9
False - if the parameters of the function if not an array or object does not exist.
Otherwise, "string" - the result of a query
 
Newbie Spellweaver
Joined
Nov 29, 2014
Messages
40
Reaction score
8
Ok so if I've unerstood it right, DBServerSaveObject take info from an Array and returns a string to save in the JSON
 
Newbie Spellweaver
Joined
Jul 7, 2014
Messages
57
Reaction score
11
And easy enough to check :)
_ok = DBServerSaveObject(_state,_parameters);
if (typeName _ok == "STRING") then { ...
 
Last edited:
Back
Top