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

[Script] !me to whisper to the player invoking it. Like /w self if self always resolved to your player's name.

Is there a way, through API or existing means, to have the game self identify who the player is so that any chat with the respective call will return who it is that called it?  I know of the "/talktomyself" deal.  But what I'm looking for would go in Macros to have the chat output ONLY register to them.  Currently I have to "/w gm" in macro menus all the time, which clutters my screen when it is called by 6 players.  Is there a better way? what I'm looking for would be something like (in game): /w self Hello to myself ... or, if an API exists, /w !SelfID   Hello to myself ... which would output: (To Wolf Thunderspirit):  Hello to myself ... based on my account name, but the exact same call would output to the "Blarg account" as: (To Blarg):  Hello to myself ...
1532270123

Edited 1532299689
The Aaron
Pro
API Scripter
That's a great idea! As a stopgap, you can use this script.  It's imperfect as you can't hover the inline rolls (they just show as numbers), but I might be able to fix that. !me Hello to myself ... Script: on('ready', () => { const processInlinerolls = (msg) => { if(_.has(msg,'inlinerolls')){ return _.chain(msg.inlinerolls) .reduce(function(m,v,k){ let ti=_.reduce(v.results.rolls,function(m2,v2){ if(_.has(v2,'table')){ m2.push(_.reduce(v2.results,function(m3,v3){ m3.push(v3.tableItem.name); return m3; },[]).join(', ')); } return m2; },[]).join(', '); m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } else { return msg.content; } }; let lastPlayerId; on('chat:message', (msg) => { if('api' !== msg.type ){ return; } let args = processInlinerolls(msg).split(/\s+/); switch(args.shift()){ case '!me': { const who=(getObj('player',('API'===msg.playerid ? lastPlayerId : msg.playerid))||{get:()=>'API'}).get('_displayname'); let content = args.join(' '); if(_.has(msg,'rolltemplate') && _.isString(msg.rolltemplate) && msg.rolltemplate.length){ content = content.replace(/\{\{/,'&{template:'+msg.rolltemplate+'} {{'); } sendChat(msg.who,`/w "${who}" ${content}`); } break; default: if(/\s!me\b/.test(msg.content)){ lastPlayerId = msg.playerid; } break; } }); });
as long as they work, this is an outstanding piece of work.  I'm assuming - because I didn't think of it b4 - that "!me" takes the place of the whisper command (/w) AND the self identifier, then lets you message whatever after, including template info, etc.?  I was looking for something that would only go in the self identifier area, but honestly just thought there would be no purpose NOT including the /w command - as it's kinda relative to the general point.  I can think of no other reason to self-ID than a whisper ... lol.
Package and publicize this once you figure out what bugs the inline roll hover.   I think this is just one more example of your great scriptwork Aaron!  TYVM!
I'm gonna go add it to the campaign now, and let you know how it works out.  Think I'll call it SelfID.js - sound good?
1532286052
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You could also do this sans API by putting their menu macros in their character sheets and putting /w @{character_name} instead of /w gm
wanted 1 macro, used globally.  Aaron's got a good run on this.  But yeah, if you're not Pro, I guess that's another route to go.  I just can't think of being a GM and not supporting the community via a very low cost sub.  :-)
Yeah - I have that setup to my PC Menu, Configuration Menu, Combat Menu, and Miscellaneous Menu so far Aaron, and it works great!  TY SO MUCH!!!
noticed something else, and maybe this is true with all scripts, but the recursive tables "!rt" does not work with "!me" afterward.  nothing outputs to the chat window when you do that.  This being the example: !rt !me &{template:5e-shaped} {{title=Madness Determination}} {{Method=Chosen Madness Duration: **?{Which Duration?|Short Term|Long Term|Indefinite}**}}{{Short Term Madness=[[1t[Mad1]]] lasting [[1d10]] minutes}}{{Long Term Madness = [[1t[Mad2]]] lasting [[(1d10)*(1d10)]] hours}}{{Indefinite Madness = Character develops this flaw: [[1t[Mad3]]], until cured.}}{{Curing Madness= - *Calm Emotions* spell supresses, but doesn't rid madness - *Lesser Restoration* (or *remove curse*, or *dispel evil*, depending on the madness form) spell can rid a PC from short or long term madness. - *Greater Restoration* or more powerful magic is required to rid a PC of indefinite madness}} It gave me the roll query, so it ran, it just didn't output.  Had to change !me back to /w gm, but nbd.
1532298068

Edited 1532298574
also ... sadly, my players aren't able to see the things I labelled "!me", only i can, for whatever reason.  The point was to make sure the person who called the macro was the only one to see it.  Went on my test account and the same thing happened there too. In-so-far as I understand code, I think the issue (not that my novice level understands much) is this: if('api' !== msg.type || !playerIsGM(msg.playerid) Which seems to point that this only works for gms.  I wanted this to work for any who call the api, including players, so that when they call their menu and functions in their menu, it reduces chat cluttering.  granted, they could always have their default output set to self, but that shouldn't be needed, and doesn't always work. I just noticed this in the API output though: "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object." "Translation Error: the key [undefined] is not in the translation object."
1532299775
The Aaron
Pro
API Scripter
I have fixed both these issues in the script above. =D I accidentally had it restricted to the GM only, which defeats the purpose!  Additionally, I added a fix that should work for the RecursiveTable calls, though it's possible if several people are using it at the same exact moment, it might send the output to the wrong person.  
1532299836
The Aaron
Pro
API Scripter
I think those translation issues are from a character sheet, though I'm not sure.
Didn't start that till after the script, but I'll check after supper.  What's the code?
nvm - looks like u changed above
The Aaron said: I have fixed both these issues in the script above. =D I accidentally had it restricted to the GM only, which defeats the purpose!  Additionally, I added a fix that should work for the RecursiveTable calls, though it's possible if several people are using it at the same exact moment, it might send the output to the wrong person.   I'm the one that uses those tables, so it worked beautifully.  The players don't use them.  The only one I'd have any worry about is the one that rolls for a starting trinket, but, meh ... that's a random thing anyway.  as long as they get something random, whose die got rolled isn't as important as getting the result; unless 2 die get rolled and both output only one die of two/ mirroring the one die roll.  That would suck. Once again, a beautiful script.  Not sure if it has any deeply set bugs, but I think that package is set to go into your long repertoire.  TheAaron ... make it so!  :-) It is definitely a wonderful workaround to using "/talktomyself" toggle, as that stopped macros from working until turned off, so never really was useful for much.  This is a wonderful embed to global macros to be able to output them only to the player who called them and not clutter up regular or dm chat.  It's a godsend!   TY SOOOOOOOOOO MUCH Aaron!
1532370557

Edited 1532382525
The Aaron
Roll20 Production Team
API Scripter
(Moved to API forum.)
All of a sudden, since updating to version 19.1.3 (along with all Script requirements, etc.) of the 5e Shaped Sheet, having issues with this great script. It's just not doing anything to things initiated by "!me ", have had to convert back to "/w gm ".  :-(
1536407578
The Aaron
Pro
API Scripter
Hmmm. The version of the character sheet should have no effect. Are you getting any errors or weird log messages?
nothing - just not working when invoked.  The only thing I did recently (manually, idk what updated automatically recently) is the character sheet and all support files associated with it ... Had a new player come in and found out any of the menu items that started macros with !me didn't show up.  Its very very strange .... they all worked previously ....
Tonight is game night, so might have to wait till tomorrow or such to fix it, I'll just have to patch on the fly till then ...
1536426048
The Aaron
Pro
API Scripter
That is super weird.
Would it be simpler to just have the API call be synonymous with your own account name?   Thereby, instead of "!me    [message] " being the substitute for "/w Wolf Thunderspirit    [message]", in my case, it would just sub "Wolf Thunderspirit", forcing me to add "/w " before it as in "/w !me [message]"?  This would also be more  versatile  to use in other places where you might just want to show the name rather than use it to invoke message calling, though that was my main focus: message calling: /w !me [message] inline call: /em launches an attack!  !me grabs the spear with both hands and thrusts it to @{target|token_name} with deadly force! part of reference (probably not possible at this; but perhaps other references, non-api based, such as macros): !token-mod --set  represents|@{!me|character_id}
1536429773
The Aaron
Pro
API Scripter
Not really.
The Aaron said: Not really. ok - I'll get back to it on Sunday - see if I can narrow down the true cause of it, if I can.
Nevermind - I don't know how it broke, and I don't know how it fixed, but seems to be fixed.  We'll just let it at that ...
1536495726
The Aaron
Pro
API Scripter
Great... ish. =D