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

Legacy_OldMansBeard

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


               Este - could you sidestep the problem by supposing that the PC's last name comes from his father but that he is entangled with one of the important plot families on his mother's side (so the name is different but the family connexion is still powerful). Or the other way around - he is illegitimate and has his mother's last name but his natural father is from an important plot family with a predetermined name ?
               
               

               
            

Legacy_Estelindis

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


               Sub-optimal, isn't it? I actually didn't test it myself due to the documentation and multiple thre   ads saying it wouldn't work, so let me know how things go. But yes, my understanding is that NWNX allows one to set a PC's name. :-)
               
               

               
            

Legacy_Estelindis

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


               OMB, that's a brilliant idea.  I'll think about it.  :-)

Honestly, the family tree has been part of the backstory of various campaigns of mine for so long that it never even occurred it me to have the family connection come from the mother's side. It was all set in stone in my head; no open mind at all. Thank you for giving me a fresh perspective!
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #18 on: August 31, 2011, 03:56:57 am »


               Sorry to come into this late. The only way I've ever been able to get this to work is to assume that there are no spaces in the first name, use GetName(), and substring out the pieces using the first space as the delimiter. It works fine as long as the first name has no spaces in it, which may be a reasonable assumption.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #19 on: August 31, 2011, 05:06:26 am »


               Going off what Lightfoot suggested I would use the StringParse function (included in "x3_inc_string"). The only draw back to this, as with other methods, is that the player can not have spaces in the LAST name to get the whole last name. Otherwise it will only return the last part of the last name. But that does leave players to create whatever weird first name they want, spaces and all.

Function:

#include "x3_inc_string"
//Works if no spaces in last name. Otherwise returns last part of last name.
string GetLastName(object oPC)
{
    string sName = GetName(oPC);
    string sParse = StringParse(sName, " ", TRUE);
    return sParse;
}

Function used in script:

void main()
{
    object oPC = GetLastUsedBy();
    string sLastName = GetLastName(oPC);
    SendMessageToPC(oPC, "My last name is: " + sLastName);
}
               
               

               


                     Modifié par GhostOfGod, 31 août 2011 - 04:09 .
                     
                  


            

Legacy_Estelindis

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


               Thank you both very much, Andarian (whose "lateness" I can hardly complain about, given the hurricane!) and GhostOfGod.  In the end, I used OMB's script for exactly the reason to which you allude: characters' full names can contain a variable number of words, but OMB's function returns only the very last word of the string. On reflection, I think this is the best approach (given the limitations we work under), because, as you point out, one sometimes sees characters who are named along the lines of Hal the Horrid or Ashara of Silverwood; Lord Horrid or Lady Silverwood wouldn't sound too bad.  Admittedly it won't always yield good results (Niall of the Nine Hostages becomes Lord Hostages rather than the more impressive - and infernal-sounding! - Lord of the Nine), but one can't have everything. ;-) However, GhostOfGod's script yields the same result as OMB's but looks even cleaner (using #include resources as it does). It might be more efficient to use OMB's in terms of zots, though (not needing to #include other files). Either way, I have some excellent resources thanks to you all, and I will study StringParse to better understand how it works; I'm sure I'll end up using x3_inc_string many times before my module is done. :-)
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #21 on: August 31, 2011, 01:12:22 pm »


               Click here

This script will split the firstname/lastnamer either at the last word (so John Paul Revelator becomes first name "John Paul" last name "Revelator"), or at the first 'connective'. So John Paul the Revelator becomes first name "John Paul" last name "the Revelator". That means your Niall of the Nine Hostages will become Lord of the Nine Hostages perfectly fine.

I'm not really big on nwscript, so someone else may be able to point out any efficiency flaws. I've tested it out pretty hard in the last, er, hour though and can confirm it works on every set of connectives I could think to include ':bandit:'
               
               

               


                     Modifié par _six, 31 août 2011 - 12:24 .
                     
                  


            

Legacy_Estelindis

  • Hero Member
  • *****
  • Posts: 935
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #22 on: August 31, 2011, 01:25:02 pm »


               Wow, thanks Six!  Even more goodies to play with!  I will experiment with this one as well.  :-D  To be honest with you, what I most need to get to grips with in your script in the syntax.  I mean, I get that it works - but I like to learn to understand the scripts people give me, so that I can make similar scripts myself later on without needing to ask for help.  I get the feeling that what I learn from this particular script will hugely increase what I can do in the future. :-)

A point to consider: while Lord of the Nine Hostages (for example) is an impressive title, speaking about the of the Nine Hostages Family is less so; either I'll modify the function to set an extra token, or I might simply use the formula "House <LastName>.  Anyway, I have a giant toolbox to use, only getting better with every wonderful post added to this thread.  ;-)
               
               

               


                     Modifié par Estelindis, 31 août 2011 - 05:51 .
                     
                  


            

Legacy_OldMansBeard

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


               This is starting to get interesting! Coding aside, it's obviously not enough to parse the full name syntactically into words and spaces; we need to consider the semantics too.

Compare:
  • John James the Gaunt
  • John James of the Gaunt Countenance
  • John James of Gaunt
  • John James Gaunt
  • Gaunt John James
  • John James de la pays de Gaunt
  • John James de la Pays
  • John James de Gaunt
  • John de Gaunt James
  • John James von Hohen Gaunt
  • John von Hohen-Gaunt James
  • John James
  • John Jamessohn
  •  ...
In some cases we can see that the family name is 'James', sometimes 'Gaunt', sometimes neither. There are different conventions at work. If we can define a set of rules that cover most cases (rather than the single rule of "take the last word", which was my starting point), we can probably code them.
               
               

               
            

Legacy_Rolo Kipp

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


                <blows the dust off an old tome...>

As an inspiration (can't believe he's still around!), look at what EBoN does :-)

Rules for locations and race/cultures... sweet :-)

<...and looks up some long lost friends>
               
               

               


                     Modifié par Rolo Kipp, 31 août 2011 - 05:21 .
                     
                  


            

Legacy_Failed.Bard

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


               Perhaps a script that breaks the names up, in various formats based on space location, and then asks the PC in a convo to select the portion of it that is the last name?

 To use the "John James de la pays de Gaunt" name example, your options would be:

1: James de la pays de Gaunt
2: de la pays de Gaunt
3: la pays de Gaunt
4: pays de Gaunt
5: de Gaunt
6: Gaunt
7: No last name

 Not ideal still, but it does beat trying to guess the naming conventions the player used.  The next step in the conversation could be in selecting the family, if more than one would be applicable.
               
               

               
            

Legacy__six

  • Hero Member
  • *****
  • Posts: 1436
  • Karma: +0/-0
Getting/setting PC's last name (help needed, please)
« Reply #26 on: August 31, 2011, 08:25:28 pm »


               Part of the problem in coding this comes in deciphering how much of the name is there only for clarification. For instance Edward Elric von Hohenheim could be first name Edward, middle name Elric, with von Hohenheim taking the place of a surname. Or it could be Edward Elric who happens to live in Hohenheim (or is the son of Hohenheim, maybe). There's no real way of determining the intent from grammar alone.

However, calling him Lord von Hohenheim makes sense in either situation, which is why I lean towards the first connective approach as a simple catch-all. However, when referring to a family as a whole, Este has quite rightly pointed out a major flaw. This has got me thinking, and the presenting the player with options might be the best idea, albeit a convoluted and more complex one. I have the image in my head of giving the player a slider to slide back and forth across the name where they want to 'slice' it, but thats not really doable in NWN.

Another might be to request name re-input by the player using the chat bar on entering the module. This would remove the need for any scripted calculations. But it'd also feel a little spoilsportish.
               
               

               


                     Modifié par _six, 31 août 2011 - 07:29 .
                     
                  


            

Legacy_Failed.Bard

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


               

_six wrote...
However, calling him Lord von Hohenheim makes sense in either situation, which is why I lean towards the first connective approach as a simple catch-all. However, when referring to a family as a whole, Este has quite rightly pointed out a major flaw. This has got me thinking, and the presenting the player with options might be the best idea, albeit a convoluted and more complex one. I have the image in my head of giving the player a slider to slide back and forth across the name where they want to 'slice' it, but thats not really doable in NWN.


  Actually, I think with coloured text, that would be doable.

  The name would be displayed as a token, cursor move back and forth options in the convo.  Set start of last name, set end, and finished for options.

  I'll post findings on it as soon as I finish writing it up.
               
               

               
            

Legacy_Estelindis

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


               

OldMansBeard wrote...

This is starting to get interesting! Coding aside, it's obviously not enough to parse the full name syntactically into words and spaces; we need to consider the semantics too.  <snip>  There are different conventions at work. If we can define a set of rules that cover most cases (rather than the single rule of "take the last word", which was my starting point), we can probably code them.

Indeed!  I'm glad this has ended up offering so much food for thought...  *ponders problem*

Let's imagine that, after finding all the sub-strings separated by spaces, we identify some of them as prepositions and conjunctions by checking them against a list.  (If we identify no such sub-strings, we just use the standard method of making the first word the first name and the last word the last name.)  Of the femaining words, our default position is that whatever sub-string (possibly including spaces) comes before the first conjunction or preposition (excluding any conjunction or preposition that might begin the whole string) is the most important part of the first name.  Similarly, whatever sub-string comes after the last conjunction or preposition is taken to be the most important part of the last name. 

That was quite a mouthful, so, to summarise: The Duke of the Dark Plains of Lirandon -> Duke Lirandon.

Under these rules, OMB's list of names would yield the following results; non-ideal results are bolded:

  • John James the Gaunt -> John James (first name), Gaunt (last name)
  • John James of the Gaunt Countenance -> John James (first name), Gaunt Countenance (last name)
  • John James of Gaunt -> John James (first name), Gaunt (last name)
  • John James Gaunt -> John (first name), Gaunt (last name)
  • Gaunt John James -> Gaunt (first name), James(last name)
  • John James de la pays de Gaunt -> John James (first name), Gaunt (last name)
  • John James de la Pays -> John James (first name), Pays (last name)
  • John James de Gaunt -> John James (first name), Gaunt (last name)
  • John de Gaunt James -> John (first name), Gaunt James (last name)
  • John James von Hohen Gaunt -> John James (first name), Hohen Gaunt (last name)
  • John von Hohen-Gaunt James -> John (first name), Hohen-Gaunt James (last name)
  • John James -> John (first name), James (last name)
  • John Jamessohn -> John (first name), Jamessohn (last name)
 

Of all these, the ones that cause problems are those that have adjectives and nouns playing together, but I cannot think of any way of distinguishing between nouns and adjectives that is not mind-bogglingly clunky.  It's possible we might be able to weed out titles that people put into their names, though, as the list of titles is relatively small compared to, say, all adjectives.  ;-)

To make provision for eventualities not covered by this system, we could follow Bard's idea of letting the PC choose from a number of possibilities via conversation.  I think I'd have the character in my module find out about his or her family through an old book; the PC would get the chance to choose a "best" translation of the family name through that conversation, with possible options for choosing being set via script and the player having the option to type a name into the chat window as a last resort.
               
               

               


                     Modifié par Estelindis, 31 août 2011 - 10:28 .
                     
                  


            

Legacy_Failed.Bard

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


               Okay, the script is finished.  There's a clip as an example of how it works here:





New permanent link here:

  String parsing in that way is far more annoying to script than I expected.

Edit:  Sorry for the quality, or lack thereof, in the video.  It's enough to give an example though, even if the text is hard to read.
               
               

               


                     Modifié par Failed.Bard, 21 septembre 2011 - 11:40 .