Aller au contenu

Photo

Not good with database...


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
Krevett

Krevett
  • Members
  • 104 messages
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!!

#2
Thayan

Thayan
  • Members
  • 244 messages
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

#3
Krevett

Krevett
  • Members
  • 104 messages
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...

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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

#5
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.

#6
Krevett

Krevett
  • Members
  • 104 messages
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 ^^

#7
La Rose Noire

La Rose Noire
  • Members
  • 25 messages
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.