Author Topic: campaign database overwrite?  (Read 466 times)

Legacy_Guest_lordofworms_*

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
campaign database overwrite?
« on: August 16, 2010, 07:14:35 pm »


               greetings all, first post in a looong time.

I have a question I am hoping someone with better knowledge can help me with.

first a quick explanation what I am doing and what i have done so far.

this is for a multiplayer mod that I will be ONLY using with about 6-7 people tops ever...so keep that in mind (:

I am making a special area that is roughly a live monument of the players as they are in game. a wax museum in so many words.

so i have a ground trigger that stores (StoreCampaignObject) the pc that triggered it. and sets them up within a numerical sequential index., first one is (1) , 2nd is (2), so on and so forth.
roughly this:
StoreCampaignObject("DATABSE", "DATABSEARRAY" + IntToString(nIndex), oPC);

then on module load I have it retrieve object, so on...and it all works just like it should more or less.


my question is this, is there anyway to actually OVERWRITE an index with the same PC?
see the reason is if the same PC walks over the trigger more than once it creates a new index and stores them as well.
so if the pc walks over trigger three times, I have three duplicate copies stored in database.

I COULD use a local int stored on a persistant item in inventory to STOP the script after the first time, but I would really like it to continually overwrite the old PC with the newer one everytime they trigger it.

so any thoughts?
could I somehow maybe store the INT given when first triggered to the persistant item and then do a compare statement(wouldnt know how to really) between whats on the item and whats in databse and if they are same overwrite?

or is there a simpler way to do it?

here is the scripts in the entirety.

ON ENTER
[nwscript]
#include "x2_inc_switches"
// Some string constants that could be placed in an include file.
const string HeroDB = "HeroDatabase";
const string HeroDBCount = "HeroCount";
const string HeroDBArray = "HeroArray";
const string HeroDBLocationArray = "HeroLocation";
const string HeroLocalIndex = "HeroDatabaseIndex";
void main()
{
    location lLocation;
    object oItem = GetEnteringObject();
    object oHeroCount = GetObjectByTag("HERO_COUNTS");
// Get the next index.
        int nIndex = GetCampaignInt(HeroDB, HeroDBCount) + 1;
        // Give this Hero the next index.
        SetLocalInt(oHeroCount, HeroLocalIndex, nIndex);
 // Save the Hero and its location to the database.
        StoreCampaignObject(HeroDB, HeroDBArray + IntToString(nIndex), oItem);
        SetCampaignLocation(HeroDB, HeroDBLocationArray + IntToString(nIndex),GetLocation(oItem));
        SetCampaignInt(HeroDB, HeroDBCount, nIndex);
}
[/nwscript]

ON USE of placeable object (will eventually edit for on mod load)
[nwscript]
// Some string constants that could be placed in an include file.
const string HeroDB = "HeroDatabase";
const string HeroDBCount = "HeroCount";
const string HeroDBArray = "HeroArray";
const string HeroDBLocationArray = "HeroLocation";
const string HeroLocalIndex = "HeroDatabaseIndex";
void main()
{
 object oHero = OBJECT_INVALID;
    location lHero;
    int nCount = 0;     // Count of Heros restored.
    int nIndex = GetCampaignInt(HeroDB, HeroDBCount);
    // Restore Heros from the database.
    while ( nIndex > 0 )
    {
        // Retrieve the next Hero.
        lHero = GetCampaignLocation(HeroDB, HeroDBLocationArray + IntToString(nIndex));
        oHero = RetrieveCampaignObject(HeroDB, HeroDBArray + IntToString(nIndex),lHero);
// See if this Hero is valid.
        if ( oHero != OBJECT_INVALID )
        {
            // Count this Hero.
            nCount++;
 }
        // "Next" index.
        nIndex--;
    }
    }
[/nwscript]

sorry for being such a noob and not really explaining myself clearly.
in a nutshell

i want every pc that triggers this event to be stored as campaign-object, BUT if same pc runs over it a second time, the stored object is replaced with the newer one rather then creating a new reference.


I have tried the following with headbanging results..

tried setting up insead of index using PCName and PublicCDkey to make a unique reference, which worked but I wasnt able to do a while loop to get them all, it would always just create the last object stored.

(I am horrible horrible horrible at while loops and such)


also lastly, this script was totally hashed together from these (well the old) forums so I cant take credit for the scripts but I did peice them together and i understand what i did/have done...so I am learning (:
'Posted
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
campaign database overwrite?
« Reply #1 on: August 16, 2010, 09:18:27 pm »


               

I COULD use a local int stored on a persistant item in inventory.





Yes that would most likely be the easiest.   Do you all the PC's already have an item in there invetory that the can not drop?





also keep in mind that when you overrite an entry in the DB it is not really overwritten.  The old entry is marked as no longer used and the new entry is add to the data base.  In order to get ride of the old entrys you will need to run the DB packer.   that is if you are useing the NWN DB.  



Ill try to work up so time to modify you script after awhile If someone else dosen't get to it first.
               
               

               
            

Legacy_Guest_lord_of_worms_*

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
campaign database overwrite?
« Reply #2 on: August 16, 2010, 09:45:47 pm »


               Yes, All the PC's currently have a persistant no drop item , a persistant rune with the resref and tag of 'database' simply enough.



now I already have a check currently in place, that says

If this is your first time

  do everything and set a INT so that it doesnt happen again.



which is waht I am using, but whenever I want to update mine and my players appearances to reflect them as they are currently, I have to remove that int from the databse object so the trigger fires again for them.

I also admit that I can also set a timer or another triggered event to say remove their INT after so many levels or so much game time or whatever else I choose.

But I also like to know as much as I can about scripting so these choices aside I was just really hopeful on using a constant update approach.



and using DB packer wouldnt be an issue for me at all. and I am using the default NWN DB.



as a side question, would you happen to know of a nwn DB reader? I have searched for months but I just dont see it out there.



Thank you soo much. I dont expect you to write it out for me, I dont mind and enjoy the challenge of figuring it out myself but...I just dont know how to compare and check ):



               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
campaign database overwrite?
« Reply #3 on: August 16, 2010, 10:39:56 pm »


               Ok I have not read the script you have already posted yet.  But here is the main Idea.  



When a PC steps on the trigger for the first Time.  (when you check for the Int you are storing it == 0)



Get a Int from the DB that is a refferance to the next index number,  

Store the Int on the PC DB item as there Index into the statue array.  

Store the PC as an object into the DB as at there Index as stored on there DB item.  

Increase the Refferance for next Statue reffrence by one and store it back into the DB for if another new player come along/  



Now if a PC already has a Statue all you di is get there Index number from there DB item and Store there PC object at the same spot it was at before.



Hope that helps.

               
               

               
            

Legacy_lordofworms

  • Sr. Member
  • ****
  • Posts: 422
  • Karma: +0/-0
campaign database overwrite?
« Reply #4 on: August 17, 2010, 02:50:22 pm »


               I have successfully written this script out and its working like a charm. I expanded upon it as well so that a display sign is also put up beside the clone detailing their name,level,class,bio,etc



really works nicely and I am very pleased with the results.

I will be posting it as an erf soon to vault for others to use as writing the whole process here would be too time consuming.

thanks again for the help and guidance.