27.10.2015, 07:50
here some utils:
example usage for ReturnUser:
Code:
var IsNumeric = function(input) { return (input - 0) == input && (''+input).trim().length > 0; };
Code:
var ReturnUser = function(text) { if(IsNumeric(text)) { return $players[text]; } else { let found = []; for(let player of $players) { if(player.name.indexOf(text) != -1) { found.push(player); } } return found.length == 1 ? found[0] : found; } };
Code:
$server.on("PlayerCommandText", function(player, text){ let args = text.split(' '); let cmd = args.shift(); switch(cmd) { case '/pm': { if(isNaN(args[0])){ SendClientMessage( player, -1, "/pm [playerid/Part of Name] [message]"); return 1; } let arg1 = args.shift(); let target = ReturnUser(arg1); if(!target) { return player.message(-1, "Couldn't find " + arg1); } if(Array.isArray(target)) { return player.message(-1, "Found matches: " + _.pluck(target, "id").join(", ")); // include underscore.js } msg = args.join(' '); SendClientMessage(target.id, -1, `PM from ${player.name}: ${msg}`); return 1; } } return 0; });