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 to sort users by player?

1615411114
Senjak
Pro
Sheet Author
Has anyone written a script to either sort the characters owned by players into sub-directories named after the player or to just generate a list of the characters with their player names sorted by their player name?  Thanks, Senjak
1615411321
The Aaron
Roll20 Production Team
API Scripter
The latter can be done, I'm sure I have a script that does that as part of some other functionality.  The former can't, the API does not have write access to the directory structure of the journal.
1615411809
The Aaron
Roll20 Production Team
API Scripter
Ah, AddPlayerCharacter: It shows you the characters you have when you log in.&nbsp; You can hit the + to add another character.&nbsp; You can get the list again with this command: !show-player-character Code: on('ready',()=&gt;{ const IN_PLAYER_JOURNALS = true; const TIME_TO_CHECK = 5000; const styles = { box: 'display: block; border: 1px solid #999; border-radius: .3em; padding: .3em; background-color: white; box-shadow: 0 0 25px 2px #999; margin: 1em 0 1em 0;', charRow: 'display: block; border-top: 1px solid #ccc; margin: .2em;', img: 'max-width: 2em; max-height: 3em;width:auto;height:auto;border:1px solid #999;float:left;margin: .1em; display: inline-block;', link: 'color: #07c; border: 1px solid #999; border-radius: .3em; padding: .3em 1em; background-color:#ccc;font-weight: bold;display: inline-block;float: right;margin: .1em;', addBtn: 'color: #fff; border: 1px solid #9f9; border-radius: .3em; padding: .3em 1em; background-color:#3c3;font-weight: bold;display: inline-block;float: right;margin: .1em;' }; const defaultImg = '<a href="https://app.roll20.net/images/character.png" rel="nofollow">https://app.roll20.net/images/character.png</a>'; const clear = ()=&gt;`&lt;div style="clear:both"&gt;&lt;/div&gt;`; const GetCharImage = (c) =&gt; c.get('avatar')||defaultImg; const GetShowCharacter = (c) =&gt; `&lt;div style="${styles.charRow}"&gt;&lt;a style="${styles.link}" href="<a href="http://journal.roll20.net/character/${c.id}&quot;&gt;Open&lt;/a&gt;&lt;img" rel="nofollow">http://journal.roll20.net/character/${c.id}"&gt;Open&lt;/a&gt;&lt;img</a> style="${styles.img}" src="${GetCharImage(c)}"/&gt;${c.get('name')}${clear()}&lt;/div&gt;`; const AddButton = () =&gt; `&lt;a style="${styles.addBtn}" href="!add-player-character"&gt;+&lt;/a&gt;`; const AddPlayerCharacter = (player) =&gt; { let c = createObj('character',{ controlledby: player.id, name: `${player.get('displayname')}'s New Character`, inplayerjournals: (IN_PLAYER_JOURNALS ? 'all' : '') }); return c; }; const ShowPlayerCharacters = (player,chars)=&gt;{ chars = chars||findObjs({ type: 'character', archived: false }).filter(c=&gt;c.get('controlledby').split(/\s*,\s*/).includes(player.id)); sendChat('',`/w "${player.get('displayname')}" &lt;div style="${styles.box}"&gt;&lt;div&gt;${AddButton()}Your Characters:${clear()}&lt;/div&gt;${chars.map(GetShowCharacter).join('')}&lt;/div&gt;`); }; const CheckPlayerCharacters = (player) =&gt; { if(playerIsGM(player.id)){ return; } let chars = findObjs({ type: 'character', archived: false }).filter(c=&gt;c.get('controlledby').split(/\s*,\s*/).includes(player.id)); if( ! chars.length){ chars.push(AddPlayerCharacter(player)); } ShowPlayerCharacters(player,chars); }; on('chat:message', (msg) =&gt; { if('api' === msg.type &amp;&amp; /^!show-player-character(\b\s|$)/i.test(msg.content)){ let player = getObj('player',msg.playerid); if(player){ ShowPlayerCharacters(player); } } if('api' === msg.type &amp;&amp; /^!add-player-character(\b\s|$)/i.test(msg.content)){ let player = getObj('player',msg.playerid); if(player){ AddPlayerCharacter(player); ShowPlayerCharacters(player); } } }); const checkAll = () =&gt; { findObjs({ type: 'player' }).forEach(CheckPlayerCharacters); }; setTimeout(()=&gt;{ checkAll(); on('change:player:_online',(obj)=&gt;{ if(true === obj.get('online')){ setTimeout(()=&gt;CheckPlayerCharacters(obj),TIME_TO_CHECK); } }); }, TIME_TO_CHECK ); });
1615411855
The Aaron
Roll20 Production Team
API Scripter
That's probably not precisely what you're after, but I could pull the listing parts out and set it up to list off all players and their assigned characters, if that's something you're interested in.
1615412760
Senjak
Pro
Sheet Author
Both the script you passed on and the scrip you've kindly offered to make available would be fantastic.&nbsp; Please do that! Thanks! Senjak
1615434880
The Aaron
Roll20 Production Team
API Scripter
This turned out really well, so I made it a full fledged script:&nbsp;&nbsp; ListPlayerCharacters
1615451907
Senjak
Pro
Sheet Author
Cool! Thank you!