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 
 
help with script

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
DM_Vecna



Joined: 10 Feb 2010
Posts: 37

PostPosted: Thu Apr 01, 2010 6:31    Post subject: help with script Reply with quote

I am not sure how to write this yet as I am still gettign used to scripting with NWNX. I was hoping someone could give me a hand.

/////////////////////////////////////////////////////////////////////////////////
string sSQL = "SELECT " + sFactionFocus + " FROM tbl_factions WHERE faction_name='" + sTargetFocus + "'";

SQLExecDirect(sSQL);

int nAdjustRep = StringToInt(sSQL);

fDelay = 2.0 * AWE_LOAD_FACTOR;

DelayCommand(fDelay, AdjustReputation(oTargetFocus, oFactionFocus, nAdjustRep));

I am trying to pull nAdjustRep from the table tbl_factions but I am not sure if this is the correct way. Sad

thanks for the help!
Back to top
View user's profile Send private message Send e-mail
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Thu Apr 01, 2010 8:27    Post subject: Re: help with script Reply with quote

DM_Vecna wrote:
I am not sure how to write this yet as I am still gettign used to scripting with NWNX. I was hoping someone could give me a hand.

/////////////////////////////////////////////////////////////////////////////////
string sSQL = "SELECT " + sFactionFocus + " FROM tbl_factions WHERE faction_name='" + sTargetFocus + "'";

SQLExecDirect(sSQL);

int nAdjustRep = StringToInt(sSQL);

fDelay = 2.0 * AWE_LOAD_FACTOR;

DelayCommand(fDelay, AdjustReputation(oTargetFocus, oFactionFocus, nAdjustRep));

I am trying to pull nAdjustRep from the table tbl_factions but I am not sure if this is the correct way. Sad

thanks for the help!


SQLExecDirect is right, but you need to

SQLFetch() -- each row
val = SQLGet() -- the column of data (0..n)
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Thu Apr 01, 2010 12:29    Post subject: Re: help with script Reply with quote

Code:
SQLExecDirect("SELECT " + sFactionFocus + " FROM tbl_factions WHERE faction_name='" + sTargetFocus + "'");

if (SQLFetch())
{
  int nAdjustRep = StringToInt(SQLGetData(1));
  fDelay = 2.0 * AWE_LOAD_FACTOR;

  DelayCommand(fDelay, AdjustReputation(oTargetFocus, oFactionFocus, nAdjustRep));
}


That's how you do it. If you have more than one row, simply use while (SQLFetch()) instead. Also, just a note, be careful about putting in data directly. If it comes from something a user could input, like a name, you need to use SQLEncodeSpecialChars. If not, you're perfectly fine.
Back to top
View user's profile Send private message
DM_Vecna



Joined: 10 Feb 2010
Posts: 37

PostPosted: Thu Apr 15, 2010 4:39    Post subject: Reply with quote

I am still having problems with the script in mention. It compiles but maybe someone can check the MySQL syntax and make sure I am using it correctly?

I am not sure how to post scripts here within a boxed text format but here it goes.

////////////////////////////////////////////////////////////////////////////

void PRR_LoadModule()
{
AWA_DEBUG( "Loading faction information...");
int nNth = 0;
object oTargetFocus = GetObjectByTag("FACTION_FOCUS", nNth);
while(oTargetFocus != OBJECT_INVALID)
{
//int nAdjustRep = 0;
int i = 0;
object oFactionFocus = GetObjectByTag("FACTION_FOCUS", i);
float fDelay;
while(oFactionFocus != OBJECT_INVALID)
{
//string sPlayerID = GetLocalString(oPC,"ID");
string sTargetFocus = SQLEncodeSpecialChars(GetStringLowerCase(GetName(oTargetFocus)));
string sFactionFocus = SQLEncodeSpecialChars(GetStringLowerCase(GetName(oFactionFocus)));

SQLExecDirect("SELECT " + sFactionFocus + " FROM tbl_factions WHERE tbl_player_player_character='" + sTargetFocus + "'");
if (SQLFetch())
{
int nAdjustRep = StringToInt(SQLGetData(1));
//float fDelay = 2.0 * AWA_LOAD_FACTOR;
fDelay += 0.10;
DelayCommand(fDelay*AWA_LOAD_FACTOR, AdjustReputation(oTargetFocus, oFactionFocus, nAdjustRep));
//DelayCommand(fDelay*AWA_LOAD_FACTOR, AWA_DEBUG("Setting how "+GetName(oFactionFocus)+" feels about "+GetName(oTargetFocus)+" to "+ IntToString(nAdjustRep) +" a t"+ FloatToString(fDelay,10,5)));
int nNewRep = GetReputation(oTargetFocus, oFactionFocus);
DelayCommand(fDelay*AWA_LOAD_FACTOR, AWA_DEBUG("New results "+GetName(oFactionFocus)+" feels about "+GetName(oTargetFocus)+" = "+IntToString(nNewRep)));
}
else
{
AWA_DEBUG("PRR ERROR: could not SELECT "+GetName(oFactionFocus)+" FROM tbl_factions WHERE tbl_player_player_character= "+GetName(oTargetFocus));
}
i++;
oFactionFocus = GetObjectByTag("FACTION_FOCUS", i);
}
nNth++;
oTargetFocus = GetObjectByTag("FACTION_FOCUS", nNth);
}
DelayCommand(0.8, AWA_DEBUG("Finished loading all factions."));
}
Back to top
View user's profile Send private message Send e-mail
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Thu Apr 15, 2010 18:22    Post subject: Reply with quote

At a glance, tbl_player_player_character - does this field actually exist in tbl_factions? Seems like an odd name for a field. It might be helpful if you listed your database structure.
Back to top
View user's profile Send private message
DM_Vecna



Joined: 10 Feb 2010
Posts: 37

PostPosted: Fri Apr 16, 2010 1:02    Post subject: Reply with quote

Is there a quick way to print out database structure or a preferred method for you to review it or should I just wing it?

Thanks!

ALso that is a real column. It was renamed when MySQL WOrkbench make the one to many connection.
Back to top
View user's profile Send private message Send e-mail
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Tue Apr 20, 2010 0:06    Post subject: Reply with quote

Not exactly sure what you want to see but im using MySQLAdministration tool and its wonderfull. I can view table structure and change it manually, no need to do it via script. Also I can view table data and change them manually...

You can found it at mysql download page.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Argonn



Joined: 03 May 2010
Posts: 13

PostPosted: Fri May 07, 2010 13:50    Post subject: Reply with quote

Maby a little late,

But from reading you code... oFactionFocus and oTargetFocus are the same object.

Both are objects with the tag "FACTION_FOCUS" that you loop 2times trough.

For every "FACTION_FOCUS" object you loop trough all "FACTION_FOCUS" objects again.. Weird code Smile

And if you Tablename is 'tbl_factions' and your Column name is 'tbl_player_player_character', your code looks good ( SQL wise )
Back to top
View user's profile Send private message
Lokey



Joined: 02 Jan 2005
Posts: 158

PostPosted: Sat May 08, 2010 0:43    Post subject: Reply with quote

Since it's bumped already...
DM_Vecna wrote:
Is there a quick way to print out database structure or a preferred method for you to review it or should I just wing it?

Code:
mysql -u root -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 5.1.42 PCLinuxOS 2010 - MySQL Standard Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Database changed
mysql> describe help_category;
+--------------------+----------------------+------+-----+---------+-------+
| Field              | Type                 | Null | Key | Default | Extra |
+--------------------+----------------------+------+-----+---------+-------+
| help_category_id   | smallint(5) unsigned | NO   | PRI | NULL    |       |
| name               | char(64)             | NO   | UNI | NULL    |       |
| parent_category_id | smallint(5) unsigned | YES  |     | NULL    |       |
| url                | char(128)            | NO   |     | NULL    |       |
+--------------------+----------------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

Can throw it into query browser if you don't like cli too Smile
_________________
Neversummer PW NWNx powered mayhem Wink
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
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