Jump to content

How to make a list of players online


Switel12

Recommended Posts

I can give you an example of how to do this. If you have a MYSQL Connection, as soon as a player connects you can make his status in the mysql database 1 or true. Then you can make a page for example with PHP and MYSQL which is selecting all the players with that status equal to 1 or true(depends of the state you set when he connects). That will print that player list. As soon as you have this you can make more and more stuff with it.

Edit: Also, when he disconnects set his status to 0 or false.
This online variable in the database needs to be rebooted to 0 or false everytime the server restarts in order to set all the players offline, since if the server crashes for example it doesnt recive any player disconnects anymore!

Edited by Atesh
Link to comment
Share on other sites

To create a list in-game, all you have to do is just loop through the players pool and this gets every player on the server.

mp.players.forEach(function(user){
  	console.log(`Player: ${user.name}`);
});

Instead of a console.log, you'd do whatever you wanna do to display the users.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...