View previous topic :: View next topic |
Author |
Message |
DM_Vecna
Joined: 10 Feb 2010 Posts: 37
|
Posted: Thu Apr 01, 2010 6:31 Post subject: help with script |
|
|
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.
thanks for the help! |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Thu Apr 01, 2010 8:27 Post subject: Re: help with script |
|
|
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.
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 |
|
|
Fireboar
Joined: 17 Feb 2008 Posts: 323
|
Posted: Thu Apr 01, 2010 12:29 Post subject: Re: help with script |
|
|
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 |
|
|
DM_Vecna
Joined: 10 Feb 2010 Posts: 37
|
Posted: Thu Apr 15, 2010 4:39 Post subject: |
|
|
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 |
|
|
Fireboar
Joined: 17 Feb 2008 Posts: 323
|
Posted: Thu Apr 15, 2010 18:22 Post subject: |
|
|
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 |
|
|
DM_Vecna
Joined: 10 Feb 2010 Posts: 37
|
Posted: Fri Apr 16, 2010 1:02 Post subject: |
|
|
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 |
|
|
ShaDoOoW
Joined: 20 Aug 2005 Posts: 584
|
Posted: Tue Apr 20, 2010 0:06 Post subject: |
|
|
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 |
|
|
Argonn
Joined: 03 May 2010 Posts: 13
|
Posted: Fri May 07, 2010 13:50 Post subject: |
|
|
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
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 |
|
|
Lokey
Joined: 02 Jan 2005 Posts: 158
|
Posted: Sat May 08, 2010 0:43 Post subject: |
|
|
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 _________________ Neversummer PW NWNx powered mayhem |
|
Back to top |
|
|
|