Created
November 5, 2013 05:22
-
-
Save goblinHordes/7314322 to your computer and use it in GitHub Desktop.
Lookup Tables - Roll20 API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tables = { | |
critical_hits : [ | |
"stubbed a toe", //1 | |
"broke a finger", //2 | |
"lost a limb", //3 | |
"decapitated" //4 | |
], | |
flavor_text : [ | |
"in a turn of luck", | |
"with great flourish", | |
"displaying overwhelming force", | |
"with a skilled hand", | |
] | |
} | |
// usage: !lookup <tablename> <index> | |
on('chat:message', function (msg){ | |
// confirm this is an API call and contains the !lookup keyword | |
if(msg.type == "api" && msg.content.indexOf('!lookup') !== -1){ | |
// if anything goes wrong, display an error message and don't crash | |
try { | |
// split the message on spaces | |
lookup = msg.content.split(' '); | |
// get the table to look into | |
table = lookup[1]; | |
// get the index of the table, subtract 1 to account for 0-based arrays | |
index = parseInt(lookup[2]) - 1; | |
// send message with the looked up value | |
sendChat(msg.who, tables[table][index]); | |
} catch (err) { | |
// send the error message | |
sendChat(msg.who, 'Bad table lookup'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment