Author Topic: Database on an item?  (Read 868 times)

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #15 on: December 07, 2010, 10:57:25 pm »


               okay it doesn't wanna compile with the prc locker you have send me earlier....would it also work if I put it in an execute file or an include?

               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Database on an item?
« Reply #16 on: December 07, 2010, 11:02:13 pm »


               

GhostOfGod wrote...

You also need to export (save) that character immediately after so that that info sticks to the item. Otherwise if the player logs out before a server wide save or some auto save then the player will have whatever hp was on the item before.

Not true. Player characters are automatically saved a moment before OnClientExit event.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Database on an item?
« Reply #17 on: December 07, 2010, 11:08:45 pm »


               

Who said that I wrote...

okay it doesn't wanna compile with the prc locker you have send me earlier....would it also work if I put it in an execute file or an include?

The scripts I gave you will compile, if you managed to re-capitalize all the instances of 'class'. What error are you getting, on what line?

Funky
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Database on an item?
« Reply #18 on: December 07, 2010, 11:09:54 pm »


               

ShaDoOoW wrote...

GhostOfGod wrote...

You also need to export (save) that character immediately after so that that info sticks to the item. Otherwise if the player logs out before a server wide save or some auto save then the player will have whatever hp was on the item before.

Not true. Player characters are automatically saved a moment before OnClientExit event.

That's what I was driving at when I posted this:

Don't forget to do the ExportSingleCharacter(oPC), per GoG's suggestion -
that's the only thing missing from Rubies' example. The character will
be saved anyway, when they exit the server, so it isn't strictly
necessary to do the export, but this will prevent loss of the variable
from a crash, should one happen before they log out.

I probably should have spelled it out more clearly to start with.

Funky
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #19 on: December 07, 2010, 11:10:16 pm »


               

ShaDoOoW wrote...

GhostOfGod wrote...

You also need to export (save) that character immediately after so that that info sticks to the item. Otherwise if the player logs out before a server wide save or some auto save then the player will have whatever hp was on the item before.

Not true. Player characters are automatically saved a moment before OnClientExit event.

Then what about a crash? Crashes are one of the most annoying things in a server, what we notice is that sometimes the player might actually lose something he had gained in the moment just before the crash or a few moments before.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Database on an item?
« Reply #20 on: December 07, 2010, 11:44:53 pm »


               

Player characters are automatically saved a moment before OnClientExit event.

Wow. All this time and I never knew that.

There have been times I have logged off of servers and come back to find that items I've had or info stored were gone or unstored. So then I must have logged out at the exact moment of crashes?

Is this a hard coded and reliable thing?

Also, does booting a player automatically trigger the OnClientExit thus saving the character as well?
               
               

               


                     Modifié par GhostOfGod, 07 décembre 2010 - 11:46 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Database on an item?
« Reply #21 on: December 07, 2010, 11:47:29 pm »


               

Who said that I wrote...

ShaDoOoW wrote...

GhostOfGod wrote...

You also need to export (save) that character immediately after so that that info sticks to the item. Otherwise if the player logs out before a server wide save or some auto save then the player will have whatever hp was on the item before.

Not true. Player characters are automatically saved a moment before OnClientExit event.

Then what about a crash? Crashes are one of the most annoying things in a server, what we notice is that sometimes the player might actually lose something he had gained in the moment just before the crash or a few moments before.

Crash will of course not save the characters, thats why all of them loose progress. To protect your players agains it, thats different question. In short: you need to save them all automatically after some time and/or when (un)acquire items.

Funky: it was clear, I just hadnt this thread refreshed, started with reply few hours after I send it '<img'>
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Database on an item?
« Reply #22 on: December 07, 2010, 11:51:47 pm »


               

GhostOfGod wrote...
Is this a hard coded and reliable thing?

Also, does booting a player automatically trigger the OnClientExit thus saving the character as well?

Yes, and yes. It DOES occasionally fail - I've noted the same thing as you - but it appears to fail only about 1 time in a couple hundred or so, for reasons I've never been able to divine. I think the failures were more frequent in older patches, as I've noticed it far less of late, but I have no scientific data to back that up, just a personal guestimate.

Funky
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Database on an item?
« Reply #23 on: December 07, 2010, 11:55:54 pm »


               Funky pointed out the function to use. ExportSingleCharacter. There are a lot of different places you could stick this to protect the players. Examples:



~Player finishes a quest

~Player receives an item from quest

~Every time a player rests

~Every time a player enters a new area or some trigger

~When you want to store specific information on player item(like HP)



And the list gos on. Really its up to the builder to decide when it is important to export and save the players.
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #24 on: December 08, 2010, 05:16:22 am »


               

FunkySwerve wrote...

Who said that I wrote...

okay it doesn't wanna compile with the prc locker you have send me earlier....would it also work if I put it in an execute file or an include?

The scripts I gave you will compile, if you managed to re-capitalize all the instances of 'class'. What error are you getting, on what line?

Funky


if (!GetIsObjectValid(oStorage)) { <- is what the script gen is saying is wrong and it gives this error -> ERROR: INVALID DECLARATION TYP
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #25 on: December 08, 2010, 05:40:02 am »


               

FunkySwerve wrote...

The solution I described above will store anything you want it to. The ONLY difficulty is making sure that the player has an undroppable 'storage' item, which you can accomplish with a few lines of code when they enter the server. You then set and get all variables relating to that player on that item. Here's the code for entering the server. All of my code will assume the resref and tag of the undroppable storage item you'll need to make are 'pc_storage'.



object oPC = GetEnteringObject();
object oStorage = GetItemPossessedBy(oPC, "pc_storage");
if (!GetIsObjectValid(oStorage)) {
    oStorage = CreateItemOnObject("pc_storage", oPC);
    SetItemCursedFlag(oStorage, TRUE);
}

Then, whenever you would set or get a variable on the pc, instead get the storage item and set it on that instead, using GetItemPossessedBy(oPC, "pc_storage");  As mentioned, you'll want to ExportSingleCharacter(oPC); after you do this.

So, instead of:

SetLocalInt(oPC, "SomeVarName", 3);

you would do:


object oStorage = GetItemPossessedBy(oPC, "pc_storage");
SetLocalInt(oStorage, "SomeVarName", 3);

This is no where near as difficult as you seem to think it should be. '<img'>

Funky



Okay got it to compile, What I did, there was already onentering oPC line so I simply added the rest under it ^^ 

So now its compiled and stuff I won't have to do anything else right?
(sometimes takes a while till my little brain understands it)
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #26 on: December 08, 2010, 05:44:03 am »


               okay works like a little fire on new years eve!



awesome guys thank you so much!
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Database on an item?
« Reply #27 on: December 20, 2010, 01:23:07 pm »


               Hmm I dont like to butt in but if you store local HP on the dmfi dice bag will this work too if char is dead or do I still need the death token script?


void main()
{
object oPC = GetExitingObject();
object oStorage = GetItemPossessedBy(oPC, "dmfi_dicebag");
SetLocalInt(oStorage, "CurrentHitPoints", 3);
ExportSingleCharacter(oPC);
  }

I put that in my onclientexit and it didnt work ...is there a script I need to put in the onclient enter to recall the HP?

EDIT: I found these a they work nicely     http://nwn.bioware.c...625285&forum=47
               
               

               


                     Modifié par Knight_Shield, 22 décembre 2010 - 11:18 .