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] DealInit - Initiative Dealer for Savage Worlds Games

1439230030

Edited 1454253665
Pat
Pro
API Scripter
Deal-Init &nbsp;-&nbsp;Script to Deal Initiative for Savage Worlds Games Revisions: 0.7 &nbsp;- Fixed bug where Hold was being interpreted as a joker - thanks Maetco! 0.6 -&nbsp;now skipping tokens that are still On Hold a the end of the round, see details below - thanks GV! &nbsp; &nbsp; &nbsp; &nbsp; stopped setting init value of Round counters to -1. &nbsp;They remain at the bottom of the order - thanks GV! 0.5 - fancy card symbols - thanks Aaron! - Aug 15 0.4 - Initial Release - Aug 6 DealInit supports Savage Worlds style card based initiative by dealing cards to the Turn Order and sorting the order by suit. &nbsp;It does not, however, utilize the Roll20 deck system. Instead it manages an internal array of cards that are reshuffled when the deck runs out or a joker is drawn. &nbsp;It also checks character attributes for any SW Initiative Edges and handles them appropriately. The Initiative Edges must be stored in a comma separated list in an Attribute named "InitEdges" (e.g. Qui,LH) The Edge shorthand is as follows: (spelling and case count!) Qui = Quick LH = Level Headed ILH = Improved Level Headed WCE = Any Joker Activated Wild Card Edge (announced in turn order) Going on Hold is accomplished by the GM manually editing the affected token's card to be "H" or "h." As long as the card is an H/h, DealInit will not deal a card to that token and will put it at the top of the order on a new round. The GM must manually edit the card to an non-H/h value in order for DealInit to start dealing to that token again. The script only has a few options: &nbsp; &nbsp; !deal-init [ --help ] [--reset ] [ --show ] (no args) Deals cards to turn order and sorts by suit. --help Displays the help. --reset Reset the deck and shuffle. Use at the start of a new scene or encounter to start the deck fresh --show Show the current contents of the deck, discard pile, and turn order (hand). I personally use 2 macros to call the script that look like this: "New Scene" !deal-init --reset !deal-init "New Round" !deal-init GIT: &nbsp; <a href="https://github.com/pelwer1/Deal-Init" rel="nofollow">https://github.com/pelwer1/Deal-Init</a> Acknowledgements: Thanks to "the Aaron" for the javascript coaching and examples
1439587375

Edited 1439588999
The Aaron
Pro
API Scripter
Hey! &nbsp;Sorry so long before I commented.. GenCon, then sick as a dog and still catching up on the forum. // ask Aaron // o How to avoid getAttrByName log errors I've asked for this exactly. &nbsp;There isn't a way to avoid it if you're using getAttrByName(). &nbsp;You can avoid getAttrByName() if you know that your attribute in question is not an auto-calculated field on a character sheet. &nbsp;I believe in GroupInitiative, I findObj() the attributes, and if that fails I use getAttrByName(). I've only glanced at the code, but I can't wait to give this a try. &nbsp;Have you considered using the&nbsp; Underscore Shuffle function? &nbsp;Here's a code snippet example: var Deck = (function() { "use strict"; var deck = _.times(52,function(n){ return n+1;&nbsp; }), shuffle = function(n) { _.times( n || 1, function(){ deck= _.shuffle (deck); }); }, showDeck = function() { log(deck); }; return { Shuffle: shuffle, ShowDeck: showDeck }; }()); Deck.ShowDeck(); Deck.Shuffle(); Deck.ShowDeck(); Deck.Shuffle(5); Deck.ShowDeck(); Keep up the good work!!
I'm not sure if this is supposed to work but as I tested it the sandbox found an error: events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE at errnoException (net.js:904:11) at Server._listen2 (net.js:1023:19) at listen (net.js:1064:10) at Server.listen (net.js:1132:5) at Sandbox.start (/home/symbly/www/d20-api-server/sandcastle/lib/sandbox.js:35:15) at Object.&lt;anonymous&gt; (/home/symbly/www/d20-api-server/sandcastle/bin/sandcastle.js:11:9) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) There are no other API scripts in that campaign.
1439655418
Pat
Pro
API Scripter
Hi Maetco, I just tried the same experiment ( new campaign, only this script ) and I am not getting the error above. &nbsp;Looking at the message, it almost looks like the api sandbox failed to initialize when you saved the script. This is my first API script, so bear with me if I ask you to do some very basic stuff. &nbsp;Here's a few things to try: * when you pull the code from the github, make sure you poke the "raw" button and copy from the page that pops up * when you paste and save the api script, do you get this error? &nbsp; *&nbsp;Or is it failing when you try to run it? * can you get the help to work? &nbsp;( !deal-init --help ) Give me a little more detail on how you installed it and how you are running it and I may have better answers for you. I've been running this version for my last 2 sessions (~8 hours total) w/o problems, but I may have some bad assumptions in there somewhere....&nbsp;
1439658628
The Aaron
Pro
API Scripter
That&nbsp;EADDRINUSE is a problem in the sandbox, not a script. &nbsp;I've been reporting it to the Devs. &nbsp;Save the script and see if you can get it to continue.
1439659659
The Aaron
Pro
API Scripter
This is pretty neat! &nbsp;If you want to use the symbols for the suits, you can do that by changing the Card initialization to this: &nbsp; &nbsp; this.cards[0] &nbsp;= new Card( 0,"2&"+"clubs;","2 of Clubs" ); &nbsp; &nbsp; this.cards[1] &nbsp;= new Card( 1,"2&"+"diams;","2 of Diamonds" ); &nbsp; &nbsp; this.cards[2] &nbsp;= new Card( 2,"2&"+"hearts;","2 of Hearts" ); &nbsp; &nbsp; this.cards[3] &nbsp;= new Card( 3,"2&"+"spades;","2 of Spades" ); &nbsp; &nbsp; this.cards[4] &nbsp;= new Card( 4,"3&"+"clubs;","3 of Clubs" ); &nbsp; &nbsp; this.cards[5] &nbsp;= new Card( 5,"3&"+"diams;","3 of Diamonds" ); &nbsp; &nbsp; this.cards[6] &nbsp;= new Card( 6,"3&"+"hearts;","3 of Hearts" ); &nbsp; &nbsp; this.cards[7] &nbsp;= new Card( 7,"3&"+"spades;","3 of Spades" ); &nbsp; &nbsp; this.cards[8] &nbsp;= new Card( 8,"4&"+"clubs;","4 of Clubs" ); &nbsp; &nbsp; this.cards[9] &nbsp;= new Card( 9,"4&"+"diams;","4 of Diamonds" ); &nbsp; &nbsp; this.cards[10] = new Card(10,"4&"+"hearts;","4 of Hearts" ); &nbsp; &nbsp; this.cards[11] = new Card(11,"4&"+"spades;","4 of Spades" ); &nbsp; &nbsp; this.cards[12] = new Card(12,"5&"+"clubs;","5 of Clubs" ); &nbsp; &nbsp; this.cards[13] = new Card(13,"5&"+"diams;","5 of Diamonds" ); &nbsp; &nbsp; this.cards[14] = new Card(14,"5&"+"hearts;","5 of Hearts" ); &nbsp; &nbsp; this.cards[15] = new Card(15,"5&"+"spades;","5 of Spades" ); &nbsp; &nbsp; this.cards[16] = new Card(16,"6&"+"clubs;","6 of Clubs" ); &nbsp; &nbsp; this.cards[17] = new Card(17,"6&"+"diams;","6 of Diamonds" ); &nbsp; &nbsp; this.cards[18] = new Card(18,"6&"+"hearts;","6 of Hearts" ); &nbsp; &nbsp; this.cards[19] = new Card(19,"6&"+"spades;","6 of Spades" ); &nbsp; &nbsp; this.cards[20] = new Card(20,"7&"+"clubs;","7 of Clubs" ); &nbsp; &nbsp; this.cards[21] = new Card(21,"7&"+"diams;","7 of Diamonds" ); &nbsp; &nbsp; this.cards[22] = new Card(22,"7&"+"hearts;","7 of Hearts" ); &nbsp; &nbsp; this.cards[23] = new Card(23,"7&"+"spades;","7 of Spades" ); &nbsp; &nbsp; this.cards[24] = new Card(24,"8&"+"clubs;","8 of Clubs" ); &nbsp; &nbsp; this.cards[25] = new Card(25,"8&"+"diams;","8 of Diamonds" ); &nbsp; &nbsp; this.cards[26] = new Card(26,"8&"+"hearts;","8 of Hearts" ); &nbsp; &nbsp; this.cards[27] = new Card(27,"8&"+"spades;","8 of Spades" ); &nbsp; &nbsp; this.cards[28] = new Card(28,"9&"+"clubs;","9 of Clubs" ); &nbsp; &nbsp; this.cards[29] = new Card(29,"9&"+"diams;","9 of Diamonds" ); &nbsp; &nbsp; this.cards[30] = new Card(30,"9&"+"hearts;","9 of Hearts" ); &nbsp; &nbsp; this.cards[31] = new Card(31,"9&"+"spades;","9 of Spades" ); &nbsp; &nbsp; this.cards[32] = new Card(32,"10&"+"clubs;","10 of Clubs" ); &nbsp; &nbsp; this.cards[33] = new Card(33,"10&"+"diams;","10 of Diamonds" ); &nbsp; &nbsp; this.cards[34] = new Card(34,"10&"+"hearts;","10 of Hearts" ); &nbsp; &nbsp; this.cards[35] = new Card(35,"10&"+"spades;","10 of Spades" ); &nbsp; &nbsp; this.cards[36] = new Card(36,"J&"+"clubs;","Jack of Clubs" ); &nbsp; &nbsp; this.cards[37] = new Card(37,"J&"+"diams;","Jack of Diamonds" ); &nbsp; &nbsp; this.cards[38] = new Card(38,"J&"+"hearts;","Jack of Hearts" ); &nbsp; &nbsp; this.cards[39] = new Card(39,"J&"+"spades;","Jack of Spades" ); &nbsp; &nbsp; this.cards[40] = new Card(40,"Q&"+"clubs;","Queen of Clubs" ); &nbsp; &nbsp; this.cards[41] = new Card(41,"Q&"+"diams;","Queen of Diamonds" ); &nbsp; &nbsp; this.cards[42] = new Card(42,"Q&"+"hearts;","Queen of Hearts" ); &nbsp; &nbsp; this.cards[43] = new Card(43,"Q&"+"spades;","Queen of Spades" ); &nbsp; &nbsp; this.cards[44] = new Card(44,"K&"+"clubs;","King of Clubs" ); &nbsp; &nbsp; this.cards[45] = new Card(45,"K&"+"diams;","King of Diamonds" ); &nbsp; &nbsp; this.cards[46] = new Card(46,"K&"+"hearts;","King of Hearts" ); &nbsp; &nbsp; this.cards[47] = new Card(47,"K&"+"spades;","King of Spades" ); &nbsp; &nbsp; this.cards[48] = new Card(48,"A&"+"clubs;","Ace of Clubs" ); &nbsp; &nbsp; this.cards[49] = new Card(49,"A&"+"diams;","Ace of Diamonds" ); &nbsp; &nbsp; this.cards[50] = new Card(50,"A&"+"hearts;","Ace of Hearts" ); &nbsp; &nbsp; this.cards[51] = new Card(51,"A&"+"spades;","Ace of Spades" ); &nbsp; &nbsp; this.cards[52] = new Card(52,"BJo","Black Joker" ); &nbsp; &nbsp; this.cards[53] = new Card(53,"RJo","Red Joker" ); The &amp;clubs; and the like will get expanded into the symbol by the browser. &nbsp;Writing them in the code as "&amp;"+"clubs;" &nbsp;prevents accidental substitution by the browser when you copy and paste the code into the API edit window.
1439660701
The Aaron
Pro
API Scripter
Very neat, I enjoyed playing around with it. &nbsp;=D
The Aaron said: That&nbsp;EADDRINUSE is a problem in the sandbox, not a script. &nbsp;I've been reporting it to the Devs. &nbsp;Save the script and see if you can get it to continue. Thanks a lot Aaron! This (saving again without changing anything) was the fix. And thank you Pat for this awesome script. I will definitely be using it on my Savage Worlds campaigns.
1440861146
Pat
Pro
API Scripter
Very cool Maetco - glad you found it useful.
1445601802
Finderski
Pro
Sheet Author
Compendium Curator
I've not messed around with this yet, but will shortly; just wondering if this script supports characters going On Hold? If so, is that documented in the Help?&nbsp;
1445660107
Pat
Pro
API Scripter
GV, The script doesn't play any role in the actual execution of the round itself. &nbsp;It just deals the cards for the round taking into account the initiative edges of the characters in the Turn Order when the cards are dealt. Hope that helps. &nbsp;
1445676641

Edited 1445679009
Finderski
Pro
Sheet Author
Compendium Curator
It does, but the reason I asked, is because if a person goes on hold they aren't dealt a card the next round. For this, would I just need to remove the person from the Turn Order and put them back in after cards are dealt? EDIT: I've also been messing around with this (pretty sweet, btw), and noticed that if I use a Round counter, it always sets the Round to -1.
1445697991
Pat
Pro
API Scripter
GV, Good point on the Hold carrying over into the next round. &nbsp;The script doesn't handle this. &nbsp; You you are also right about the Round Counter getting set to -1. 2 bugs in 1 day - nice work! :) To fix the Hold problem, I'm thinking the process would be to have the GM put an "H" in the init value and the dealer script would carry that over to the next round. &nbsp;The "H's" would start the next round at the top of the order in the final sort. To fix the round counter, I'll have to stop messing with the values and change the sort algo to push them to the bottom of the list each round. &nbsp; Do you think those solutions would work? &nbsp;Can you think of any corner cases where they wouldn't? Thanks for the feedback. Pat.
1445699719
Finderski
Pro
Sheet Author
Compendium Curator
Pat said: To fix the Hold problem, I'm thinking the process would be to have the GM put an "H" in the init value and the dealer script would carry that over to the next round. &nbsp;The "H's" would start the next round at the top of the order in the final sort. That's about what I was thinking as well. :) To fix the round counter, I'll have to stop messing with the values and change the sort algo to push them to the bottom of the list each round. &nbsp; And that sounds about right as well. Thanks for taking a look at this—I'm really excited about this script (I was going to try my hand it, but just don't have time at the moment and then noticed you'd already done it. :) Thanks for putting this together!
1445724240
Pat
Pro
API Scripter
Ok GV - new version up on github 0.6 - now skipping tokens that are still On Hold a the end of the round &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stopped setting init value of Round counters to -1. They remain at the bottom of the order Give it a go and let me know if you have any problems. Thanks for the help and suggestions, Pat.
1445768910
Finderski
Pro
Sheet Author
Compendium Curator
Worked like a charm! Thanks again, this is very cool and should make things a lot easier. :)
Thanks a lot Pat for the update. Both improvements are really useful.