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 
 
super-noob

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
melchoir55



Joined: 06 Jan 2007
Posts: 4

PostPosted: Sat Jan 06, 2007 23:38    Post subject: super-noob Reply with quote

Hey all, I have some very noobish questions here.

I have been leading the charge on a PW. We are just about ready for beta, but we really wanted a database for player inventories and quest variables. We would also like it to work for the players character sheets. My questions are:

1) I installed nwnx4 and mysql using the help documentation. The area that I really need (nwnx4 functions, using mysql etc) has no link. I was wondering if someone had guides for these. As it stands, I load up SQLyog and click on my servers DB. I get a PW table but I have no idea what to do next.

2) I wanted the external database for player inventories and stats so I wouldnt have to use the server save function, which would interrupt the players AND would lose player progress if the server crashes. I have no idea, at all, how to go about doing this.

3) Once I figure out the above I guess I'll probably know how to store quest variables and things like that.

I am super-duper-noob when it comes to this stuff. I've never touched a DB before, even my scripting experience is pretty limited.

Do I have any hope of doing these things, or should I just wait for the PWMS to be released?
Back to top
View user's profile Send private message
caloup



Joined: 29 Sep 2006
Posts: 59
Location: albi (france)

PostPosted: Sun Jan 07, 2007 8:16    Post subject: i try to answer your question Reply with quote

Quote:

1) I installed nwnx4 and mysql using the help documentation. The area that I really need (nwnx4 functions, using mysql etc) has no link. I was wondering if someone had guides for these. As it stands, I load up SQLyog and click on my servers DB. I get a PW table but I have no idea what to do next.


(yes i haven't finished the documentation, sorru...)
You need to create your table. Actually nwnx4 is in alpha version so it don't create any table, you should create them yourself.

The first table you need to create is pwdata, because the Set and Get function try to look in this table by defaut.

You have two choice :

1- You will create your table manually in SLQYog : right click on you database and then "Create table". Next you should specify whitch column you want in you table...So you need to think about what you want in your table before...

2 - You can create your table in a NWNScript that could be launch in the lauching of your module...

You could name that script "nwnx_buildtable"
Quote:

-------------------------------------------------------------------------------------------------------------------------------

#include "nwnx_sql"

void main()

{

SQLExecDirect("CREATE TABLE IF NOT EXISTS pwdata (player varchar(64) NOT NULL default ' ',tag varchar(64) NOT NULL default ' ',name varchar(64) NOT NULL default ' ',val varchar(64),expire smallint(5) unsigned default NULL,last timestamp(14) NOT NULL,PRIMARY KEY (player,tag,name)) TYPE=MyISAM;");

}

-----------------------------------------------------------------------------------------------------------------------------

Note : I wrote this for MySQL 5.0 it’s the reason there isn’t any ‘ around table name…

Next, you will create a script named “OnModuleLoad” that you must place in the event of your module name OnmoduleLoad. Put this on the script :

-----------------------------------------------------------------------------------------------------------------

/*Script witch will be launch on Module Load*/

void main()

{

ExecuteScript("nwnx_buildtable",OBJECT_SELF);

ExecuteScript("x2_mod_def_load",OBJECT_SELF);

}

------------------------------------------------------------------------------------------------------------------

So when you’re launching you’re module, it create the pwdata table if it isn’t existing already.


If you want to create other table just add another sqlrequest like this in your nwn_buildtable :
Quote:

SQLExecDirect("CREATE TABLE IF NOT EXISTS mytable (namecolumn1 varchar(64) NOT NULL default ' ',namecolumn2 varchar(64) NOT NULL default ' ',namecolumn3 varchar(64) NOT NULL default ' ',PRIMARY KEY (namecolumn1,namecolumn2,namecolumn3)) TYPE=MyISAM;");


although you need to specify your own type of column...I put varchar in this exemple but it could be boolean, integer,...It depend of what you want in your table.
If you don't know anything about the sql request, you must read a tutorial about MySQL. I'm sure google can help you for that...

Quote:

2) I wanted the external database for player inventories and stats so I wouldnt have to use the server save function, which would interrupt the players AND would lose player progress if the server crashes. I have no idea, at all, how to go about doing this.


You take the information you want to save with a NWNScript and then you do a MySQL reguest with a SetPersistent function to save it in you database. Then when you want to recover you data you put a GetPersistent function in your script.

For exemple, you want to stock the cdkey of a player to verify when next time he connect that it's the good player that play the caracter (my english isn't verify good i'm not sure that you could understand what i say) then you create a table named "cdkey" like this in your nwnx_buildtable:

Quote:

SQLExecDirect("CREATE TABLE IF NOT EXISTS cdkeys ("+
"`Player` char(64) NOT NULL default '',"+
"`Date` timestamp(14) NOT NULL,"+
"`Ban` tinyint(1) NOT NULL default '0',"+
"`CDKey` char(20) NOT NULL default '',"+
"PRIMARY KEY (`Player`,`CDKey`)"+
") TYPE=MyISAM;");


Then in your "OnClientEnter" module event script you put something like this :

Quote:


#include"nwnx_sql"
void main()
{
object oPlayer=GetEnteringObject();
int iXP = GetXP(oPlayer); /*if it's the first time the player enter he have no XP !*/
//you take the information you need :
string CDKey = GetPCPublicCDKey(oPlayer);
string sPlayer = GetPCPlayerName(oPlayer);

if (iXP==0)
{
//you put them in your database
string sSQL = "INSERT INTO cdkey (Player,CDkey) VALUES ('"+sPlayer+"','"+CDKey+"');";
SQLExecDirect(sSQL);

//you give some XP to avoid that this function apply the next time the player connect
GiveXPToCreature(oPlayer,1);
}
else
{
//we verify if the player caracter is the original owner of the caracther
string sCDKey = "SELECT CDkey FROM cdkey WHERE Player = "+sPlayer;
if (CDKey==sCDKey)
{
SendMessageToAllDMs("The player "+sPlayer+" is a valid player");
}
else
{
SendMessageToAllDMs("The player "+sPlayer+" is not a valid player");
SendMessageToPC(oPlayer,"You are not the valid player for this caracther. You will be kicked !");
DelayCommand(10.0,BootPC(oPlayer));
}
}
}


It's an exemple of how using NWNX4. I haven't tested the script but in theory it will be correct...

Quote:

3) Once I figure out the above I guess I'll probably know how to store quest variables and things like that.

Yes it's the same way than your question 2.just create another table for your Quest data...



Your a beginer like i am myself Wink I'm not a master of the use of a Database, neither C++...
If you have some time, you just have to read some tutorial about MySQL, read scripts made by other people to see how they make their script...

If you have a lot of time you could see some tutorial for scripting in NWN1, i think you could find a lot. You also could download on of the module in nwnvault on do some revers engeneering...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 Hours
Page 1 of 1

 
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