Aller au contenu

Photo

(SOLVED) Autosave via trigger - script ?


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
gentleman2rogue

gentleman2rogue
  • Members
  • 8 messages
Is there a way to set up an auto save on a trigger's "on enter" or through other means such as in a conversation?

Modifié par gentleman2rogue, 17 août 2010 - 11:02 .


#2
Shadooow

Shadooow
  • Members
  • 4 468 messages
What do you mean about "auto save"? Is that MP or SP?

#3
Fester Pot

Fester Pot
  • Members
  • 1 393 messages
Here is an autosave function you can use for your single player adventure by adding it to an already existing script.

DoSinglePlayerAutoSave();


Just place that function in a trigger or the area's OnEnter and it will autosave the game at that very moment. The player can then simply reload the autosave and continue where it was last saved by the game. Additionally, the player can also save manually themselves.

FP!

Modifié par Fester Pot, 16 août 2010 - 07:58 .


#4
Genisys

Genisys
  • Members
  • 525 messages
Yes, you identify the PC with..

object oPC = GetEnteringObject(); //For Tracks Triggers OnEnter

object oPC = GetPCSpeaker(); //From Conversation..

Make sure you use this after the above...

//Prevent this script from running on NPCs/Monsters/& DMs
if(!GetIsPC(oPC) || GetIsDM(oPC) || GetIsDMPossessed(oPC))
{ return; } //Stop here


The best way to handle Autosave is to just loop a script (refire it) every so often, saving ALL of the PCs based upon if it's Single Player or a Multiplayer Module, you would fire this from the OnModuleLoad Event.... (Provided they are NOT Polymorphed & NOT between areas...)

I have this script somewhere, let me go dig it out for you...

//script name:   savepcinfo
////////////////////////////////////
//Created by Genisys / Guile 6/14/08
////////////////////////////////////
/*
   This script will save ALL the characters on the module every X Minutes (You Set Below How Often)
    If the PC is NOT between areas and NOT Polyrmorphed (A NWN Bug)
*/
////////////////////////////////////
//This checks to see if the player is polymorphed...
int IsShifterMorphed(object oPC);

void main()
{

/////////SAVE LOCATION TIMER OPTION/////
//Change 180.0 to the amount of time (in seconds) that you want this script to refire
//180.0 = 3 minutes... (you can use less time)

DelayCommand(180.0, ExecuteScript("savepcinfo", OBJECT_SELF));

///////////////////////////////////////////////////////////////////////
object oPP;
string sName;
location lSaved;
object oGuild;
object oArea;
int MULTI = GetLocalInt(GetModule(), "multi"); //This needs to be set in the OnModuleLoad Event
oPP = GetFirstPC();
while(GetIsObjectValid(oPP))
{
//Make sure the area if valid!
oArea = GetArea(oPP);

//If the PC is not polymorphed save their character as well!
if(IsShifterMorphed(oPP))
{
if(oArea !=OBJECT_INVALID)
{
if(MULTI)
{
DelayCommand(0.3, ExportSingleCharacter(oPP));
SendMessageToPC(oPP, "Your Character was Saved");
}
//Otherwise it's a single player module, do this instead..
else
{
DoSinglePlayerAutoSave(); //Saves the Game...
//You can export character, however they will have a lot of character in their vault, not good!
}
}
else
{
SendMessageToPC(oPP,"Your character were NOT saved because you were between areas!");
}

}
else
{
SendMessageToPC(oPP,"Your character were NOT saved because you were polymorphed!!");
}

oPP = GetNextPC();
}

//End Script
}


//PROTOTYPE DEFINED
int IsShifterMorphed(object oPC)
{
effect ef = GetFirstEffect(oPC);
int iShifter = TRUE; //Default, they are NOT polymorphed
int n;
//if (GetLevelByclass(class_TYPE_DRUID,oPC)>0) //Is Shifter, search the PolyEff
while( GetEffectType(ef) != EFFECT_TYPE_INVALIDEFFECT && iShifter == TRUE)
{
n = GetEffectType(ef);
if ( n == EFFECT_TYPE_POLYMORPH )
iShifter = FALSE;

ef = GetNextEffect(oPC);
}

if(GetHasSpellEffect(SPELL_POLYMORPH_SELF, oPC))
{ iShifter = FALSE; }

return iShifter;
}



Now, in the OnModuleLoad Event, you need to set if it's a multiplayer module or not..

//Set this to FALSE for Single Player....
SetLocalInt(GetModule(), "multi", TRUE);      //TRUE = it is Multiplayer


Of course you can check to see if the module is set up for single or multiplayer in other scripts as well by using this integer...

//Place this AFTER void main() {  near the top }
int nMultiPlayer = GetLocalInt(GetModule(), "multi");

if(nMultiPlayer)  //if it's a multiplayer Game
{
   //do this..
}
else  //It's a single player module..
{
   //Do this instead.
}

Modifié par Genisys, 16 août 2010 - 09:13 .


#5
gentleman2rogue

gentleman2rogue
  • Members
  • 8 messages
Thank you gentleman!

Fester was right on the money - guess if I had dug further into the Lexicon, I would have found it.



Goes something like this:



// An area you want the singleplayer game to save in, this will

// save it once.



void main()

{

int nDone = GetLocalInt(OBJECT_SELF, "ON_ENTER_SAVE_ONCE");



// Check if we have done it already or not.

if(nDone == FALSE)

{

// So the save

DoSinglePlayerAutoSave();



// Do not do again

SetLocalInt(OBJECT_SELF, "ON_ENTER_SAVE_ONCE", TRUE);

}

}


#6
Fester Pot

Fester Pot
  • Members
  • 1 393 messages

gentleman2rogue wrote...

Fester was right on the money - guess if I had dug further into the Lexicon, I would have found it.


Yup. No need for complexity when a single line of code will do the job you were asking for.

Enjoy!

FP!

Modifié par Fester Pot, 17 août 2010 - 11:26 .


#7
Genisys

Genisys
  • Members
  • 525 messages

Fester Pot wrote...

gentleman2rogue wrote...

Fester was right on the money - guess if I had dug further into the Lexicon, I would have found it.


Yup. No need for complexity when a single line of code will do the job you were asking for.

Enjoy!

FP!


lol...