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

Dealer API help

Good day! I need help with automating dealing cards to my players. I tried keithcurtis' script "dealer" found in this forum&nbsp; <a href="https://app.roll20.net/forum/post/7687278/script-dealer/?pageforid=7834013#post-7834013" rel="nofollow">https://app.roll20.net/forum/post/7687278/script-dealer/?pageforid=7834013#post-7834013</a> . The problem is I dont know how to edit the script to recognize roll results like [[{2, [[@{sampleattrib}-?{Modifier|0}]]}kh1]] as an integer to input in the deal command like this&nbsp; !deal --give [[{2, [[@{sampleattrib}-?{Modifier|0}]]}kh1]] --sampledeckname I tried searching how to recognize it and I found this function processInlinerolls (msg) { if (_. has (msg, 'inlinerolls' )) { return _. chain (msg.inlinerolls) . reduce ( function (previous, current, index) { previous[ '$[[' + index + ']]' ] = current.results.total | | 0 ; return previous; },{}) . reduce ( function (previous, current, index) { return previous. replace (index, current); }, msg.content) . value (); } else { return msg.content; } } But I don't know if it is the right script to add and where should i place it Also, since I am stuck with that problem, I haven't started figuring out how to edit the script to include specific targets to deal the cards aside from the selected token controller which is default for the script. any help or insight would be awesome Thank you
1587919792
The Aaron
Roll20 Production Team
API Scripter
Try this version: // Dealer // Last Updated: 2019-09-03 // A script to deal and take cards to selected users from specified decks. // Syntax is !deal --[give,take] [number of cards as integer] --[deck name]|[card name] on('ready', () =&gt; { const version = '1.1.0'; const processInlinerolls = (msg) =&gt; { 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 &amp;&amp; ti) || v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } else { return msg.content; } }; log('-=&gt; Dealer v' + version + ' &lt;=-'); on('chat:message', (msg) =&gt; { if ('api' === msg.type &amp;&amp; /!deal\b/i.test(msg.content) &amp;&amp; msg.selected) { //get parameter and use default of 'give' if parameter is missing or malformed const args = processInlinerolls(msg).split(/\s+--/); if (args.length &lt; 2) { if (args[0] !== '!deal') { sendChat('Deal', '/w gm Malformed command. Please use !deal --[give/take] --[Deckname].'); return; } else { args[1] = 'give'; } } let action = args[1].split(/\s+/)[0]; let numCards = args[1].split(/\s+/)[1]; numCards = Number((Number.isInteger(Number(numCards))) ? numCards : 1); const actions = ['give', 'take']; let cardAction = 'give'; if (action &amp;&amp; actions.includes(action)) { cardAction = action; } let choices = args[2] || 'Playing Cards'; let deckChoice = choices.split(/\|/)[0] || 'Playing Cards'; let cardChoice = choices.split(/\|/)[1] || ''; //getid of deck let theDeck = findObjs({ _type: "deck", name: deckChoice })[0]; //test if deck exists if (!theDeck) { sendChat('Deal', '/w gm Create a deck named ' + deckChoice + '. If the intent is an Inspiration deck, it must be an infinite deck of one card only.'); return; } let deckID = theDeck.id; let deckCards = theDeck.get('_currentDeck'); if (msg.selected.length &gt; 1) { sendChat('Deal', '/w gm Please select only one token. It must represent player-controlled character.'); return; } let token = getObj(msg.selected[0]._type, msg.selected[0]._id); //assign associated character to a variable if (!token.get('represents')) { sendChat('Deal', '/w gm This token does not represent a player character. Only players get cards.'); return; } let character = getObj("character", token.get('represents')); //Get owner IDs of each -- Not needed at this point // If the token represents a character, get the character's controller, otherwise the token's let ownerids = (token.get('controlledby').split(',')); if (character) { ownerids = (character.get('controlledby').split(',')); } //reduces to one ownerid that is not ['all'] ownerid = ownerids.filter(s =&gt; s !== 'all')[0]; // give card to player // If the ownerid is undefined (no valid controller) explain and exit if (!ownerid) { sendChat('deal', '/w gm If a token represents a character controlled by \'All Players\', an individual player must be also be specified. If there are multiple controllers, only the first will get inspiration.'); return; } //If a card is specified by name if (cardChoice !== '') { let theCard = findObjs({ _type: 'card', name: cardChoice, _deckid: deckID })[0]; if (theCard !== undefined) { do { let specificCardID = theCard.id; giveCardToPlayer(specificCardID, ownerid); numCards--; } while (numCards &gt; 0); return; } else { sendChat('deal', '/w gm There does not seem to be a card named ' + cardChoice + ' in the deck ' + deckChoice); return; } } //If this is a random card do { //get id of card let cardid = drawCard(deckID); if (!cardid) { shuffleDeck(deckID); cardid = drawCard(deckID); } // get playerId of Token controller //assign selected token to a variable switch (cardAction) { case 'take': let hand = findObjs({ type: 'hand', parentid: ownerid })[0]; let theHand = hand.get('currentHand'); cardid = (theHand.split(',').filter(x =&gt; deckCards.split(',').includes(x)))[0]; if (theHand.length !== 0 &amp;&amp; cardid !== undefined) { takeCardFromPlayer(ownerid, { cardid: cardid }); } else { let deckName = theDeck.get('name'); sendChat('deal', '/w gm ' + token.get('name') + ' has no cards left to take from the ' + deckName + ' deck.'); } break; default: giveCardToPlayer(cardid, ownerid); break; } numCards--; } while (numCards &gt; 0); } }); });
Thank you very much!&nbsp; You are a lifesaver! It is working now!. Is there an -- argument somewhere if I want to target a specific player or token. either way I am happy its working ill just work around it in macros for the targeting
1587932986
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
The script works on a selected token, which must be controlled by a player. You can't deal cards to tokens, only players. This is my first (and only really complete) script. I added the ability to specify particular cards, but always assumed there would be a controlled token available.
Thank you keith for making the script! Thank you also to aaron for making it recognize my inline commands.