It's A Trap! (old thread)
Follow this link to the new support thread: https://app.roll20.net/forum/post/6927186/script-its-a-trap-thread-2/?pageforid=6927192#post-6927192
Follow this link to the new support thread: https://app.roll20.net/forum/post/6927186/script-its-a-trap-thread-2/?pageforid=6927192#post-6927192
var PlaySound = function(trackname, time) { var track = findObjs({type: 'jukeboxtrack', title: trackname})[0]; track.set('playing',false); track.set('softstop',false); if(track) { track.set('playing',true); } else { log("No track found"); } };
Ziechael said:
Oh boy oh boy oh boy, I've been using a 'hacked' version for months which allowed inline rolls in GM notes for custom trap outputs (thanks The Aaron!) but to have it officially supported is immense... and now for my full list of ideal additions ;)
- have it so that the bars can be used to set some trap values (maybe DC, save type and jukebox sound to play?) For example bar1value of 15, bar 2 value of Reflex and bar3value of springloaded would tell the script to output as part of the text [[bar2value]] Save DC [[bar1value]] and trigger the jukebox to play the sound called 'springloaded' :)
- Some way in which 'passive' searching could be enabled to detect traps, maybe even with a way to have active searching increase that chance of success (maybe auras and collision, although that would raise the issue of it passing through walls unless you could find a way to restrict that via your coding magic??)
Awesome, I love how this is growing! Would love to see support for 3.5e DnD for those of us who love pointlessly complex mathematics and contradictory/vague rules :)
Christopher (Obi) said:
Would it be possible to get the JSON script examples for the trap's settings? I have the 5eOGL going, but I cannot seem to get it to say anything other than "Invalid blah blah blah" when I put the JSON code in for the additional effects.
Stephen L. said:
Christopher (Obi) said:
Would it be possible to get the JSON script examples for the trap's settings? I have the 5eOGL going, but I cannot seem to get it to say anything other than "Invalid blah blah blah" when I put the JSON code in for the additional effects.
Done. The OP has been edited to include a couple examples.
Stephen L. said:
I've been testing with characters that have anywhere from 1-3 words in their names with no problem. Have you made sure that ItsATrap is the cause of it by disabling all other scripts except ItsATrap and its dependencies?
Stephen L. said:
Ok, I might have an idea of where it might be goofing up in the 5E-OGL theme. I'll see about getting that patched up soon.
I must have made a mistake while making the theme for the sheet.Xiavn said:
Hi there, I've just installed this script and have manually added the 5th Edition Shaped script to run alongside. Added in the theme to the script all right, and tested it using the two examples you give in the documentation, and it seems to work great except for one thing - any characters that have armour on, it adds 10 to their AC. If the character has no armour in-putted on their sheet at all it calculates correctly.
Any ideas on what I could be doing wrong?
Edit: I also seem to be getting errors in the log stating "ERROR: You tried to use the repeating section row at index 28 for repeating_skill, but there doesn't seem to be a row at that index." The index number basically errors out for anything past 18. Although it doesn't seem to cause a problem in the actual running of the script.It does that when it trying to find the passive perception for a character. Because there is currently no way from the API to tell how many rows are in a repeating section, it tries to find the perception skill within the first 30 (just in case someone decides they REALLY need to have a bunch of additional homebrew skills) skills in the repeating skills list. When it goes beyond the actual number of items in the list, it starts displaying those error message, but it doesn't appear to actually throw an Error about it, so it's not like I can just catch it in a try-block. I'm still looking for a work-around on this.
Cool! I didn't even realize I had a technique for that. =D Happy to (passively) help!Stephen L. said:
Edit:
I discovered Aaron's technique for getting repeated section attributes using filterObjs and getAttrByName. So now I've refactored the theme so that it should have better performance and not have those index errors. That will hopefully be available to everyone (along with the armored AC fix) on the next merge day.
var char = /* got from somewhere */; var conditions = filterObjs( function(o){ return o.get('type') === 'attribute' && o.get('characterid') === char.id && /repeating_moves_[^_]+_condition/.test(o.get('name')) ; });
Stephen L. said:
I actually haven't put these changes in my master branch yet, but proficient passive perception is working fine for me in my coding sandbox with the new fixes. If you'd like to try out the fixes early, here's the branch for it here: https://github.com/Cazra/roll20-api-scripts/tree/TrapThemeFXUpdates/ItsATrap_theme_5E_Shaped
var skills = filterObjs(function(o) { return o.get('type') === 'attribute' && o.get('characterid') === character.get('_id') && /repeating_skill_-?([a-zA-Z]|\d)+_name/.test(o.get('name')); });
/repeating_skill_-?([a-zA-Z]|\d)+_name/
/repeating_skill_(-|\$)([a-zA-Z]|\d)+_name/
Stephen L. said:
If that character has been around for a while, it's possible that their skills are still using row indexes instead of row IDs. Try replacing/repeating_skill_-?([a-zA-Z]|\d)+_name/
with/repeating_skill_(-|\$)([a-zA-Z]|\d)+_name/
/repeating_skill_(-|\$)([a-zA-Z-]|\d)+_name/
/repeating_skill_(\$\d+|-[a-zA-Z0-9\-]+)_name/The function that generates row ids can generate a dash inside the id.
var generateUUID = (function() { "use strict"; var a = 0, b = []; return function() { var c = (new Date()).getTime() + 0, d = c === a; a = c; for (var e = new Array(8), f = 7; 0 <= f; f--) { e[f] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(c % 64); c = Math.floor(c / 64); } c = e.join(""); if (d) { for (f = 11; 0 <= f && 63 === b[f]; f--) { b[f] = 0; } b[f]++; } else { for (f = 0; 12 > f; f++) { b[f] = Math.floor(64 * Math.random()); } } for (f = 0; 12 > f; f++){ c += "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".charAt(b[f]); } return c; }; }()), generateRowID = function () { "use strict"; return generateUUID().replace(/_/g, "Z"); };It's basically base64 encoding a block of data which is highly unlikely to be repeated in order to generate a unique ID. _ is a valid character in that id, so technically, a character ID of -______________ would be completely valid (all IDs from this function begin with a - because of what I can only assume is an off by one error). In the case of RowIDs, the _ is necessarily replaced by another character (Z) as _ is something of a delimiter in attribute names. (Subbing in a Z increases the likelihood of a collision (1.5625% overlap in keyspace), though not by nearly as much as lowercasing the whole thing (40.625% overlap in keyspace).)
repeating_skill_(-([0-9a-zA-Z\-_](?!_storage))+?|\$\d+?)_name
Hi Stephen,Stephen L. said:
Update:
Token Collisions 1.3 is now unofficially available, with support for rectangular collisions (including rotated rectangles).
This will allow collisions with rectangular traps.
It's not merged yet, but if you guys want to play with it, you can replace whichever version of Token Collisions you have with the one on my 1.3 branch here: https://github.com/Cazra/roll20-api-scripts/tree/T...
To set a trap as rectangular using Token Collisions 1.3, just set the trap's Aura1 to be a square.
TypeError: other.get is not a function TypeError: other.get is not a function at apiscript.js:175:24 at /home/node/d20-api-server/node_modules/underscore/underscore.js:380:19 at Function._.map._.collect (/home/node/d20-api-server/node_modules/underscore/underscore.js:172:24) at Function._.sortBy (/home/node/d20-api-server/node_modules/underscore/underscore.js:376:22) at _.(anonymous function) [as sortBy] (/home/node/d20-api-server/node_modules/underscore/underscore.js:1496:34) at _getCollisionsInWaypoint (apiscript.js:167:11) at apiscript.js:141:20 at Function._.map._.collect (/home/node/d20-api-server/node_modules/underscore/underscore.js:172:24) at _.(anonymous function) [as map] (/home/node/d20-api-server/node_modules/underscore/underscore.js:1496:34) at Object.getCollisions (apiscript.js:140:12)I think it's from this codes segment (lines 55-87):
function _getCollisionsInWaypoint(token, others, waypoint) { var startPt = waypoint[0]; var endPt = waypoint[1]; var numCollisions = 0; return _.chain(others) // Get the list of tokens that actually collide, sorted by the distance // from the starting point at which they occur. .sortBy(function(other) { var dist; if(token.get('aura1_square')) if(other.get('aura1_square')) dist = _testRectsCollision(token, other, waypoint); else dist = _testRectCircleCollision(token, other, waypoint); else if(other.get('aura1_square')) dist = _testCircleRectCollision(token, other, waypoint); else dist = _testCirclesCollision(token, other, waypoint); if(dist !== undefined) numCollisions++; return dist; }) // Other tokens with undefined collision distance will be sorted to the high // end of the list. So, we'll just drop them. .first(numCollisions) .value(); }But other than that I'm stymied. I'm trying to call Token Collisions with the following code:
getDestinationCollisions = function(token) { var pageId, destinations, collisions, lastCollision; pageId = token.get('_pageid'); destinations = getDestinations(pageId); collisions = TokenCollisions.getCollisions(token, destinations); lastCollision = _.last(collisions); }, getDestinations = function(pageId){ return findObjs({ pageid: pageId, type: 'graphic', layer: /*'map' ||*/ 'gmlayer', statusmarkers: 'aura' })[0]; },If I comment out the "collisions =" and "lastCollisions =" lines and log all the variables I get:
"pageId" "-Jo6Dd7nZqSelv3fMvdG" "token" {"_id":"-Jp2cpJ5LRb6rewwjAJg","_pageid":"-Jo6Dd7nZqSelv3fMvdG","left":3395,"top":1085,"width":70,"height":70,"rotation":0,"layer":"objects","isdrawing":false,"flipv":false,"fliph":false,"imgsrc":"https://s3.amazonaws.com/files.d20.io/images/7039467/f7qYLQ3M1plP_Fg1wFQkcg/thumb.png?1420690169","name":"","gmnotes":"","controlledby":"","bar1_value":"","bar1_max":"","bar1_link":"","bar2_value":"","bar2_max":"","bar2_link":"","bar3_value":"","bar3_max":"","bar3_link":"","represents":"","aura1_radius":"","aura1_color":"#FFFF99","aura1_square":false,"aura2_radius":"","aura2_color":"#59E594","aura2_square":false,"tint_color":"transparent","statusmarkers":"","showname":false,"showplayers_name":false,"showplayers_bar1":false,"showplayers_bar2":false,"showplayers_bar3":false,"showplayers_aura1":false,"showplayers_aura2":false,"playersedit_name":true,"playersedit_bar1":true,"playersedit_bar2":true,"playersedit_bar3":true,"playersedit_aura1":true,"playersedit_aura2":true,"light_radius":"","light_dimradius":"","light_otherplayers":false,"light_hassight":false,"light_angle":"","light_losangle":"","light_multiplier":1,"sides":"","currentSide":0,"lastmove":"3395,1155","_type":"graphic","_subtype":"token","_cardid":""} "destinations" {"_id":"-KHXcUKIYyHbJGZIf8do","_pageid":"-Jo6Dd7nZqSelv3fMvdG","left":3395,"top":1050,"width":210,"height":140,"rotation":0,"layer":"gmlayer","isdrawing":false,"flipv":false,"fliph":false,"imgsrc":"https://s3.amazonaws.com/files.d20.io/images/17909715/MSbM_vNTea-EnPc74F_DFA/thumb.png?1459987051","name":"Scrapwall","gmnotes":"","controlledby":"","bar1_value":"","bar1_max":"","bar1_link":"","bar2_value":"","bar2_max":"","bar2_link":"","bar3_value":"","bar3_max":"","bar3_link":"","represents":"","aura1_radius":"","aura1_color":"#FFFF99","aura1_square":true,"aura2_radius":"","aura2_color":"#59E594","aura2_square":false,"tint_color":"transparent","statusmarkers":"aura","showname":false,"showplayers_name":false,"showplayers_bar1":false,"showplayers_bar2":false,"showplayers_bar3":false,"showplayers_aura1":false,"showplayers_aura2":false,"playersedit_name":true,"playersedit_bar1":true,"playersedit_bar2":true,"playersedit_bar3":true,"playersedit_aura1":true,"playersedit_aura2":true,"light_radius":"","light_dimradius":"","light_otherplayers":false,"light_hassight":false,"light_angle":"","light_losangle":"","light_multiplier":1,"sides":"","currentSide":0,"lastmove":"3325,1085","_type":"graphic","_subtype":"token","_cardid":""}So I'm reasonably sure I'm passing valid objects to TokenCollisions. Any ideas?