Aller au contenu

Photo

Getting/setting PC's last name (help needed, please)


  • Veuillez vous connecter pour répondre
31 réponses à ce sujet

#1
Estelindis

Estelindis
  • Members
  • 3 699 messages
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!  ;)

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


#2
Shadooow

Shadooow
  • Members
  • 4 468 messages
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 .


#3
Estelindis

Estelindis
  • Members
  • 3 699 messages
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.

#4
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
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.

#5
Estelindis

Estelindis
  • Members
  • 3 699 messages
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. ;-)

#6
OldMansBeard

OldMansBeard
  • Members
  • 152 messages
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?

#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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;
    }



#8
Estelindis

Estelindis
  • Members
  • 3 699 messages
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!

#9
OldMansBeard

OldMansBeard
  • Members
  • 152 messages
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.
:)

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


#10
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.

#11
Estelindis

Estelindis
  • Members
  • 3 699 messages
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

#12
Estelindis

Estelindis
  • Members
  • 3 699 messages
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! :-)

#13
henesua

henesua
  • Members
  • 3 863 messages
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.

#14
Estelindis

Estelindis
  • Members
  • 3 699 messages
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.

#15
henesua

henesua
  • Members
  • 3 863 messages
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.

#16
OldMansBeard

OldMansBeard
  • Members
  • 152 messages
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 ?

#17
Estelindis

Estelindis
  • Members
  • 3 699 messages
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. :-)

#18
Estelindis

Estelindis
  • Members
  • 3 699 messages
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!

#19
AndarianTD

AndarianTD
  • Members
  • 701 messages
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.

#20
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#21
Estelindis

Estelindis
  • Members
  • 3 699 messages
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. :-)

#22
_six

_six
  • Members
  • 919 messages
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 .


#23
Estelindis

Estelindis
  • Members
  • 3 699 messages
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 .


#24
OldMansBeard

OldMansBeard
  • Members
  • 152 messages
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.

#25
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
 <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 .