Author Topic: Unique ID String for PCs and NPCs  (Read 402 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« on: October 30, 2012, 02:56:06 pm »


               I've found a need to generate unique ID strings for NPCs and PCs. I posted it to Pastebin:

GetPCIdentifier(object oPC)

Feedback is welcome.

NOTES:
Uses of PC string should be obvious as that couplet is commonly used. Feel free to ask if this is a new concept to you. The NPC string however is a novel solution as far as I am aware. Feel free to let me know about "the first solution" if this is simply a reinvention of one.

Intentions of the NPC string:
  • Easily differentiate NPC from PC
  • Uniqueness across server resets
  • Enable finding the NPC by ID, extract TAG from ID, retrieve creatures by tag, then look for one that has same unique ID.
Hopefully this solves the typical problems of storing IDs of instantiated objects in a database. Anything I missed?
               
               

               


                     Modifié par henesua, 30 octobre 2012 - 02:57 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« Reply #1 on: October 30, 2012, 04:24:16 pm »


               I a not at the house right now and the leicon was not uch hel ( and this keyoard is dying)  ut is not 
StringReplace a core NWN function 
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« Reply #2 on: October 30, 2012, 05:48:53 pm »


               No it isn't. I just checked. Perhaps it is in an include?

Anyway, what does it do? I'm not clear on how that relates to what I posted.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« Reply #3 on: October 30, 2012, 07:33:37 pm »


               I think lightfoot8 is noticing that you seem to be doing a lot of string replaces by hand to put
in the fancy symbols.  It's in  x3_inc_string.

Out of curiosity, why does it matter if there are * or : or whatever in your returned ID? Those
are not any of the things you are using for delimiters. It shouldn't matter what characters are
in the name as long as they are not what you are using...

And as an aside, why are you using characters that are hard to print or type?

Cheers,

Meaglyn
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« Reply #4 on: October 30, 2012, 09:32:41 pm »


               Meaglyn, I have some other systems that are data intensive with long strings and lots of delimiters. When I inject the ID of a PC or NPC into it I want to ensure that I won't mess up my parsing of those long strings.

I'll check out x3_inc_string and see if I can do some of my string manipulation more efficiently. Thanks.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« Reply #5 on: November 04, 2012, 06:24:56 pm »


               

henesua wrote...

Meaglyn, I have some other systems that are data intensive with long strings and lots of delimiters. When I inject the ID of a PC or NPC into it I want to ensure that I won't mess up my parsing of those long strings.

I'll check out x3_inc_string and see if I can do some of my string manipulation more efficiently. Thanks.


Sorry for taking so long in getting back to this. ..


Since the function is not an internal one I would not worry to much about looking at the X3 version of it. 

....

The only thing in your script that raises a flag for me is line 22:
 
sPCID   = GetName(oPC)+"¤"+GetPCPlayerName(oPC);

The GetPCPlayerName function returns the name in the case that the player used to LogIn with. For exsample if I had an account Name of lightfoot8 I could use any case to log in with: Lightfoot8, LightFoot8, LIGHTfoot8, lightFOOT8; would all be valid way to log into the same account with the MS being down. If you need to even worry about this here is dependent on how you have handled the same problem in your custom security. If you have not handled it in your custom security. you may want to look here for a possiable way to handle it.

EDIT: Read down a few posts in the link to the get the full picture.
               
               

               


                     Modifié par Lightfoot8, 04 novembre 2012 - 06:27 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Unique ID String for PCs and NPCs
« Reply #6 on: November 04, 2012, 06:58:31 pm »


               interesting... I did not think about that. I'll look at how I handle case in my custom security, thanks.