Jump to content
Sign in to follow this  
rejenorst

(_name = name unit) Script to auto seperate first name from last name, how to?

Recommended Posts

Ok I am working on random mission generator scripts where I plan to combine a bit of voice acting and RPG elements.

Instead of using setidentity I thought it would be cool to voice act a bunch of the auto generated names in game.

Would anyone know how I could seperate the first name from the last name automatically from the string returned value of _name = name unit ?

I can save said value to an array so that it would be (for example):

["John Doe"]

Any tips for removing "Doe" so I am left with John? Keeping in mind that the last name could vary? Is there any way I can copy everything that comes before the space between John and Doe? Thanks. I honestly doubt that there is a way but I thought I'd venture the question.

Thanks for any help.

Share this post


Link to post
Share on other sites

Not tested...

_completeName = "John Doe";
_ar = toArray _completeName;
_namear = [];

{
   if (_x == 32) exitWith {};
   _namear set [count _namear, _x];
} forEach _ar;

_name = toString _namear;
// _name should now be "John"

Xeno

Share this post


Link to post
Share on other sites

Turn the name into an array of characters using toArray, then find the position of the first space character (32) using the find command. Then resize the array to only contain the characters until the first space using resize, and then convert it to a string again using the toString command.

_nameArray = toArray name player;
_nameArray resize (_nameArray find 32);
_newName = toString _nameArray;
hint _newName;[/Code]

Edited by Mondkalb
added missing underscores.

Share this post


Link to post
Share on other sites

Even better, lol (I always forget resize, stupid me).

Xeno

Share this post


Link to post
Share on other sites
Turn the name into an array of characters using toArray, then find the position of the first space character (32) using the find command. Then resize the array to only contain the characters until the first space using resize, and then convert it to a string again using the toString command.

_nameArray = toArray name player;
_nameArray resize (_nameArray find 32);
_newName = toString _nameArray;
hint _newName;[/Code]

Thank you very much the both of you! This has been a nagging question of mine for ages and I couldn't figue out how to do it.

I've tested the above and it works! Thank you so much Mondkalb :D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×