Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

API to circumvent /emas

The lack of player /emas pretty much sucks in my campaign. Since this post exists, I know that /emas can be cheated, but since I'm not good at API, I don't know how to isolate it. If I use the linked API as is, I get an annoying green box that reads "Undefined" so I'm trying to find another way.
1393920371
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
on("chat:message", function(msg) { if (msg.type != "api") return; if(msg.content.indexOf(' ') == -1){ var msgMessage = null; var msgApiCommand = msg.content.substr(1, msg.content.length); }else{ var msgMessage = msg.content.substr(msg.content.indexOf(' ') + 1); var msgApiCommand = msg.content.substr(1, msg.content.indexOf(' ')-1); } if(msgApiCommand == "emas" && msgMessage != null){ var selectedObject = findObjs({_id: msg.selected[0]._id, _type: "graphic"}); sendChat(selectedObject[0].get("name"), "/me " + msgMessage); } }); Select a named token..... and enter "!emas attack with his sword!" Something like this should work. And you could use a macro like this with it: !emas ?{Emote what?|attacks!
1393928077
Alex L.
Pro
Sheet Author
Or the advanced version :P function parseString(str) { var re = /(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g; var res=[], arr=null; while (arr = re.exec(str)) { res.push(arr[1] ? arr[1] : arr[0]); } return res; } on("chat:message", function(msg) { var parseRes = parseString(msg.content); if(parseRes[0] == "!emas") { if(parseRes.length == 3) { sendChat(parseRes[1], "/me " + parseRes[2]); } else if(parseRes.length == 2) { var selectedObject = getObj("graphic", msg.selected[0]._id); if(selectedObject != undefined && "get" in selectedObject) { sendChat(selectedObject.get("name"), "/me " + parseRes[1]); } } } }); Just use: !emas "Hello World" While you ahve a token selected or: !emas "Alex L." "Hello How are you?" If you want to specify the name. if you want to use a sentence with spaces you must use quotes, if its just a single word with no spaces you don't have to !emas Alex Attacks <- Good !emas "Alex L" Attacks <- Good !emas Alex "Attacks Bob" <- Good !emas Alex L Attacks Bob <- Bad !emas Alex L "Attacks Bob" <- Bad !emas "Alex L" Attacks Bob <- Bad
I get the following error message from both: TypeError: Cannot read property '0' of undefined at evalmachine.<anonymous>:965:57 at eval (
1393948600
Alex L.
Pro
Sheet Author
Robert R. said: I get the following error message from both: TypeError: Cannot read property '0' of undefined at evalmachine.<anonymous>:965:57 at eval ( Can i make a guess and say you have a lot of other scripts installed?
1393948782

Edited 1393948933
No, just 2, and they're both working perfectly. Edit: I have disabled all other scripts but I am getting the same message.
1393948860
Alex L.
Pro
Sheet Author
Robert R. said: No, just 2, and they're both working perfectly. I would expect its an iteration with one of them as mine works fine on its own.
1393949078

Edited 1393949397
It is now the only script I have but it does not function, and I got the same error message. In fact, it never generates the error message until the moment I type "!emas Robert Attacks"
The simpler version might suit it better because it doesn't require quotes, but the simple one has even more trouble running.
But the biggest problem with #2 is as follows. !emas "I attack" #melee-basic-attack translates into /roll 1d20+blah blah blah I attack basically now all of my attack macros are backward.
Yeah. API commands always go into chat after regular commands, regardless of the order entered.
but in your script above the emote always happens first.
1393966296

Edited 1393966500
That's because I wrote it to do it that way. The emote is sent by the API not sent through the macro.
1393969159
Lithl
Pro
Sheet Author
API Scripter
The API can send messages to the chat via the sendChat function. sendChat, as far as I can tell, is asynchronous, which basically means "it will finish when it's done," and it allows other things to go on while it's working. If you mix API calls sending messages to chat with normal chat messages, the API messages will (almost) always come last. If you use multiple sendChat calls, they will (usually) appear in the same order sent, but you've got no real guarantee on the ordering when it comes to sendChat . HB's script guarantees the ordering of his card by using a single instance of sendChat which uses the /direct command (only available from sendChat) to send the entire power card at once. There is a slight chance that the emote will appear after the card in HB's script, but because he's already computed all of the text by that point (and assuming sendChat performs any sanity checks on the input, the power card's text is much longer and so will take longer to output), the chances are low that that will happen.
1393985268
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Robert R. said: I get the following error message from both: TypeError: Cannot read property '0' of undefined at evalmachine.<anonymous>:965:57 at eval ( Returns this error when macro action is: !emas "Hello World" AND no token is selected (for Alex's script.) What Robert is looking for could be possible if you parse out for the macros... and the emas macro was all one line like: !emas "Hello World" #melee-basic-attack
1394005021

Edited 1394005594
Alex L.
Pro
Sheet Author
I didn't really sit down to make a fully functional production script that will sit and handle user error well, but as it seems that is what is expected I present the uber emas script of doom with custom command parsing and follow on macro activation: Useage: !emas Message [options] [macros .....] Options: --Name name : sets the name, if you don't use this you must select a token or it will whisper an error. Macros can be anything "/r 1d20", but macros will not work, on the other hand abilities will, IE: Will work: !emas "Hello World!" --name Alex "%{bob|test}" This will not: !emas "Hello World!" --name Alex "#test" on("chat:message", function(msg) { function emas(arg, opt, who) { var Message = "", Who = "", i = 0, selectedObject = false; if(arg != undefined && arg.length > 0) { Message = arg[0]; if(opt != undefined && opt.name) { if(opt.name !== true) { Who = opt.name; } else { sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]"); sendChat("Api", "/w " + who + " Options: --Name : Supply a name."); return; } } else if(msg.selected != undefined) { selectedObject = getObj("graphic", msg.selected[0]._id); if(selectedObject != undefined && "get" in selectedObject) { Who = selectedObject.get("name"); } else { sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]"); sendChat("Api", "/w " + who + " Options: --Name : Supply a name."); return; } } else { sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]"); sendChat("Api", "/w " + who + " Options: --Name : Supply a name."); return; } sendChat(Who, "/me " + Message); if(arg.length > 1) { for(i = 1; i < arg.length; i++) { sendChat(Who, arg[i]); } } } else { sendChat("Api", "/w " + who + " Useage: !emas Message [Options] [Commands ....]"); sendChat("Api", "/w " + who + " Options: --Name : Supply a name."); return; } } function parseString(str) { var re = /(?:")([^"]+)(?:")|([^\s"]+)(?=\s+|$)/g, res=[], arr=null, arg = [], opt = {}, i = 0, optName = ""; while (arr = re.exec(str)) { res.push(arr[1] ? arr[1] : arr[0]); } for(i = 0; i < res.length; i++) { if(res[i].indexOf("--") !== 0) { // arg arg.push(res[i]); } else { optName = res[i].replace("--", "").toLowerCase(); opt[optName] = true; if((i + 1) < res.length) { opt[optName] = res[++i]; } } } return [arg, opt]; } if(msg.type === "api") { var parseRes = parseString(msg.content),Command = "", Who = "", i = 0, arg = [], opt = {}; if(parseRes != undefined && parseRes.length === 2) { opt = parseRes[1]; arg = parseRes[0]; if(arg.length > 0) { Command = arg[0].toLowerCase(); arg.splice(0, 1); //Remove the command. Who = msg.who.split(" ")[0]; if(Command === "!emas") { emas(arg, opt, Who) } } } } });
1394015785
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Alex L. said: I didn't really sit down to make a fully functional production script that will sit and handle user error well, but as it seems that is what is expected I present the uber emas script of doom with custom command parsing and follow on macro activation: LOL