Bioware Archive

Bioware Archive V2 => Builders - Scripting => Topic started by: Baaleos on December 11, 2010, 08:27:42 pm

Title: Transfer Feat to mySQL Database- getting around TMI
Post by: Baaleos on December 11, 2010, 08:27:42 pm

               Im trying to build another web interface that allows me to build more feat combo's into my PW.

However, im having trouble getting around the TMI error on the windows server.

The issue is that I need to get

1. The feat number, which is easy, it starts at 0, and works its way up.
2. The feat name - Got via Get2daString and GetStringResRef or whatever its called
3. The Description of the feat.

and then post it all into the mySQL database.

The script runs, for about 47 feats, and then runs into TMI errors.

Whats the best way of getting around TMI errors?

I suppose I could code the script to process 10 feats at a time, and have it save its progress on a Module stored int, and then continue from that point on next run. And have it run every heartbeat until finished?

Title: Transfer Feat to mySQL Database- getting around TMI
Post by: Legacy_FunkySwerve on December 11, 2010, 09:28:07 pm

               You'll want to set up a function that you call repeatedly, with incrementing inputs. Here's the one we use to build the featlist for the leveler. It starts at the last feat and goes foward, though we have far more feats than vanilla - around 4k rows at present (with a lot of blank saved ones). You'd want to start at 1100 or 1060 or whatever you're at at present - I forget the exact number of 'normal' feats.

#include "aps_include"
#include "zdlg_include_i"
#include "hgll_func_inc"

void BuildFeatList(int nStartFeat, int nInterval, float fDelay) {
    object oPC = OBJECT_SELF;
    int nFeat, nCount2;

    if (nStartFeat < 0) {
        string sList = "feat_select";
        string sServer = GetLocalString(GetModule(), "ServerNumber");
        int i, nCount = GetElementCount(sList, oPC);

        SQLExecDirect("DELETE FROM sort_" + sServer);
        string sSQL = "INSERT INTO sort_" + sServer + " VALUES (?, ?)";

        for (i = 0; i < nCount; i++)
            SQLExecStatement(sSQL, GetStringElement(i, sList, oPC), IntToString(GetIntElement(i, sList, oPC)));

        SQLExecDirect("SELECT sort_key, sort_val FROM sort_" + sServer + " ORDER BY sort_key DESC");

        while (SQLFetch() != SQL_ERROR) {
            string sName = SQLDecodeSpecialChars(SQLGetData(1));
            int nFeat    = StringToInt(SQLGetData(2));

            ReplaceIntElement(--i, nFeat, sList, oPC);
            ReplaceStringElement(i, sName, sList, oPC);

        if (i != 0) {
            DeleteList(sList, oPC);
            nCount = AddStringElement("An error occurred building the feat list. Please talk to a DM.", sList, oPC);
            ReplaceIntElement(nCount - 1, -1000, sList, oPC);
        } else {
            nCount = AddStringElement("Return to first page ...", sList, oPC);
            ReplaceIntElement(nCount - 1, -1000, sList, oPC);

    } else
        DelayCommand(fDelay, BuildFeatList(nStartFeat-nInterval, nInterval, fDelay));

    for (nFeat = nStartFeat; nFeat > (nStartFeat-nInterval); nFeat--) {
        if (nFeat < 0)
        if (GetIsFeatAvailable(nFeat, oPC)) {
            string sList = "feat_select";
            string sMaster = Get2DAString("feat", "MASTERFEAT", nFeat);
            int nMaster = StringToInt(sMaster);

            if (nMaster > 0 || sMaster == "0") {
                sList += IntToString(-(nMaster + 1));

                if (GetElementCount(sList, oPC) == 0) {
                    nCount2 = AddStringElement("Main feat list ...", sList, oPC);
                    ReplaceIntElement(nCount2 - 1, -1, sList, oPC);

                    sMaster = GetStringByStrRef(StringToInt(Get2DAString("masterfeats", "STRREF", nMaster))) + " ...";
                    nCount2 = AddStringElement(sMaster, "feat_select", oPC);
                    ReplaceIntElement(nCount2 - 1, -(nMaster + 1), "feat_select", oPC);

            nCount2 = AddStringElement(GetFeatName(nFeat), sList, oPC);
            ReplaceIntElement(nCount2 - 1, nFeat, sList, oPC);

void main() {
    BuildFeatList(3999, 25, 0.01);

Alternatively, if you're just inputting into MySQL, you can just do excel/googledoc coding, pasting in the repetitive INSERT statment segments into long columns, with the varying data in between. You can then do a couple large pastes to INSERT them all, since MySQL is very agreeable about parsing them properly. If you need more clarification on that, don't hesitate to ask.


Title: Transfer Feat to mySQL Database- getting around TMI
Post by: Baaleos on December 11, 2010, 09:36:30 pm

               Thanks Funky,

I managed to get a slow approach to work, and in fact, its still working... when I say working, I mean, its being fired on each hb of the module, processing 10 feats at a time, until it gets to the end of the feat list.

#include "aps_include"

void StoreFeats2(int iNum)
int i = 0;
int iLastFeat = 0;

    for(i =iNum; i<= iNum+10; i++)
        if(i <= 1115)
          string sFeatNum = Get2DAString("feat","feat",i);
          int iNumber = StringToInt(sFeatNum);

          string sFeatDescNumber = Get2DAString("feat","description",i);
          int iDescNumber = StringToInt(sFeatDescNumber);

          string sName=SQLEncodeSpecialChars(GetStringByStrRef(iNumber));
          string sDescription =SQLEncodeSpecialChars(GetStringByStrRef(iDescNumber));
          string sInsert = "insert into Feat_Database (FEAT_NUM,FEAT_NAME,DESCR) VALUES ("+IntToString(i)+",'"+sName+"','"+sDescription+"')";
          iLastFeat = i;


void StoreFeats()

    int iNum = GetLocalInt(GetModule(),"FEAT_NUMBER");
    if(iNum < 1115)