- Joined
- May 17, 2014
- Messages
- 62
- Reaction score
- 10
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:
Copy and rename.
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.
The next step. We need to change the type of the object being saved. It is defined by the line:
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)
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.
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).
To distinguish requests the preservation of the character from the query save the tents are changing so:
And correct this feature on their:
Ultimately, should we would get something like this:
Sorry for my English, used the online translators.
Для русскоязычных людей могу это же изложить на русском, для большей понятности.
p.s.I will not answer questions: how to compile or give an EXE server. Sorry.
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)
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.