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] Find token

Hello guys!&nbsp; I'm quite new here and I've been lurking some api from a whilr to improve my games. I tried to use the !find script from Kastion (link here:&nbsp;<a href="https://app.roll20.net/forum/post/6585464/script-find-token#newtopic" rel="nofollow">https://app.roll20.net/forum/post/6585464/script-find-token#newtopic</a>).&nbsp; It works very fine for me, but when I use the macro with players in game the api moves all players visual to the token.&nbsp; Nevertheless I tried to give the api command to player to find their own token in big map (we use lot of them) but the script seems very slow (takes a lot of time to activate) and doesn"t work always.&nbsp; There is a way to make an api to make each player able to find its own token?&nbsp; Thank you for help :)&nbsp; Rockshow&nbsp;
1580287661

Edited 1580321696
GiGs
Pro
Sheet Author
API Scripter
Here are two changes to try (I've never used this script, so I'm guesstimating). First, if('api' !== msg.type || !playerIsGM(msg.playerid)) { return; } to if('api' !== msg.type ) { return; } This will let players run the script. Then change this line sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true); to one of these (not sure which, try each): sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true, msg.playerid); sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, false, msg.playerid); sendPing(t.get("left"), t.get("top"), playerPageID, null, true, msg.playerid); That should stop moving everyone's view, and just the person who triggered it.&nbsp; Try all three if needed, one after another, and let us know how it goes.&nbsp; Optionally, you could also change this line const cmdName = "!find-token"; to&nbsp; const cmdName = "!find-token-pc"; so that its launched with a different command (!find-token-pc), so you can have both versions of the script installed.
THANKS :)&nbsp; I'll try it as soon as possible!&nbsp;
Tried this out myself cause it seems useful! This change isn't letting players run the script in my game. GiGs said: [...] if('api' !== msg.type || !playerIsGM(msg.playerid)) { return; } to if('api' !== msg.type ) { return; } In fact, when a player tries to use the command, the API crashes with this error Would something about this part if(playerIsGM(playerid)){ return player.get('lastpage'); need to be changed, since it seems to require the player to be GM? And the first of your suggestions here seems to work as intended; only pings on my screen, not my players'. GiGs said: [...] sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true); to one of these (not sure which, try each): sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true, msg.playerid); sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, false, msg.playerid); sendPing(t.get("left"), t.get("top"), playerPageID, null, true, msg.playerid);
1580346803

Edited 1580362908
GiGs
Pro
Sheet Author
API Scripter
Well spotted. There was an error in the original code. This line&nbsp; return Campaign.get('playerpageid'); should be return Campaign().get('playerpageid'); Here's a version of the script with all these little changes and a correction for the sendChat commands to so that players get messaged not the GM. Use !find-token --tokenname Edit: See next post for code
1580362425

Edited 1580370562
GiGs
Pro
Sheet Author
API Scripter
I just streamlined the script, so it now works for PCs and GMs with the same command, !find-token. If you're a GM , it will ping all players and focus their view on the token. You can add --true or --1 to the command, and it will limit the ping to the gm only. eg. --!find-token --Kastion --1 If you're a PC, and run this, it will ping only you, but only if you control the token. You cant use this to find NPCs. Here's the updated script on('ready', () =&gt; { const getPageForPlayer = (playerid) =&gt; { let player = getObj('player', playerid); if (playerIsGM(playerid)) { return player.get('lastpage'); } let psp = Campaign().get('playerspecificpages'); if (psp[playerid]) { return psp[playerid]; } return Campaign().get('playerpageid'); }; const getToken = (name, page, id, gm) =&gt; { const tokens = findObjs({ _pageid: page, _type: "graphic", _name: name }).filter((token) =&gt; { let controlledby = (getObj('character', token.get('represents')) || token).get('controlledby'); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return gm || controlledby.split(",").includes('all') || controlledby.split(",").includes(id); }); return tokens[0] || ''; }; on('chat:message', (msg) =&gt; { if ('api' === msg.type &amp;&amp; /^!find-token\b/i.test(msg.content)) { const gm = playerIsGM(msg.playerid); const pname = getObj('player', msg.playerid).get('_displayname'); const args = msg.content.split("--"); const token_name = (args[1] || '').trim(); const focus_gm = args[2] || ''; if (token_name) { const playerPageID = getPageForPlayer(msg.playerid); const t = getToken(token_name, playerPageID, msg.playerid, gm); if (t) { sendPing(t.get("left"), t.get("top"), playerPageID, msg.playerid, true, (gm &amp;&amp; !focus_gm ? null : msg.playerid)); } else { sendChat('FindToken', `/w ${pname} No tokens named &lt;code&gt;${token_name}&lt;/code&gt; and owned by you found on your current page.`); } } else { sendChat('FindToken', `/w ${pname} Please use the format &lt;code&gt;!find-token --token name&lt;/code&gt;.`); } } }); log("-=&gt; Find Token Loaded (!find-token) [Last Edited Jan 29th 2020] &lt;=-"); });
This is *awesome* thanks so much. I was looking for a way to get Kastion's findtoken to work for players just last week. *fingerkiss*
This is working wonderfully, GiGs, thank you!
1580366613
GiGs
Pro
Sheet Author
API Scripter
That's great :) I just noticed I left the wrong text in one of the sendchat lines, and have fixed it. It would inform pcs of the wrong command to use (find-pc-token instead of find-token), so you should update.
1580368884

Edited 1580369454
One of my players just tested it out, but she keeps getting this message: She's using this command exactly: !find-token --Sally Her token is named Sally, and it's linked to her sheet. Does it only work if the player's name is in the token's Controlled By, rather than being linked to a character controlled by them? EDIT: It was because her sheet's controlled by more than one player. Removed the extra controller for now. Don't suppose there's an easy fix for that?
1580370601
GiGs
Pro
Sheet Author
API Scripter
You're right - I hadnt properly tested for multiple controllers. I've updated the script, try it now.
That did it :) Thanks again!
1580412646
GiGs
Pro
Sheet Author
API Scripter
you're welcome :)
1580415293

Edited 1580415471
Don't know why, but doesn't work for me :( .. If I use it, it will ping all player to token, but if a player use it, nothings happen!
To use it without pinging all players, try formatting the command like this: !find-token --Token Name --1 Are your players getting an error message in their chat?
I have no error, it's working fine for me. My players have no error either, but when they use the macro it spam the macro name in chat with an # (ex. #macroname). That is not happening to me!
1580422031

Edited 1580424611
GiGs
Pro
Sheet Author
API Scripter
That suggests there's something wrong with the way the macro is set up. Is it a macro you've created? if so, edit the macro, scroll down to the Visible to Players option, and make sure that is correct. If that's not it, ask them just to copy the specific text and paste into chat without using a macro !find-token --Sally (or whatever the token name is) and see if it works.
1580425086

Edited 1580425497
Yeah i've set up the macro for my player. That how it is: If they click the button "Test macro" it works! If he type "!find-token --Reginald Pennington" it works too.. but if he use the macro button, the result is a chat line "#where-is-Reginald Pennington?" I can't really understand :\ EDIT I made them do their own macro and now it works! strange but ok! thank you :)
1580426362
GiGs
Pro
Sheet Author
API Scripter
You have a space in the name of the macro, which might the issue. Though why it works for you and not them is a mystery. Try changing it to&nbsp; #where-is-Reginald-Pennington? or #where-is-ReginaldPennington?
1582097224

Edited 1582097244
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Just found a really nice bonus use for this script. If you have a large dungeon that is described at length in a handout, put a token in each room and give it a name. Ex: "Room 3". On your handout, where the heading of the section says: "Room 3 - blahblahblah", make the words "Room 3" a link. In that link, put: `!find-token --Room 3 That backtic at the front is important, for inscrutable Roll20 reasons. Now this token could be an invisible Note token , or a room indicator on the GM layer (most modules already have these). The name does not have to display. Now, when you are going through the handout and running the adventure, clicking on the heading will immediately ping-pull the screen to the room being described. It doesn't matter if the token is visible, or what layer it is on. If you add " --1" to the end, of course, only the GM will be pulled.
1582103815
GiGs
Pro
Sheet Author
API Scripter
That's a very handy trick.
1582126004
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
If it weren't so specialized, I'd put it into Stupid Tricks.
1582126349
GiGs
Pro
Sheet Author
API Scripter
I thought of suggesting it for that too, but it does seem a bit specialised.
1582129555

Edited 1582129581
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hmm. I wonder if this can be leveraged into other scripts. If there is an "on page load" type of script that could run other macros, it could cause the view to automatically shift to a pre-determined starting point, rather than the GM pulling everyone to say, the lower right corner. There might be a timing issue depending on page load time, though.