logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Saving and Spawning Persistent Placeables
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Thu Mar 29, 2007 23:36    Post subject: Saving and Spawning Persistent Placeables Reply with quote

What I'm trying to do is save many placeables' locations into the database and then when the module loads, all of the saved placeables are spawned at each of the locations.

Can someone explain how to do this? I tried using GetPersistentLocation but it needs me to designate an object to be spawned, which should be in the database as well.

I'm sort of clueless about these NWNX functions but I have done a bit of scripting using the normal functions so I can learn quickly.

Any help is appreciated!
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Fri Mar 30, 2007 1:56    Post subject: Reply with quote

This isn't something you really need the database for, unless you plan to change the locations. Could you elaborate a little more on what you are doing and why?
Funky
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Fri Mar 30, 2007 2:17    Post subject: Reply with quote

I am creating a system that allows players to create their own placeables within the game world. I have a good chunk of it done but I can't figure out how to store the placeables they create persistently and then load them after a server restart.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Mar 30, 2007 7:59    Post subject: Reply with quote

Hi, i can solve your problem.

Well, there is 1 thing you need to do. Create conditions to be able to create GetFirst/NextAreaInModule() function. There is two way to do it: 1) give to every area waypoint with certain tag you will then checking
2) I created these functions for letoscript, if you have letoscript in your PW i can post it to you.


Algoritm:

Player create placeable - you store on area location of placeable and resref.

In module load you get all areas by getfirst and next and then you can retrieve variables stored on area. Then you can create it.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
FunkySwerve



Joined: 02 Jun 2005
Posts: 377

PostPosted: Fri Mar 30, 2007 8:37    Post subject: Reply with quote

Could you post the GetFirst/Next for letoscript please? Virusman is working on that for his events fumctions, but it'd be nice to have in the meantime.
Thanks,
Funky
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Mar 30, 2007 9:45    Post subject: Reply with quote

Note: This is nwscripted function.
I posted it as soon I will at home.

If GetFirstArea is used first, I retrieve arealist from module.ifo and then for each area (there is resref) open .are and retrieve tag which i store to "stringlist" ("tag|tag|"). First and next function then retrieve tag from this stringlist.

Well, I now know why I didn't post it to nwvault. I shall have to translate and rework stringlist function becose I give it other name and it returns from stringlist struct.Int,.String,.Float ...
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Mar 30, 2007 9:48    Post subject: Reply with quote

And tip:

I think is best way in OnModuleLoad event SignalEvent for each area - custom defined event for this reason, I call it OnRestart. But you should have Moneo for add all areas customdefined event.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Fri Mar 30, 2007 20:24    Post subject: Reply with quote

Yes, I have the letoscript plugin, and would love to have the functions you created if you don't mind posting! Smile

Thanks for the help!
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Mar 30, 2007 22:13    Post subject: Reply with quote

No I help you willingly Smile I like that people using my stuff (that's why I've got nwn PW).

I add my List function too, becose GetFirst/NextAreaInModule needs it. I hope you'll find it useful too!

few functions and constants from my include, name it anyhow
Code:
#include "leto_include"

const int VARIABLE_TYPE_VARIANT = 0;
const int VARIABLE_TYPE_INT = 1;
const int VARIABLE_TYPE_FLOAT = 2;
const int VARIABLE_TYPE_STRING = 3;

const string MODULE_FILE_NAME = "GwainTharr.mod"; //don't forget to REPLACE this

struct list
{
int Int;
float Float;
string String;
string Variant;
};

//This function returns first area in module, i recommend to use it firstly at
//OnModuleLoad to initialize area string list from letoscript
//Note: Make sure you set up MODULE_FILE_NAME constant!
//Needs letoscript
object GetFirstAreaInModule();

//This function returns next area in module
//Note: Make sure you set up MODULE_FILE_NAME constant!
//Needs letoscript
object GetNextAreaInModule();

//This function will create list which is string of this formate: "3hi|3hello|"
//Also return a stringlist string you can input to ListGetFirst/NextVariable
//Note you always have got same delimiter
//nType - VARIABLE_TYPE_*
//sValue - value of your variable in string formate (so you must use IntToString etc.)
string ListCreate(int nType, string sValue, string sDelimiter="|");

//This function adds to already existing list new variable of chosen type
//Note you using same delimiter which is used in existing list
//sList - return of ListCreate
//nType - VARIABLE_TYPE_*
//sValue - value of your variable in string formate (so you must use IntToString etc.)
string ListAddVariable(string sList, int nType, string sValue, string sDelimiter="|");

//This function returns list structure from first value in inputed list.
//You should know which type of variable is there stored
//Note that if you use other type then VARIABLE_TYPE_VARIANT if add in front of
//value that indicate type, so if you have list like "hello|world|" only, use
//Variant for correct values!
//For not so skilled users use this syntax to get values:
//struct list l = ListGetFirstVariable(sList);
//string v = l.Variant;
//int n = l.Int;
//float f = l.Float;
//string s = l.String;
struct list ListGetFirstVariable(string sList, string sDelimiter="|");

//This function returns list structure from netxt valuee in inputed list.
//You should know which type of variable is there stored
//Note that if you use other type then VARIABLE_TYPE_VARIANT if add in front of
//value that indicate type, so if you have list like "hello|world|" only, use
//Variant for correct values!
//For not so skilled users use this syntax to get values:
//struct list l = ListGetNextVariable(sList);
//string v = l.Variant;
//int n = l.Int;
//float f = l.Float;
//string s = l.String;
struct list ListGetNextVariable(string sList, string sDelimiter="|");

//Returns value of number variables stored in list
int ListGetVariablesCount(string sList, string sDelimiter="|");

//Returns TRUE if is list structure (ListGetFirst/NextVariable) is valid, FALSE
//otherwise.
int GetIsListValid(struct list l);

int GetIsListValid(struct list l)
{
 if(l.Int!=0)
 {
 return TRUE;
 }
 else if(l.Float!=0.0)
 {
 return TRUE;
 }
 else if(l.String!="")
 {
 return TRUE;
 }
 else if(l.Variant!="")
 {
 return TRUE;
 }
 else
 {
 return FALSE;
 }
}

string ListCreate(int nType, string sValue, string sDelimiter="|")
{
 if(nType==VARIABLE_TYPE_INT && sValue=="0")
 {
 nType=VARIABLE_TYPE_STRING;
 }
string sType;
 if(nType!=VARIABLE_TYPE_VARIANT)
 {
 sType = IntToString(nType);
 }
return(sType+sValue+sDelimiter);
}

string ListAddVariable(string sList, int nType, string sValue, string sDelimiter="|")
{
 if(nType==VARIABLE_TYPE_INT && sValue=="0")
 {
 nType=VARIABLE_TYPE_STRING;
 }
string sType;
 if(nType!=VARIABLE_TYPE_VARIANT)
 {
 sType = IntToString(nType);
 }
return(sList+sType+sValue+sDelimiter);
}

int pomocna;

struct list ListGetFirstVariable(string sList, string sDelimiter="|")
{
struct list l;
pomocna = 2;
int typ = StringToInt(GetStringLeft(sList,1));
int oddelovac = FindSubString(sList,sDelimiter);
string sValue = GetSubString(sList,1,oddelovac-1);
 switch(typ)
 {
 case VARIABLE_TYPE_INT:
 l.Int = StringToInt(sValue);
 break;
 case VARIABLE_TYPE_FLOAT:
 l.Float = StringToFloat(sValue);
 break;
 default:
 l.String = sValue;
 break;
 }
l.Variant = GetStringLeft(sList,oddelovac-1);
return l;
}

struct list ListGetNextVariable(string sList, string sDelimiter="|")
{
struct list l;
int x = 1;
int typ = StringToInt(GetStringLeft(sList,1));
int oddelovac = FindSubString(sList,sDelimiter);
string sValue = GetSubString(sList,1,oddelovac-1);
 while(x<pomocna)
 {
 sList = GetStringRight(sList,GetStringLength(sList)-oddelovac-1);
 typ = StringToInt(GetStringLeft(sList,1));
 oddelovac = FindSubString(sList,sDelimiter);
 sValue = GetSubString(sList,1,oddelovac-1);
 x+=1;
 }
 switch(typ)
 {
 case VARIABLE_TYPE_INT:
 l.Int = StringToInt(sValue);
 break;
 case VARIABLE_TYPE_FLOAT:
 l.Float = StringToFloat(sValue);
 break;
 default:
 l.String = sValue;
 break;
 }
l.Variant = GetStringLeft(sList,oddelovac-1);
pomocna+=1;
return l;
}

int ListGetVariablesCount(string sList, string sDelimiter="|")
{
struct list l = ListGetFirstVariable(sList);
int x;
 while(GetIsListValid(l))
 {
 x+=1;
 l = ListGetNextVariable(sList);
 }
return x;
}

object GetFirstAreaInModule()
{
object M = GetModule();
string s = GetLocalString(M,"AREA_LIST");
 if(s=="")
 {
 string script = "%mod = '"+NWN_DIR+"modules/"+MODULE_FILE_NAME+"'; %ifo = %mod['module.ifo']; $name;for(/{'Mod_Area_list'}){$name = /~/Area_Name+'.are';%are = %mod[$name];print '3'+/Tag+'|';close %are;}close %ifo;close %mod;";
 s = LetoScript(script);
 SetLocalString(M,"AREA_LIST",s);
 }
struct list l = ListGetFirstVariable(s);
return GetObjectByTag(l.String);
}

object GetNextAreaInModule()
{
string s = GetLocalString(GetModule(),"AREA_LIST");
struct list l = ListGetNextVariable(s);
return GetObjectByTag(l.String);
}


In case you haven't got leto_include script:
Code:
#include "leto_constants"
//::///////////////////////////////////////////////
//:: Leto Include
//:: leto_include.ns
//:: Copyright (c) 2006 EleGoSoft.
//:://////////////////////////////////////////////
/*
  This file contains the low-level scripts in order
  to communicate to LetoScript. This file contains
  the port between LetoScript and NWScript.

  It's porting to NWScript let unskilled scripters
  use this fantastic program :D
*/
//:://////////////////////////////////////////////
//:: Created By: EleGoS
//:: Created On: 02/09/2006
//:://////////////////////////////////////////////


// Returns the script for leto
string GetLetoScript(object oPC);
// Adds a script-code level row of leto script
void addLeto(object oPC, string sScript);
// Adds the beginning (open).
void LetoIncipit(object oPC);
// Adds the end (save -> close) of the script.
void LetoFooter(object oPC);
// Starts NWNX-Leto.
string LetoScript(string Script);
// Resets the PC's script.
void LetoResetScript(object oPC);

//return only string value of letoscript
string LetoIncipitString(object oPC);

string LetoIncipitString(object oPC)
{
    string script = GetLetoScript(oPC);
    string pcName = GetPCPlayerName(oPC);
    string pcTag = GetTag(oPC);
    int pcTagLength = GetStringLength(pcTag);
    string sreturn;
    if(pcTag == "")
    {
     sreturn = "%char = q{" + NWN_DIR + "servervault/" + pcName + "//}+FindNewestBic q{" + NWN_DIR + "servervault/" + pcName + "//};";
    }
    else
    {
        pcTag = GetStringLeft(pcTag, pcTagLength-3)+".bic";
     sreturn = "%char = q{" + NWN_DIR + "servervault/" + pcName + "/"+pcTag+"};";
    }
  return sreturn;
}

string GetLetoScript(object oPC)
{
    return GetLocalString(oPC,"letoScript");
}

void addLeto(object oPC, string sScript)
{
    string temp = GetLetoScript(oPC);
    SetLocalString(oPC,"letoScript",temp + " " + sScript + ";");
}

void LetoIncipit(object oPC)
{
    string script = GetLetoScript(oPC);
    string pcName = GetPCPlayerName(oPC);
    string pcTag = GetTag(oPC);
    int pcTagLength = GetStringLength(pcTag);

    if(pcTag == "") SetLocalString(oPC,"letoScript","%char = q{" + NWN_DIR + "servervault/" + pcName + "//}+FindNewestBic q{" + NWN_DIR + "servervault/" + pcName + "//};" + script);
    else
    {
        pcTag = GetStringLeft(pcTag, pcTagLength-3)+".bic";
        SetLocalString(oPC,"letoScript","%char = q{" + NWN_DIR + "servervault/" + pcName + "/"+pcTag+"};" + script);
    }
}

void LetoFooter(object oPC)
{
    addLeto(oPC,"%char = '>'");
    addLeto(oPC,"close %char");
}

void LetoResetScript(object oPC)
{
    SetLocalString(oPC,"letoScript","");
}

string LetoScript(string Script)
{
    object M = GetModule();
    SetLocalString(M, "NWNX!LETO!SCRIPT", Script);
    return GetLocalString(M, "NWNX!LETO!SCRIPT");
}

_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect


Last edited by ShaDoOoW on Fri Mar 30, 2007 22:53; edited 1 time in total
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Fri Mar 30, 2007 22:58    Post subject: Reply with quote

WOW! Thank you so much!

However it seems that I'm missing leto_constants. I tried finding the leto download again but was unable to. Can you post leto_constants as well here? Please and thanks! Smile
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Fri Mar 30, 2007 23:20    Post subject: Reply with quote

Sorry, I noticed it before, but i had problems with posting.

leto_constants
Code:
//::///////////////////////////////////////////////
//:: Name Leto Constants
//:: FileName leto_constants.ns
//:: Copyright (c) 2006 EleGoSoft.
//:://////////////////////////////////////////////
/*
  EleGoS' system Leto Constants. REMEMBER TO EDIT NWN_DIR!
*/
//:://////////////////////////////////////////////
//:: Created By: EleGoS
//:: Created On: 02/09/2006
//:://////////////////////////////////////////////

const string NWN_DIR = "C:/Games/NWN_134/"; //Set it depending on your NwN directory
const string LETO_CHARACTERISTIC_STR = "/Str";
const string LETO_CHARACTERISTIC_CON = "/Con";
const string LETO_CHARACTERISTIC_DEX = "/Dex";
const string LETO_CHARACTERISTIC_WIS = "/Wis";
const string LETO_CHARACTERISTIC_INT = "/Int";
const string LETO_CHARACTERISTIC_CHA = "/Cha";

const string LETO_MODIFIER_AND = "+";
const string LETO_MODIFIER_MINUS = "-";

//nezmenitelne konstanty, nepouzivat
const string LETO_SECONDARY_CHAR_WILLBONUS = "/willbonus";
const string LETO_SECONDARY_CHAR_FORTBONUS = "/fortbonus";
const string LETO_SECONDARY_CHAR_REFBONUS = "/refbonus";
const string LETO_SECONDARY_CHAR_BASEATTACKBONUS = "/BaseAttackBonus";
const string LETO_SECONDARY_CHAR_REFSAVETHROW = "/RefSaveThrow";
const string LETO_SECONDARY_CHAR_WILLSAVETHROW = "/WillSaveThrow";
const string LETO_SECONDARY_CHAR_FORTSAVETHROW = "/FortSaveThrow";
const string LETO_SECONDARY_CHAR_ARMORCLASS = "/ArmorClass";
const string LETO_SECONDARY_CHAR_NATURAL_AC = "/NaturalAC";

const string LETO_CHAR_PLOT = "/Plot";
const string LETO_CHAR_NO_PERM_DEATH = "/NoPermDeath";
const string LETO_CHAR_DISARMABLE = "/Disarmable";
const string LETO_CHAR_BODYBAG = "/Bodybag";
const string LETO_CHAR_MOVEMENT_RATE = "/MovementRate";
const string LETO_CHAR_FACTION_ID = "/FactionID";

const string LETO_BG_AGE = "/Age";
const string LETO_BG_GENDER = "/Gender";
const string LETO_BG_RACE = "/Race";
const string LETO_BG_PHENOTYPE = "/Phenotype";

const string LETO_BG_STRING_SUBRACE = "/Subrace";
const string LETO_BG_STRING_FIRSTNAME = "/FirstName";
const string LETO_BG_STRING_LASTNAME = "/LastName";
const string LETO_BG_STRING_DEITY = "/Deity";

const string LETO_SPRITE_SOUNDSET = "/SoundSetFile";
const string LETO_SPRITE_COLOR_SKIN = "/Color_Skin";
const string LETO_SPRITE_COLOR_HAIR = "/Color_Hair";
const string LETO_SPRITE_COLOR_TATOO1 = "/Color_Tatoo1";
const string LETO_SPRITE_COLOR_TATOO2 = "/Color_Tatoo2";
const string LETO_SPRITE_APPEARANCE_TYPE = "/Appearance_Type";
const string LETO_SPRITE_APPEARANCE_HEAD = "/Appearance_Head";
const string LETO_SPRITE_TAIL = "/Tail";
const string LETO_SPRITE_WINGS = "/Wings";

const string LETO_SPRITE_STRING_PORTRAIT = "/Portrait";

_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Fri Mar 30, 2007 23:52    Post subject: Reply with quote

Thanks for posting all of this but I'm still not quite sure what to do. I think you said I should store variables on the areas when the placeable is created but how do I set persistent variables on the area itself?

Sorry, this isn't making a whole lot of sense for me. Sad
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Mar 31, 2007 2:33    Post subject: Reply with quote

Well player somehow create a placeable and you want to store it. You must have nwnx_odbc plugin which contain SetPersistent functions. So then after player created placeable you store resref of placeable and position via SetPersistentString - resref and SetPersistentFloat - x,y,z position and facing on location where the PC is. e.g. SetPersistentString(GetArea(oPC),"PLACEABLE_1",resref); and so on

And then restart occur and getfirst/nextarea will needed. You get area and retrieve all variables by GetPersistent functions. From this variables you can re-create your placeable.

If you still don't understand, I can write you whole code, it isn't difficult script.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Zunath



Joined: 06 Jul 2006
Posts: 183

PostPosted: Sat Mar 31, 2007 2:36    Post subject: Reply with quote

I hate to ask it, but would you mind writing it? I'm sorry but I think once I see it I'll understand how it works better.

I was trying to store the resref and location on a waypoint and then load it once the PC enters an area but I couldn't figure out a way.

Anyhoo, if you're willing to that'd be amazing. You'll be going in the credits so don't worry! Smile
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Mar 31, 2007 10:51    Post subject: Reply with quote

Yes, no problem but you must wait a minute so I can tune it Smile.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group