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

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« on: December 07, 2010, 10:21:26 am »


               I am trying to work on a database that is stack on an item so it would store everything that will happen on a pc (including death) and will not simply be reset when we are having a server reset...

I sorta tried that with a normal database but most wouldn't really compile with my current scripts.

So anyone have a script for me that can do that for me?

at any rate thanks!

 ~Who said that I
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Database on an item?
« Reply #1 on: December 07, 2010, 05:03:01 pm »


               You don't need a script. Any variable saved on an item in a pc's possession will be saved when the character file is saved - meaning they will persist after resets. Just set and get the variables on the item instead of the pc.



Funky
               
               

               
            

Legacy_Who said that I

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


               errr, that is not really what I was looking for.



Might be me asking it wrong really, my english is not the greatest ^^



But this is my issue:



We do not have a database here really other than the quest database that is stacking on our dicebag,

so what I was wondering: Can a player's HP be saved on an item like this? That if the player has died and the server resets so it will not have its 100% of its health again?  Like the item would be the database that will remember and stores everything the player does with his character. That even cheating by logging out and in or waiting for server reset won't really help?



Maybe this will make it a bit clearer to get an answer on my question maybe?
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Database on an item?
« Reply #3 on: December 07, 2010, 06:51:18 pm »


               Funky's answer is correct and it is what you are looking for.
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #4 on: December 07, 2010, 08:27:08 pm »


               so than my question would be: Why is it so that some of our players can log out with only 50% of their health and return with a 100% health after reset?

               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Database on an item?
« Reply #5 on: December 07, 2010, 08:37:09 pm »


               If you are saving the players hit points to an item. 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.

Are you asking for scripts to set up a system like this? Or do you already have the scripting in place?
               
               

               


                     Modifié par GhostOfGod, 07 décembre 2010 - 08:37 .
                     
                  


            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #6 on: December 07, 2010, 09:02:14 pm »


               well that was the original question, so yes please if you can provide us with one then you make me so HAPPY!



Though I then really need to ask: Would it also store like the current affliction on it and stuff? Like if the player is diseased or has a stat penalty?
               
               

               
            

Legacy_FunkySwerve

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


               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
               
               

               
            

Legacy_Who said that I

  • Hero Member
  • *****
  • Posts: 931
  • Karma: +0/-0
Database on an item?
« Reply #8 on: December 07, 2010, 09:58:26 pm »


               okay so the "SomeVarName" is the name of the item that is storing the information correct?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Database on an item?
« Reply #9 on: December 07, 2010, 10:01:10 pm »


               No, it's the name of a sample int variable. It could be 'CurrentHitPoints', or 'CompletedQuest1', or any other name (or type of variable, for that matter).



Funky
               
               

               
            

Legacy_Rubies

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


               "SomeVarName" would be the name of the variable you want to store, which you'd have to pick a name for and then later reference. If you wanted to store HP, you'd do something like:

object oPC = GetExitingObject();
int nHP = GetCurrentHitPoints(oPC);
object oStorage = GetItemPossessedBy(oPC, "pc_storage");
SetLocalInt(oStorage, "HPAmount", nHP);
If that makes sense (hopefully my scripting memory is working today). You'd then use "GetLocalInt" with the stored string "HPAmount" to return it.

EDIT: Already answered, nevermind! '<img'>
               
               

               


                     Modifié par Rubies, 07 décembre 2010 - 10:04 .
                     
                  


            

Legacy_Who said that I

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


               oooh okay! Well it might not be as dificult as I think it should be but I have an unnatural talent for making it difficult!



Not only me but also for the other builders and scripters on the team!

Just ask and they will burst out in tears!! ^^
               
               

               
            

Legacy_FunkySwerve

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


               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.



Funky
               
               

               
            

Legacy_Who said that I

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


               okay I might be an annoying bugger for asking so many questions but I like to have things clear, so here goes:



We have a similar system set up for the quests, a bit more complicated than this but it looks rather similar, but what we do notice is that the players who made a new character get the storage item at entering and the once who were build "before" we used this system didn't get it at each entering.



So my question would be: Would it still be working if the player had to buy the item from a widget merchant? If not, well then I kindly ask for help on this matter since I had a lot of complains about it lately and I do not really know how to solve this myself
               
               

               
            

Legacy_FunkySwerve

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


               That won't be a problem with this setup. Any character entering the server who doesn't have the item will get one, using the onenter code I gave you. That isn't to say there are no downfalls to doing databasing this way. First and foremost, you can only access the character's data when they're actually on the server. That tends not to matter for a lot of people, though. Second, it IS possible to drop undroppable ('cursed') items, and lose the database, but it's a pretty deliberate exp=l(oit, and not easy to do.



Funky