I've modified RF to have a Save/Load feature for all the pawns attributes. My idea is to set up an Order to Save all the Entity attributes while saving and an Order to load all the Entity attributes while loading. I post the code if someone wants to integrate it in the current RF build.
In CPlayer.cpp I added:
Code: Select all
int CPlayer::LoadAttributesEntity(char *szSaveFile, char *MyEntityName)
{
FILE *theFile = CCD->OpenRFFile(kInstallFile, szSaveFile, "rb");
if(theFile == NULL)
{
char szError[256];
sprintf(szError, "File %s - Line %d: Failed to LoadAttributes from '%s'",
__FILE__, __LINE__, szSaveFile);
CCD->ReportError(szError, false);
return RGF_FAILURE;
}
geActor *MyActor = CCD->ActorManager()->GetByEntityName(MyEntityName);
m_Attr = CCD->ActorManager()->Inventory(MyActor);
m_Attr->RestoreFrom(theFile, false);
fclose(theFile);
return RGF_SUCCESS;
}
int CPlayer::SaveAttributesEntity(char *szSaveFile,char *MyEntityName)
{
FILE *theFile = CCD->OpenRFFile(kInstallFile, szSaveFile, "wt");
if(theFile == NULL)
{
char szError[256];
sprintf(szError, "File %s - Line %d: Failed to SaveAttributes to '%s'",
__FILE__, __LINE__, szSaveFile);
CCD->ReportError(szError, false);
return RGF_FAILURE;
}
geActor *MyActor = CCD->ActorManager()->GetByEntityName(MyEntityName);
m_Attr = CCD->ActorManager()->Inventory(MyActor);
m_Attr->SaveTo(theFile, false);
fclose(theFile);
return RGF_SUCCESS;
}
in CPlayer.h
Code: Select all
int SaveAttributesEntity(char *szSaveFile, char *EntityName); // Save inventory and attributes
int LoadAttributesEntity(char *szSaveFile, char *EntityName); // Load inventory and attributes
in CCommonData.cpp
you must add the commands in the AddHash list and then in CPawnLow.cpp using the same hash number (mine was 215 and 216)
Code: Select all
case 214: // else if (IS_METHOD(methodName, "SaveAttributesEntity"))
{
PARMCHECK(2);
strcpy(param0, arguments[0].str());
strcpy(param4, arguments[1].str());
CCD->Player()->SaveAttributesEntity(param0,param4);
return true;
}
case 215: // else if (IS_METHOD(methodName, "LoadAttributesEntity"))
{
PARMCHECK(2);
strcpy(param0, arguments[0].str());
strcpy(param4, arguments[1].str());
CCD->Player()->LoadAttributesEntity(param0,param4);
return true;
}
Just to give you an hint about the use, I created a folder called Attributes where the attributes file must be written. Then I add all the attributes I need at the starting of the script. for example:
AddAttribute("State", 0, 10,EntityName); // 0 ok 1 disabled 2 removed
AddAttribute("PosX", 0, 9000,EntityName); // position
AddAttribute("PosY", 0, 9000,EntityName);
AddAttribute("PosZ", 0, 9000,EntityName);
AddAttribute("PropertyState", 0, 1,EntityName); //for example the oil lamp is on
AddAttribute("PropertyQuantity", 0, 100,EntityName); //for example how much oil lamp remains
then I can save the attributes using the SaveAttributesEntity command. something like:
SaveAttributesEntity("Attributes/" # EntityName # ".ini", EntityName);
and to load it using:
LoadAttributesEntity("Attributes/" # EntityName # ".ini", EntityName);
I think that this is a start but I think that a more radical solution is needed.
the point is to modify the SaveTo and RestoreFrom part of the CPawn and call it in the CMenu SetSlot()/GetSlot() functions. This would be more radical and effective.
I hope this helps.