Author Topic: Getting/setting PC's last name (help needed, please)  (Read 631 times)

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« on: August 29, 2011, 09:09:38 pm »


               I'm an intermediate-level scripter.  I've been poring through NWN Lexicon and the old forum archives for a way to do what I want, but I keep seeing that NWNX is needed.  Perhaps that's still the case, but perhaps not; a lot of the posts I found seemed fairly old.  (For the record, I'm not opposed to using NWNX at all.  I just don't like the idea of forcing my module's potential players to use it too, just for the sake of one little thing.)

Anyway, I want to write a script that will check if the PC has a last name.  If the PC doesn't, then he or she will be given a default last name.  The trouble is, the function GetName is described in the Lexicon as follows: "Returns the first and last name of oObject. In the case of creatures, returns first and last names together as single concatenated string."  So how do I separate the last name from the first name?  This is even leaving aside for the moment the fact that, without NWNX, there doesn't seem to be a function that will set a PC's name (as opposed to, say, that of an NPC).

If anyone is wondering why I don't just tell all players to make sure their character has a last name as part of the module description (and thereafter just use the standard <LastName> token in conversation), the trouble is that I am using a background system that gives the player a different role in the story based on the PC's class and alignment.  If the PC meets certain criteria, s/he will be a member of a family of particular historical importance, and the module will use the PC's last name at all times when referring to that family.  If the PC meets different criteria, an NPC will take on that role, and the module will use that character's last name instead.  Accordingly, it would be really handy if I could make a custom token and set it as the PC's last name or the default last name (depending on what the PC is like).  Otherwise, I'll have to put a boatload more conditionals into my conversations every time I want to mention the family.  It's doable, but it'll be awkward.  Something nice and simple that I only have to do once, at the start of the module, would be much better. 

Thanks for reading!  '<img'>
               
               

               


                     Modifié par Estelindis, 29 août 2011 - 08:10 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #1 on: August 29, 2011, 09:21:55 pm »


               Funky has a good function for it (I let him to post it), realible for english users in most cases but still not perfect. Other than that its possible to retrieve it from BIC file via NWNX though there probably isnt any public plugin that could do that and I guess that NWNX isnt any good for you anyway. EDIT: Leto of course can do that but its kinda abadoned now.

One workaround could be to allow player to set his last name by himself if the one substracted from full name doesnt match.
               
               

               


                     Modifié par ShaDoOoW, 29 août 2011 - 08:24 .
                     
                  


            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #2 on: August 29, 2011, 09:24:50 pm »


               Thank you, ShaDoOoW.  :-)  I eagerly await anything Funky might like to add as well.

In the meantime, I am checking out NWNX to see what extra features it might bring to the mix that might allow me to exceed regular NWN's boundaries!  But yes, it's possible that it might not be for me.  It seems like it's more of a PW tool than one for SP, to my novice eyes.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #3 on: August 29, 2011, 09:35:20 pm »


               If this is a single player module, can't you set a unique custom token for the last name, and just use that through the whole module?  The name itself could also be stored as a string on the character for times it's needed to be pulled up, or even as an int if there are only a few families they can be part of.
 The only issue I can think of doing that way, is if a custom token doesn't persist through a save game.  I'm not sure how you would go about setting again at game load, unless the regular on player enter event still fires.
               
               

               
            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #4 on: August 29, 2011, 09:42:15 pm »


               Yes, I can, but I want to be able to use the PC's last name as that token in certain situations.  Accordingly, I'm trying to figure out how to get just the PC's last name as opposed to the whole name.

As I said, I can just run the class/background alignment check every time, and either use my custom name or the PC's name on different conversation nodes, but that would be really clunky.

I'm assuming custom tokens persist in saves.  I've never seen any evidence to the contrary.  Now you're making me paranoid, though.  ;-)
               
               

               
            

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #5 on: August 29, 2011, 10:10:43 pm »


               Este - it would be simple enough to make a function that gets the last (or only) word of the GetName() - assuming spaces as separators - but it wouldn't distinguish between a first name with no last name as opposed to a last name with no first name. Would that matter?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #6 on: August 29, 2011, 10:31:54 pm »


               Event though the tokennizer in x0_i0_stringlib is not the most effecient code. you could use it to quickly easily find the information you are after. 

example:

#include "x0_i0_stringlib"
void main()
{
   object oPC = GetFirstPC();
   string FullName =GetName(oPC);
   string FirstName, LastName;

    int nNumOfNames = GetNumberTokens(FullName," ");
    switch (nNumOfNames)
    {
      case 1: // PC only has a first name.
         FirstName = FullName;
         LastName  = "Your choice";
         break;
      case 2: // PC has a firs and last name.
         FirstName = GetTokenByPosition(FullName," ",1);
         LastName =  GetTokenByPosition(FullName," ",2);
         break;
      default:// something odd is going on.  need more information.
         // what ever you want to do here. Perhaps start a
         // conversation with the player so the can clairfy.
         break;
    }


               
               

               
            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #7 on: August 29, 2011, 11:19:29 pm »


               You are both quite right, I believe. :-)  

OMB, while exploring the larger function library, I started to wonder if looking for " " via FindSubString() would do the trick to separate the words.  I assume that this, or, more likely, some even simpler approach is what you mean. Yes, that would definitely do the trick. All I'd have to do would be to ask any prospective player to make sure to give his or her character a last name. Besides, if they didn't (i.e. no spaces found in the character's name), I could just set the token containing the last name to a certain default value. It wouldn't appear on their character sheet, but that woukdn't be the end of the world. Thank you.  :-) (It does make me wonder a bit about the intricacies of your OHS, though! If there are so many things you can do to most creatures but not to PCs, how much work must it have taken you to make the game swap PCs and henchies around? But maybe this musing only reveals deeper chasms of my ignorance.)

Lightfoot, I had never even heard of the tokennizer.  I had thought I'd struggled (torturously!) above the level of beginner scripter, but I definitely need to downgrade my self-estimation. ;-) That looks like it would do the job. Thanks!

I'm going to try your suggestions and see what happens (though, of course, if anyone wishes to add other suggestions, they're more than welcome). I really appreciate the help. What a great community we still have!
               
               

               
            

Legacy_OldMansBeard

  • Full Member
  • ***
  • Posts: 245
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #8 on: August 29, 2011, 11:38:54 pm »


               Yes, I was thinking of FindSubString() to look for spaces - something like this -
<nwscript>
string GetLastWord(string sString)
{
 int len = GetStringLength(sString);
 if (len <= 0) return sString;

 int c = FindSubString(sString," ");
 if (c == -1) return sString;

 return GetLastWord(GetStringRight(sString,len-c-1));
}
</nwscript>
but the tokeniser does it for you, so that's probably better.

I like your idea. Like DA but more flexible.
'<img'>
               
               

               


                     Modifié par OldMansBeard, 29 août 2011 - 10:39 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #9 on: August 29, 2011, 11:49:40 pm »


               There is also another string parser in x3_inc_string. with the functions:   StringParse  and  StringRemoveParsed.   That will work just about the same way as OMB script above.   they allow you to parse the tokens Left to right    or  right to left.
               
               

               
            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #10 on: August 30, 2011, 12:01:23 am »


               That tokenizer is wonderful. It will make lots of excellent things possible for me. I must better familiarise myself with more include files. Thank you again! :-D
               
               

               
            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #11 on: August 30, 2011, 12:18:46 am »


               Sorry for the double post, but the device I'm using to write this doesn't seem to like editing posts.

Thanks for the additional comments.  That other include file will be handy, Lightfoot, I have no doubt.  And I'll learn lots from examining the script you wrote, OMB, even though the tokenizer does seem fine.  And I'm glad you like the idea, by the way.  :-)  I'm trying to implement a genuinely branching narrative with meaningful choices, but to do that I need to set up a number of discrete story roles into which the PC can fit, depending on class and alignment.  There always have to be restrictions somewhere (or the game/module will never be finished); the trick is to turn them into a gameplay strength that adds flavour to the world and story rather than a weakness that diminishes the player's enjoyment. I hope I end up succeeding!

I have put thanks to you both in the script documentation. Now to write more. Hurrah! :-)
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #12 on: August 30, 2011, 05:57:33 pm »


               That sounds like a very interesting project, Este. I am trying to do something similar in terms of branching narrative, but decided to narrow it down to three main branches of story so I could focus on complex dialog. Hopefully we will both release our projects and then be able to learn from one another.

I also had to write functions for splitting up the name - something along the lines of what oldmansbeard has shown although I was focused on getting the first name.

I am wondering in your case if you could change the PCs name in a starting area to work with the background system you have going. Perhaps there are old families specifically named in your setting with different resources/curses/social standing, and a player would have the choice to select between them. You'd then alter the PCs name with SetName appending the surname to the end.
               
               

               
            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #13 on: August 30, 2011, 09:07:34 pm »


               That's the whole thing; I believe that SetName doesn't work on PCs.  I'm getting around it by setting the noble family's name as a custom token (pulled from the PC's last name under certain conditions but set as a certain default name otherwise).  It would be ideal if there was a way to easily get and set PCs' last and first names, though. A character should be able to take her NPC husband's name if they get married (if she wants, obviously).

I'm interested that you're working on something similar to what I've described and I'd be delighted to play your module once it's done.  :-)

By the way, since I last posted I've mucked about with the scripts by OMB and Lightfoot and have greatly improved my understanding of some principles.  Thanks to both again.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #14 on: August 30, 2011, 09:24:41 pm »


               SetName doesn't work on a PC? Wow. That sucks. I had been counting on using it down the road along with SetDescription. I'll run tests this evening.

I suppose the problem relates to how the game stores PC data in a bic file. I am sure NWNX has an app for that to help the multiplayer mods.