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 help] Fallout Terminal - whisper terminal screen to activating player via JS mod

As the title says, I'm trying to adapt the script's code to show the terminal on the chat to the player who clicks the button ONLY. 
Now, I understand this is a stated limitation of the script itself but I can see that it works with "/w gm" just before the <table> opening at line 59; so the first question is: how can I find the player who activated the macro and pass his name to substitute the "gm" there via JS? one Idea was to use "selected" (for PC) and "target" (for the terminal) in the macro but still it would need a rework of the JS code.

secondary way: I tried using the command !me (from a script from the marvelous Aaron i dont remember the name of) just before the <table> on line 59, but had no luck. I was even trying to merge its very code in order to substitute its "who" costant but I think I made nothing but a horrible mess, I overestimated my JS skills I guess..


Can someone help me with this conundrum? we may even figure out a way to update fallout terminal for private screens, I'm sure that by combining the !me command with it we can do it! :-)


for reference, here is the !me script code

 

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;
        }
    });
});

 

April 15 (4 years ago)
David M.
Pro
API Scripter

Looks like the script above also handles being called by another script, but if that's not the case you can access the player that called the script with something along the the following:

let who = getObj('player',msg.playerid).get('_displayname');
April 18 (4 years ago)

Edited April 18 (4 years ago)

sadly that script doesnt handle being called by FalloutTerminal
Where should I put that line of code in FalloutTerminal? I'd need a little help with the correct position.

I understand I would then do something like this:

 var html = '/w ' + who + ' <table style="background-color:........


April 18 (4 years ago)
David M.
Pro
API Scripter

Not familiar with this script at all, but assuming you are working from v1.2 found in the one-click repo, you could try:

Adding this to line 17

var who;

Then adding the following as a separate line in four places: after each of the if statement lines found on lines 334, 337, 343, & 347. Being explicit here only within the if statements since doing it once before these statements would fire off that line for everything sent to chat.

who = getObj('player',msg.playerid).get('_displayname');

Then change line 74 to: 

sendChat('Fallout Terminal', `/w "${who}" ${html}`);

This is just air coding, so hopefully no syntax errors. Basically, the intention is to create a variable "who" that is scoped to the entire script (so it is available within both within the on('chat:message'...) and the _displayscreen function), and when the msg is received and meets the criteria, "who" is populated with the calling player name. The sendChat html is prepended with the whisper syntax within the _displayscreen function to actually do the whispering.

Note: all of the line numbers above refer to the version in the github repo. As soon as you add lines up top, they will obviously all shift down ;)