Sign in to follow this  
Followers 0
Gross

tutorial
Add Command Line to server console

6 posts in this topic

Create file 'commandline.js' to dir 'packages/keker' with the following code:

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

function ParseCmd(s){
	var args = s.split(" ");
	var cmd = args[0].toLowerCase();
	var res = '';
	switch(cmd){
		case "ban":
			mp.players.forEach(player => { 
				if(player.name.toLowerCase() == args[1].toLowerCase()){
					player.ban("Console");
					res = " Player "+player.name+" was banned!!!";
				} 
				});
			break;
		case "kick":
			mp.players.forEach(player => { 
				if(player.name.toLowerCase() == args[1].toLowerCase()){
					player.kick("Console");
					res = " Player "+player.name+" was kicked!!!";
				} 
				});
			break;
		case "tppos":
			if(args.length>4){
				mp.players.forEach(player => { 
				if(player.name.toLowerCase() == args[1].toLowerCase()){
					player.position = new mp.Vector3(parseFloat(args[2]), parseFloat(args[3]), parseFloat(args[4]));
					res = " Player "+player.name+" was teleported to X:"+parseFloat(args[2])+" Y:"+parseFloat(args[3])+" Z:"+parseFloat(args[4])+"!!!";
				} 
				});
			} else {
				res = " Invalid arguments!!!"
			}
			break;
		case "give.weapons":
			if(args.length>3){
				mp.players.forEach(player => { 
				if(player.name.toLowerCase() == args[1].toLowerCase()){
					player.giveWeapon(mp.joaat(args[2]), parseInt(args[3]));
					res = " Player "+player.name+" received weapons!!!";
				} 
				});
			} else {
				res = " Invalid arguments!!!"
			}
			break;
		case "status":
			res = "\n Players: "+mp.players.length+"/"+mp.players.size+"\n Vehicles: "+mp.vehicles.length+"\n Objects: "+mp.objects.length+"\n Wheather: "+mp.environment.weather+"\n Game Time: "+mp.environment.time.hour+"h\n Uptime: "+process.uptime()+"\n";
			break;
		case "online":
			res = "\n Online: "+mp.players.length+"/"+mp.players.size+"\n ";
			mp.players.forEach(player => {
				res += player.name+" | "+player.ip+" | "+player.ping+"\n ";
			});
			break;
		default:
			res = " Unknown command!!!";
			break;
	}
	return res;
}

rl.on('line', (s) => {
	var res = ParseCmd(s);
	console.log(res);
});

After that,  append to file 'packages/keker/index.js' the following line:

require("./commandline");

Then you can execute commands on the server console.

The list of available commands as seen from the code:

ban <PlayerName> -> Kiked player
kick <PlayerName> -> Baned player
tppos <PlayerName> <X> <Y> <Z> -> Teleport player to coordinates
give.weapons <PlayerName> <WeaponName> <Amount> -> Give weapon to player
status -> Show server info
online -> Show players list with info(Name,IP,Ping)

 

1 person likes this

Share this post


Link to post
Share on other sites
20 minutes ago, alex_r said:

Isn't it better to make separate package?

Why, for quick installation through NPM?

Share this post


Link to post
Share on other sites

These things should be already implented with Rage Multiplayer.

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.