Author Topic: Not good with database...  (Read 255 times)

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Not good with database...
« on: January 19, 2011, 01:00:43 pm »


               I'm trying to write a simple script for a storage system but it doesn't seems to work well ^^ here are the onopen and onclose scripts:

onopen():

void main()
{
string sPC = GetPCPlayerName(GetLastOpenedBy()) + GetName(GetLastOpenedBy());
int nItems = 0;
int nTotal = GetCampaignInt("Origin", sPC);
if (nTotal == 0) return;
object oItem = RetrieveCampaignObject("Origin", sPC + IntToString(nItems), GetLocation(OBJECT_SELF), OBJECT_SELF);
while(GetIsObjectValid(oItem) && (nItems < nTotal))
 {
 DeleteCampaignVariable("Origin", sPC + IntToString(nItems));
 nItems++;
 oItem = RetrieveCampaignObject("Origin", sPC + IntToString(nItems), GetLocation(OBJECT_SELF), OBJECT_SELF);
 }
SetCampaignInt("Origin", sPC, 0);
}
////

onclose():

void main()
{
string sPC = GetPCPlayerName(GetLastClosedBy()) + GetName(GetLastClosedBy());
int nItems = 0;
object oItem = GetFirstItemInInventory(OBJECT_SELF);
while (GetIsObjectValid(oItem))
 {
 if (GetHasInventory(oItem) == FALSE)
  {
  StoreCampaignObject("Origin", sPC + IntToString(nItems), oItem);
  DestroyObject(oItem);
  nItems++;
  }
  oItem = GetNextItemInInventory(OBJECT_SELF);
 }
SetCampaignInt("Origin", sPC, nItems);
}

If you can point me in the right direction of how to do this plz!!
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Not good with database...
« Reply #1 on: January 19, 2011, 03:24:06 pm »


               Well, I'm not sure of the problem you're seeing, (maybe tell us what 'not working well' consists of). But putting a StoreCampaignObject within a while loop is bad, bad news. Database access is very slow in NWN and making multiple quick calls like this will cause lag or possibly even crash the server.



I'd suggest looking on NWVault for some storage systems there. There's several to choose from that are efficient and will store non-palette (modified) items as well. Here's just a couple to consider -

http://nwvault.ign.c....Detail&id=2942

http://nwvault.ign.c....Detail&id=1214

http://nwvault.ign.c....Detail&id=2246
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Not good with database...
« Reply #2 on: January 19, 2011, 04:16:17 pm »


               Well we are just a limited number of player and we play in LAN so the acces time is not really a problem! Te "not working well" consist of items that had just dissapeared from the chest and necer come back fot the player who stored them...
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Not good with database...
« Reply #3 on: January 19, 2011, 07:04:24 pm »


               You're script seems like it should work. However I've never attempted to retrieve campaign objects like this so I could be wrong. The usual way of doing this is to save all the items onto an ivisisble object with inventory and then just save that one object. Then retrieve the one object and take all the items from it and give them back to the player. You really should use one of the persistent systems already out there. We use Scarfaces. Can be found here :
nwvault.ign.com/View.php
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Not good with database...
« Reply #4 on: January 19, 2011, 10:20:26 pm »


               

Krevett wrote...

  The "not working well" consist of items that had just dissapeared from the chest and necer come back fot the player who stored them...


Is this happening for all players or just one?

Possiable cause.  DB var names are limited to 32 characters.  If your player has a long account name followed by a long character name, All of the index numbers could be getting trimmed off of your var names.
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Not good with database...
« Reply #5 on: January 20, 2011, 12:39:07 am »


               I'll try to take a look at scarface's system thanks for your quick answers!

@ lightfoot if i remenber well it happened to one of my player only but i can't remember the lenght of his login + player name ^^
               
               

               
            

Legacy_La Rose Noire

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
Not good with database...
« Reply #6 on: January 21, 2011, 11:08:42 am »


               If i may ask a question...... what doesn't work ?



Does it store badly, does it retrieve badly ? Does it loose items ? Many of them, few ?



You should insert SendMessageToPC retrieving each tag.... to see where is the bug.