Author Topic: Can anyone point me to a script or utility that removes/merges items from players on log in?  (Read 2197 times)

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               

Lightfoot8 wrote...

FunkySwerve wrote...

If you're already using MySQL, there's absolutely no reason to use a DB item, and a number of reasons not to.

Funky


I can only take this statment to be an opinon. 

To me the greatest benifit for useing a DB item is keeping the data with the characters Bic file. 

Don't get me wrong, I am not saying that there are no drawbacks to using DB items.  But there are still some benifits.    

Lets say I have a player in a PW that want to delete a few character from his vault.  Once I have deleted his characters the data that was stored on his DB item is gone.  I do not need to create a system to also remove data for that character from an external DB.  Most people in this position would just leave the unneeded data in the DB. 
To me the DB item is just an extention of the Character's Data structure.  If there is ever anything where I could say. "It sure would be nice to just have this as part of the character structure."  I just add it to the DB item and save it out as part of the characters structure.

It's not opinion, it's fact. That 'benefit' is a huge drawback, since it makes that data highly inaccessible when the character is offline, short of digging into their bic with a gff editor. By contrast, you can easily wipe all data related to a character with a single MySQL DELETE FROM call. No 'system' required, beyond the system you already need in any MySQLor other database setup for connecting database entries to bic files - by default, correlation of player and character name, or, in more advanced setups, a unique id.

Then, of course, there's all the other applications where the bic file's inaccessibility is an even bigger drawback. Suppose you want to know how many characters have a given variable set. With a database item, that means going into each bic individually, or, if you have the savvy, writing an extensive letoscript for Moneo to scan up the data. By contrast, with MySql, it's just another single call.

I can only assume from your mistaken assumptions about MySQL that you don't use it yourself?

Funky
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0


               

FunkySwerve wrote...

I can only assume from your mistaken assumptions about MySQL that you don't use it yourself?

Funky

You are correct that I do not use MySQL for the NWN DB. I also do not use NWNx.   

Then, of course, there's all the other applications where the bic file's inaccessibility is an even bigger drawback. Suppose you want to know how many characters have a given variable set. With a database item, that means going into each bic individually, or, if you have the savvy, writing an extensive letoscript for Moneo to scan up the data. By contrast, with MySql, it's just another single call.

I already stated that a DB item has draw backs and the one you state here is by far the biggest.  It is also why you do not store information that you want to gain while the character is off line on a DB item. 

By contrast, you can easily wipe all data related to a character with a single MySQL DELETE FROM call. No 'system' required, beyond the system you already need in any MySQLor other database setup for connecting database entries to bic files - by default, correlation of player and character name, or, in more advanced setups, a unique id.

I would hold that the storage of the unique id in more advanced setups would be good use of a DB item.  Even if it was the only data on the item.  

I am not trying to start an argument here.  I am just stating my opinion.   
 


  
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0


               So if I don't use the database item approach (and as I mentioned the mod is already set up to be run with nwnx and a MySQL database, or at least that is how it was done in the past, and I am assuming there are things [like scripts, and functions] with in the mod that depend on it being run as such in the future.) how would you flag a PC as having had the item check run?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               
Quote
Lightfoot8 wrote...

I already stated that a DB item has draw backs and the one you state here is by far the biggest.  It is also why you do not store information that you want to gain while the character is off line on a DB item. 

The problem is, that that category - things you might want to check offline - is very large, especially if you want to leave open future functionality.
Quote

I would hold that the storage of the unique id in more advanced setups would be good use of a DB item.  Even if it was the only data on the item. 

Unique ids are best stored on things that players can't mess with - bic fields. There are ways to force undroppable items out of inventory. Though you could probably make it VERY counter to their interests to do so, with a little creative coding. '<img'> We use the tag field, in which we also store pc version, for when edits need to be retroactive.
[/quote]

Quote

I am not trying to start an argument here.  I am just stating my opinion.  

Two man enter. One man leave. '<img'>

Funky
               
               

               


                     Modifié par FunkySwerve, 18 juin 2011 - 11:16 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               

Lazarus Magni wrote...

So if I don't use the database item approach (and as I mentioned the mod is already set up to be run with nwnx and a MySQL database, or at least that is how it was done in the past, and I am assuming there are things [like scripts, and functions] with in the mod that depend on it being run as such in the future.) how would you flag a PC as having had the item check run?

Just SetPersistent some variable on them, and check for it before you run the item reset. Are you setting your Persistent vars as locals on the pc for faster reads? If not, I'd recommend doing so, and would be happy to show you how.

Funky
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0


               I feel stupid here, but sadly I don't know that mean's Funky, so I would say no not intentionally, however I have no idea what previous devs have done in that regard.
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0


               I know it's the scripting forum, but too much jargon flying about at the moment.

When you replace all of a character's items with updated versions, you need to somehow mark that character as having had all their items replaced (so that the process doesn't run every time they enter the mod or trigger or however it's set to run).  To mark them, you set a variable on them.and have the script check for it before running.  Setting a variable on a player in-game only lasts until the server resets, but setting a Persistent variable sets it in the external database (like MySQL) which keeps track across resets.

Since I have no experience with databases, I would do what GoG suggested and give the player an item that they can't drop, trade, sell, etc.  You can set variables on that item in their inventory and all those variables are saved across server resets, because it is part of the character file.  No database knowledge required, but of course you can't do many spiffy things Funky is talking about.

I think if you used GoG's script, set it on a trigger that every player must walk thru when entering the mod, and have it give them an item tthey can't drop, sell, trade, etc and set the variable on that item, then you'll be done.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               

Lazarus Magni wrote...

I feel stupid here, but sadly I don't know that mean's Funky, so I would say no not intentionally, however I have no idea what previous devs have done in that regard.

Don't worry about it. Just use SetPersistent from the nwnx database include to set a variable, and GetPersistent to check it. If it's not been set, set it, and replace all the character's items.

Lastly, ignore the people telling you to use a database item. With MySQL available, that would be completely harebrained. If you need me to supply you a script, I'm hapy to do so.

Funky
               
               

               


                     Modifié par FunkySwerve, 19 juin 2011 - 02:55 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               

Terrorble wrote...

Since I have no experience with databases,

If this is the case, why on earth are you posting in this thread? SetPersistent isn't 'jargon', it's a reference to a specific function that comes packaged with the default NWNX install, which you would know if you had said experience.

Funky
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0


               If you want to use the script I posted you will have to have someone else change the functions in it to work with NWNx/mysql (And yes you can use a "database item" in conjuction with NWNx/mysql. Neither has anything to do with the other). I have never used mysql and haven't had the need to yet. I just use a "database item" for everything I need. But I also haven't had any systems that need to check any player info offline. It's all about preference.

I personally haven't experienced any drawbacks from using a "database item". Quite the contrary.

But yes if you are going to be using mysql and have it all set up and what not, then you might as well use it since it is much more versatile.
               
               

               


                     Modifié par GhostOfGod, 19 juin 2011 - 03:17 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               Here's what is essentially GoG's script modified to use a Persistent int. Set/Get Persistent using aps_include (the default set of functions packaged with NWNX) uses exactly the same function parameters as bioware's Set/Get Local functions (with a few optional paramaters you don't need to worry about). It's designed to be intuitive. Just save this script as an include (it named it item_replace_inc in the example below):


#include "aps_include"

void ResRefMatchReplace(object oItem, object oTarget) {
    string sResRef = GetResRef(oItem);
    DestroyObject(oItem);
    object oReplacement = CreateItemOnObject(sResRef, oTarget);
    if (!GetIsObjectValid(oReplacement))
        WriteTimestampedLogEntry("Character: " + GetName(oTarget) + " (playername: " +
            GetPCPlayerName(oTarget) + "): No replacement item for " +GetName(oItem) +
            " (resref: " + sResRef + ").");
}

void CheckReplaceItems(object oTarget){
    if (!GetIsPC(oTarget) ||
        GetPersistentInt(oTarget, "ItemsReplaced"))
        return;
    SetPersistentInt(oTarget, "ItemsReplaced", 1);
    object oItem = GetFirstItemInInventory(oTarget);
    int iSlot;

    //Get items in inventory and replace if needed
    while (GetIsObjectValid(oItem)) {
        //if item is a container, loop through items inside
        if (GetHasInventory(oItem)) {
            object oConItem = GetFirstItemInInventory(oItem);
            while (GetIsObjectValid(oConItem)) {
                ResRefMatchReplace(oConItem, oTarget);
                oConItem = GetNextItemInInventory(oItem);
            }
        } else
            ResRefMatchReplace(oItem, oTarget);

        oItem = GetNextItemInInventory(oTarget);
    }

    //Get equipped items and replace if necessary
    for (iSlot=0; iSlot<NUM_INVENTORY_SLOTS; iSlot++) {
        oItem = GetItemInSlot(iSlot, oTarget);
        if (GetIsObjectValid(oItem))
            ResRefMatchReplace(oItem, oTarget);
    }
}

Then include it in the area onenter script for the first area pcs spend any substantial time. In that script, just Get the entering object, and call CheckReplaceItems on them, like so:

#include "item_replace_inc"
void main() {
    object oEnter = GetEnteringObject();
    CheckReplaceItems(oEnter);
}

If it generates lag hiccups from the mass replacements, let me know, and I'll write you one with recursive delays like the one I pasted on the first page of this thread.

LMK if you have any questions.
Funky
               
               

               


                     Modifié par FunkySwerve, 19 juin 2011 - 03:44 .
                     
                  


            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0


               

FunkySwerve wrote...

Terrorble wrote...

Since I have no experience with databases,

If this is the case, why on earth are you posting in this thread? SetPersistent isn't 'jargon', it's a reference to a specific function that comes packaged with the default NWNX install, which you would know if you had said experience.

Funky


I'm not usually argumenative, but why not.
It is jargon, and did not appear to be completely understood.
Lack of experience does not preclude my offering clarification, and a suggestion - that would work.
The jargon comment was not directed, but I see how it looks that way.
Sorry to argue.
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0


               @ Terrorble, and Ghost,
for some reason when you guys speak it makes alot of sense to me. I think you must have some skill bonus to newbie dev relations or something.

@ Funky,
It seems you are a bit overly defensive. Quite understandable actually given the BS that goes on in online forums (or e-mail chains for that matter), and also due to the fact that text vs vocalizations lends messages transmited as such being open to much more interpertation from the receiver, than perhaps may have been originally intended. But be assured I appreciate your efforts to help me with this, as I do everyones. Sadly due to my own inexperience I have alot of trouble deciphering what you are saying.

@ All,
It seems there are competing ideas on how to achieve this goal. To me though they aren't competing just different alternatives (options are always good). Database item solutions seems more straight forward (and newbie friendly), yet Funky's approach seems more flexible (yet requires some basic understanding of the componets used [e.g. nwnx and its plugins, or MySQL], which unfortunately I don't have.)

Regardless, the server is set up with nwnx, and a mysql database, although it sounds like a database item approach would be workable with in that. I may try both in the dev mod and see what happens. Thank you again everyone so much!
Laz
               
               

               


                     Modifié par Lazarus Magni, 19 juin 2011 - 05:32 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0


               

Lazarus Magni wrote...
@ Funky,
It seems you are a bit overly defensive. Quite understandable actually given the BS that goes on in online forums (or e-mail chains for that matter), and also due to the fact that text vs vocalizations lends messages transmited as such being open to much more interpertation from the receiver, than perhaps may have been originally intended. But be assured I appreciate your efforts to help me with this, as I do everyones. Sadly due to my own inexperience I have alot of trouble deciphering what you are saying.

Defensive? Not at all. I just don't have a great deal of patience for people who insist on talking about things they don't understand. There's just more of that going on in this thread than usual.

In any event, if their comments have made you feel the need to try using a database item, then they've done you a disservice - it's actually more complex, as well as less useful, since you already have nwnx databasing set up. By all means, though, feel free to ignore the code I posted and do whatever you like. You can lead a horse to water... '<img'>

Funky
               
               

               
            

Legacy_Lazarus Magni

  • Hero Member
  • *****
  • Posts: 1837
  • Karma: +0/-0


               LOL Funky... I was just saying options are always good. Say in the future someone is using the standard nwn database, at least the alternatives presented here would give an option for them.

I most certainly am guilty of talking about things I don't understand, and believe me it is not by choice. It is pure necessity that I am having to confront these issues, and my lack of understanding is merely due to my inexperience along with the fact that other than these boards I am having to try to do this stuff on my own thus far.

I most certainly would like to try the script you made Funky, but I would prolly require some guidance unfortunately. I can make a new script in the mod by cut and pasting what you posted, and attach it to the onclient enter script (by adding the execute script xyx line to the end I think), but I don't know what " In that script, just Get the entering object," means, or how to do that.

P.S. My comment toward you was not meant to agitate. I love you man, your PW is awsome, and your contribution to the NWN community in general is outstanding. I have just noticed you seem to feel adversarial towards others with differing opinions here sometimes (which I am sure in the context of past interactions with people on these boards in general is prolly justified), but all I was saying is we are just all friends here, just people, with different knowledge bases, and bound by a common interest (nwn).

Cheers!
               
               

               


                     Modifié par Lazarus Magni, 19 juin 2011 - 08:32 .