Ah, matty goes the DIY way again!
However, I think you have a small error in your error handling. When
parseFloat can't convert
Param into a valid floating point number, it'll return
NaN. Now,
NaN isn't just a string containing those three letters, it's a special value and - ironically - is of the type Number.
The correct way to see whether the result is valid is by using the
isNaN function provided by JScript/JavaScript. I also recommend doing the
parseFloat call after confirming that the /random command was sent. So, this would be the corrected code:
js code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage){
if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {
var Command = RegExp.$1.toLowerCase();
var Param = RegExp.$2;
switch (Command) {
case 'random':
>>> if (!isNaN(Param = parseFloat(Param))) {<<<
return Math.floor((Param)*Math.random());;
} else {
return '';
}
}
}
return sMessage;
}
Yes, that line is perfectly valid. First I re-assign Param to the parseFloat result, then that result is checked against isNaN. Neat, uh?