Read player Username script?

so i want to know it is possible to use a script to check and read for the player's computer username and save that name as an actor id name? i found this thread: https://forums.rpgmakerweb.com/inde...sert-your-windows-username.87772/#post-800193 but since i am a noob and stupid i honestly dont understand anything, so plz help me if you know da wea, also thanks for reading
I don't think there is, and honestly any program who tries that is probably going to get flagged as a virus as well, due to how it would probably have to access windows registry to get that info, and since MV runs as a web program, web program accessing the registry tends to not go over well.

Now maybe there is a way without getting flagged as a virus, but as of yet I've not found it.
I don't think there is, and honestly any program who tries that is probably going to get flagged as a virus as well, due to how it would probably have to access windows registry to get that info, and since MV runs as a web program, web program accessing the registry tends to not go over well.

Now maybe there is a way without getting flagged as a virus, but as of yet I've not found it.
that was sad, thanks for the reply dude
Like bgillisp said, might be flagged by anti-virus programs (your mileage may vary etc. etc.), but Node.js/nwjs is designed to be able to interact with your operating system. I tried it and it worked fine for me in a test play of a game (I did not try in a deployed version).

However, the only way you'll know is if you try it yourself.

How to get the host name:
Inside an event, use a Script Call with the following:
Code:
var os = require('os');
$gameActors.actor(X).setName(os.hostname());
Where X is the ID# of the actor.

The host name is the name of the computer, but not the name of the user. To get the name of the user it is more complicated. Try it on a test project first.

How to get the user name (Windows instructions. May be slightly different for Mac/Linux):

1.
Install Node.js on your computer. RPG Maker MV already uses 'nwjs' which is a framework that combines Node.js and Chromium to be able to run HTML/CSS/JS through an application window. A feature of this is that it also allows interaction with the OS (operating system).

https://nodejs.org/en/download/

Why download Node.js if it's already incorporated into the 'nwjs' in RPG Maker MV? The version of Node.js in RPG Maker MV is old and doesn't have access to the functions needed here. Technically, it is not required to download Node.js for this step, what you really need is the 'npm' package manager. But npm comes installed already with the Node.js download so it's easiest to download together. If you want to just download npm you can do that too.

Take note of where these files are downloaded to in case you need to move it later.

2. Open the Command Prompt on your computer (on windows it is 'cmd' from the start menu)

3. Type into the Command Prompt and press enter:
Code:
cd [path to your project's js folder]
The path is the entire path to your project's js folder. For example mine looks like this:
cd C:/Users/me/Documents/RPGMakerMV/Games/TestProject/js

Make sure that the text in front of your command now reflects the full path to the js folder.

4. Type into the Command Prompt and press enter:
npm install --save user-info

(source: https://github.com/sindresorhus/user-info)

5. Check your files. If this is all done right, your project's js folder should contain 3 sub-folders: libs, plugins, and node_modules (NEW)
Inside the node_modules folder should be a folder called "user-info" which contains some files.

6. Inside an event, use a Script Call with the following:
Code:
var userInfo = require('./js/node_modules/user-info/index.js');
$gameActors.actor(X).setName(userInfo().username);
Where X is the ID# of the actor.
Like bgillisp said, might be flagged by anti-virus programs (your mileage may vary etc. etc.), but Node.js/nwjs is designed to be able to interact with your operating system. I tried it and it worked fine for me in a test play of a game (I did not try in a deployed version).

However, the only way you'll know is if you try it yourself.

How to get the host name:
Inside an event, use a Script Call with the following:
Code:
var os = require('os');
$gameActors.actor(X).setName(os.hostname());
Where X is the ID# of the actor.

The host name is the name of the computer, but not the name of the user. To get the name of the user it is more complicated. Try it on a test project first.

How to get the user name (Windows instructions. May be slightly different for Mac/Linux):

1.
Install Node.js on your computer. RPG Maker MV already uses 'nwjs' which is a framework that combines Node.js and Chromium to be able to run HTML/CSS/JS through an application window. A feature of this is that it also allows interaction with the OS (operating system).

https://nodejs.org/en/download/

Why download Node.js if it's already incorporated into the 'nwjs' in RPG Maker MV? The version of Node.js in RPG Maker MV is old and doesn't have access to the functions needed here. Technically, it is not required to download Node.js for this step, what you really need is the 'npm' package manager. But npm comes installed already with the Node.js download so it's easiest to download together. If you want to just download npm you can do that too.

Take note of where these files are downloaded to in case you need to move it later.

2. Open the Command Prompt on your computer (on windows it is 'cmd' from the start menu)

3. Type into the Command Prompt and press enter:
Code:
cd [path to your project's js folder]
The path is the entire path to your project's js folder. For example mine looks like this:
cd C:/Users/me/Documents/RPGMakerMV/Games/TestProject/js

Make sure that the text in front of your command now reflects the full path to the js folder.

4. Type into the Command Prompt and press enter:
npm install --save user-info

(source: https://github.com/sindresorhus/user-info)

5. Check your files. If this is all done right, your project's js folder should contain 3 sub-folders: libs, plugins, and node_modules (NEW)
Inside the node_modules folder should be a folder called "user-info" which contains some files.

6. Inside an event, use a Script Call with the following:
Code:
var userInfo = require('./js/node_modules/user-info/index.js');
$gameActors.actor(X).setName(userInfo().username);
Where X is the ID# of the actor.
thanks for the help it does work for a deployed game but i dont know if it will work when other people download and play the game , i can't test it yet
FYI in the new version of MV (v.1.6.0), there is no need to download anything extra.

In a Script Call just use this and it's already built in.
Code:
const os = require('os');
$gameActors.actor(X).setName(os.userInfo().username);
// X is the Actor ID# that you wish to set as the player's username
As an aside - before implementing this, consider player reaction. At least some (if indeed, it's not many) would find this creepy/intrusive, or would easily assume that somehow malware had been installed. Just something to bear in mind.
FYI in the new version of MV (v.1.6.0), there is no need to download anything extra.

In a Script Call just use this and it's already built in.
Code:
const os = require('os');
$gameActors.actor(X).setName(os.userInfo().username);
// X is the Actor ID# that you wish to set as the player's username
wow cool, thanks dude
FYI in the new version of MV (v.1.6.0), there is no need to download anything extra.

In a Script Call just use this and it's already built in.
Code:
const os = require('os');
$gameActors.actor(X).setName(os.userInfo().username);
// X is the Actor ID# that you wish to set as the player's username
Any way to make this work wit VX Ace?
Currently it just gives off the error message:
"no such file to load -- os"
Any way to make this work wit VX Ace?
Currently it just gives off the error message:
"no such file to load -- os"
I found this script
but it just says the name of the pc and not the user

I found this script
but it just says the name of the pc and not the user
Okay, I'm stupid. For anyone else looking for this, you just need to define the ENV as ["USERNAME"]

@herohammerstudios , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.


This thread was also solved 5 years ago, so I'm closing it.

Original thread: https://forums.rpgmakerweb.com/threads/read-player-username-script.91546/