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 
 
script to check merchant stock

 
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: Wed Jul 14, 2010 2:53    Post subject: script to check merchant stock Reply with quote

I would like to run a script that will take all of the stock of some custom merchants I am using and create a list of the items in a table with a column stating which merchant they are contained in. This should work as a reference and help me to copy the item later without having to look in every merchant one item at a time.

My function is outputing properly to a log but I find that only one row is being added to the table. I am not sure if my SQL is off.

any thoughts?

Here is the function I am using:
Code:
void PrimeLootitems()
{
//object oChest =GetObjectByTag("ss_t_chest_"+IntToString(i));
        int nChestNum=1;
        string sChestTag = "ss_t_chest_"+IntToString(nChestNum);
        object oChest = GetObjectByTag(sChestTag);
        while (oChest != OBJECT_INVALID)
        {
                AWA_DEBUG("awa_inc_treasure: found a CHEST called= "+GetName(oChest));
                object oInv = GetFirstItemInInventory(oChest);
                while (GetIsObjectValid(oInv) == TRUE)
                {
                string sItemResref = GetResRef(oInv);
                string sItemTag = GetTag(oInv);
                string sItemName = GetName(oInv, FALSE);
                string sItemValue = IntToString(GetGoldPieceValue(oInv));
                AWA_DEBUG("awa_inc_treasure: found a ITEM called= "+sItemName); //debug
                SQLExecDirect("INSERT INTO `nwn`.`"+TABLE_LOOT+"` (`"+LOOT_CHEST_TAG+"`,`"+LOOT_ITEM_REF+"`,`"+LOOT_ITEM_TAG+"`,`"+LOOT_ITEM_NAME+"`,`"+LOOT_ITEM_VALUE+"`) VALUES ('"+sChestTag+"','"+sItemResref+"','"+sItemTag+"','"+sItemName+"','"+sItemValue+"');");
                oInv = GetNextItemInInventory(oChest);
                }
                if (oInv == OBJECT_INVALID) AWA_DEBUG("awa_inc_treasure: ITEM INVALID");
        nChestNum++;
                //if (nChestNum > MAX_num_TABLES) return; //quick finish
        oChest =GetObjectByTag("ss_t_chest_"+IntToString(nChestNum));
        }
AWA_DEBUG("AWA_INC_TREASURE: finished primeing Treasure Table by Chest.");
}


the sql statement I am using is
SQLExecDirect("INSERT INTO...
All the variables seem to be working properly as the first line is updating.


THANKS AGAIN!
Back to top
View user's profile Send private message Send e-mail
DM_Vecna



Joined: 10 Feb 2010
Posts: 37

PostPosted: Wed Jul 14, 2010 8:05    Post subject: Reply with quote

I found the issue here.

I was using the chest tag as a primary key and apparently tables do not like duplicates for primary keys so I added an auto increment id column and it works like a charm.
Back to top
View user's profile Send private message Send e-mail
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