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] Two Sided Token (lycanthropes?)

1392183781
Konrad J.
Pro
API Scripter
Not sure if this already exists, I remember some talk about flippable tokens for characters that are lycanthropes. I was more interested in an easy way to do two side tokens for boardgames without going to rollable tables or decks. Decks would work great for a lot of games, but they can only have one graphic for a back. This is a very simple script and idea. It was written as a test to see how well it would work and if it might be useful for boardgames that need to flip a token. Could be used for tokens that have two different forms like a human/wererat. Very easy to use. The only requirement is you can't use the GMNotes for anything else. Eventually we could make it so you still could yuse the notes by incorporating some kind of header into the notes to tell the script where the paths are? GMNotes is where the path to the images are stored unless someone can think of a better place. You need to find the path to both graphics in your art library that you want to use by using your browser to inspect the graphic. You put both complete paths in the GMNotes separated by a space. If anyone needs help figuring out the paths just let me know, there is info on it in the Wiki API entries. Thats it. Then in the chat window you type !! 0 or !! 1. Of course this has potential to be upgraded a lot. You could have multiple sides, sides could have names instead of just a number, etc. If anyone thinks its useful I'll expand on it or if someone else wants to take the idea and run with it then of course you are welcome! Oh and there isn't any error checking and it works on the currently selected token. Of course we could add error checking and even have a popup to target which token you would like to flip. Possibilities are endless with this magical machine Riley has created!!! :) Well here it is, nice and simple. // Two Sided Tokens // // copyright pug games 2014 // please feel free to use this script, change it, add to it in any way you feel // Script created by Roll20 user Konrad J. var tstCONSTANTS = { TSTCOMMAND : "!!" }; function processTwoSidedToken(command, msg){ var token = getObj('graphic', msg.selected[0]._id); var tokenPathTemp1 = token.get("gmnotes"); var tokenPathTemp2 = toString(" "); var side = Number(command); tokenPathTemp2 = decodeURIComponent(tokenPathTemp1); var tokenPath = tokenPathTemp2.split(' '); token.set("imgsrc", tokenPath[side]); } on("chat:message", function(msg) { var chatCommand = msg.content; chatCommand = chatCommand.toLowerCase(); //make all characters lowercase if (msg.type != 'api') { return; } var argv = chatCommand.split(' '); switch(argv[0]) { case tstCONSTANTS.TSTCOMMAND: processTwoSidedToken(argv[1], msg); break; } });
1392195749

Edited 1392195799
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Use the rollable table. It has the URL information as part of the item and you can name each item. I kind of ignored it for a long time but for image management its the best way to go,
1392198835
Konrad J.
Pro
API Scripter
Ya, I was already playing with rollable tables, but then each user has to create a table. This way you could just distribute a script and the users would just need to figure out the paths to each graphic, which is probably more work than recreating a table each time. :) I was thinking of hardcoding the paths to variables in the script instead of using GMNotes. Then you can create a token just by entering a chat command. There are some advantages, but rollable tables are probably better. I'll keep on with this though and see what happens.
1392226481
Konrad J.
Pro
API Scripter
Stephen S. said: Use the rollable table. It has the URL information as part of the item and you can name each item. I kind of ignored it for a long time but for image management its the best way to go, I think it just hit me what you were hinting at. The user creates a rollable table which is easier than inspecting their art library. Then you can create a script that changes any graphic tokens imgsrc to one of the rollable table entries imgsrc. I was thinking it had to be a rollable table's graphic token, but it can be any token since you are simply using the rollable table as a holder for the proper paths to the artwork! Awesome! That would work much easier than what I was thinking! !! rtName rtItemName if there is a selected token then use that, if not then bring up the selection popup. Or even let the user supply a token name as a 3rd option. That would work very nicely indeed. Now to finish it! Thanks for the reply!
1392229481
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Yes. I am starting to really value the Rollable Tables for that reason alone. The avatar property uses the "med" file name so you have to find/replace that if you are using it as graphic. Something like UrlYouWant = YourObjectForTheItem.get("avatar").replace("med.jpg?","thumb.jpg?");
1392229908
Konrad J.
Pro
API Scripter
Thanks for the heads up, that probably would have been my next question! :) I can't wait to get started on the Polymorpher, I would have chosen the Transmogrifier, but that was taken. :(
Nice idea, Konrad. I find easier to use the gmnotes (in tokens, unfortunately the ones in the Journal are bugged), but it's just my preference. I use them in my scripts for a lot of stuff. A simple script like this would allow you log the imgsrc of any selected token: on('chat:message', function(msg) { if(msg.type == "api" && msg.content.indexOf("!logimg") !== -1) { var selected = msg.selected; _.each(selected, function(obj) { var oToken = getObj("graphic", obj._id); log(oToken.get("name") + ": " + oToken.get("imgsrc")); }); } }); Then you could use a custom tag in the gmnotes like this (using the "|" character as a separator): {poly}1|imgsrc1|imgsrc2{/poly} I normally use a function to parse those tags in a given token, and it spits out an array and a string of its contents. In this case you would have an array with a number at index 0 representing the image currently in use (1 or 2), while at index 1 and 2 there would be the 2 different image sources. You can still have any other kind of info in the gmnotes since you are using tags. I took the liberty of trying something slightly different: A script like this would allow you to "toggle" between two images any selected token(s) without having to specify which one to apply (some testing needed): on('chat:message', function(msg) { if(msg.type == "api" && msg.content.indexOf("!toggle") !== -1) { var selected = msg.selected; _.each(selected, function(obj) { var oToken = getObj("graphic", obj._id); var unwrapped = UnwrapString("poly", "|", oToken); var forms = unwrapped.uArray; var newimg = forms[1]; if(parseInt(forms[0]) === 1){ newimg = forms[2]; forms[0] = 2; } else{ forms[0] = 1; } oToken.set("imgsrc", newimg); var gmnotes = decodeURI(oToken.get("gmnotes")); gmnotes = cleanString(gmnotes); var currForm = "{poly}" + unwrapped.uString + "{/poly}"; var newForm = "{poly}" + forms[0] + "|" + forms[1] + "|" + forms[2] + "{/poly}"; var newgmnotes = gmnotes.replace(currForm, newForm); oToken.set("gmnotes", newgmnotes); }); } }); function cleanString(dirtystring){ dirtystring = dirtystring.replace(/%3A/g, ':'); dirtystring = dirtystring.replace(/%23/g, '#'); dirtystring = dirtystring.replace(/%3F/g, '?'); return dirtystring; } function UnwrapString(stringname, separator, obj){ var uArray = new Array(); var uString = ""; var gmnotes = decodeURI(obj.get('gmnotes')); gmnotes = cleanString(gmnotes); var startPos = gmnotes.indexOf("{" + stringname + "}"); if(startPos == -1) return { uString: "", uArray: uArray }; var endPos = gmnotes.indexOf("{/" + stringname + "}"); return { uString: gmnotes.substr(startPos+stringname.length+2, (endPos-startPos)-(stringname.length+2)), uArray: gmnotes.substr(startPos+stringname.length+2, (endPos-startPos)-(stringname.length+2)).split(separator) }; }
1392284159
Konrad J.
Pro
API Scripter
Thanks Fabio, some great info there. I'll have a closer look Thursday. But I did make my Polymorph script and its working great using Rollable Tables. Works well with them and easier for the regular user since they don't have to figure out what the path is, just create a rollable table full of images and away they go. Need more error checking, but you can state the name of the token to flip, use the selected token, or use the targeting popup to find the token the user wants. I've got a bunch of stuff I want to add to it, "enlarge person" (just an option to make the token larger or smaller as well), "Dimension Door" (option to move the token in a certain direction), "Summon", etc. Whatever fits with the theme of the script. But the main thing is the change of the graphic which works great right now. Nothing that earth shattering, but I like it.