Saving via Script or Entity

Post your Feature Requests here...
Post Reply
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Saving via Script or Entity

Post by Juutis »

I think this hasn't been posted yet, and now that it has come up again, I decided to post it.

Would it be possible to add an entity that saves the game?
Or a script command that saves/loads the game...?

Then it would be possible to autosave, which would be an extremelly useful feature in RF.
Pain is only psychological.
User avatar
paradoxnj
RF2 Dev Team
Posts: 1328
Joined: Wed Mar 01, 2006 7:37 pm
Location: Brick, NJ
Contact:

Post by paradoxnj »

I would probably be better to do a timer registry than use an entity. Timer registry would allow you to register a timed event (recurring or single) with a script function. I don't know if RF has this already, but it's the cleanest way to do an autosave and would be very dynamic also. You probably can implement a poison spell using the same thing.
Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay »

Yes this is possible with scripting. Implementing a timer works almost like in C/C++ :wink:

I would like to have the feature to script the save/loading system, too. I mean, you come to a new area and the game automatically saves your game. Or you get Save-Cards which you then have to use to save your game - an interesting feature because you can only save a few times and not save yourself trough the game. It's more challenging.

You could make your own menu which is in fact a level where you can click on, say a bookshelf, to save a game, then on the bookshelf there will be medals that represent the games saved and by clicking on them you can load them. You could even go further and say that when you exit the room, you start a new game and then when you click on the bed you exit it.
Everyone can see the difficult, but only the wise can see the simple.
-----
User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico »

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. :wink:
Post Reply