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 .
×
Our team is currently investigating rolling service outages. For more information, visit our most recent Forum Announcements post.
Create a free account

itsatrap API script

I am still learning and need to know if I have to have grids on to get this to work. I add it in, set up a trap token on GM layer with the web icon and BOOM nothing happens of a token moves over it not sure if I am missing something like token collision script or what it is.
1431100978
The Aaron
Pro
API Scripter
It requires: * Token Collisions: <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/Token%20Collisions" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/Token%20Collisions</a> * Vector Math: <a href="https://github.com/Roll20/roll20-api-scripts/tree/master/Vector%20Math" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/Vector%20Math</a> The grid shouldn't matter.
Ok well I have them all in with no errors and move a token over the "trap" and does nothing says nothing. Not sure if the trap token needs something else. I am using a token that looks like a trap with the web icon and no luck at all
1431111750
Lithl
Pro
Sheet Author
API Scripter
I haven't looked at the collision code, but it may be requiring exact coordinates, which would mean your chances of triggering it without the grid are slim. That said, it's just a guess without checking against the codebase. Have you tried it with the grid (making sure both trap and character are aligned to the grid)?
I thought the grid would make a difference and no luck so I am at a loss
I think that the player flag has to be on the page when you are testing. You can't just move the token over the trap without the flag being there. Probably saves resources.
Kunguru said: I think that the player flag has to be on the page when you are testing. You can't just move the token over the trap without the flag being there. Probably saves resources. so having DM tag with npc will not work it has to be player? I will try it then.
Vampiregoat69 said: Kunguru said: I think that the player flag has to be on the page when you are testing. You can't just move the token over the trap without the flag being there. Probably saves resources. so having DM tag with npc will not work it has to be player? I will try it then. I think he means that the map you are on has to be the "active" map - that is the map has to have the "Player" ribbon on it.
ok ty I will try it when we game
I got it to work had to put the poly line around it and bam
would be cool to add something such as damage so when it went off it rolled damage..lol
1435340320

Edited 1435340355
It's actually not too hard to include a damage roll in the output. I set my traps to have saving throw information in bar 1, and the damage roll in bar2. It's probably not the cleanest way to do it, but this is how I wrote it: if(trap) { sendChat("Merrshaulk", "Don't move! " + obj.get("name") + " has set off a trap!"); sendChat("Merrshaulk", obj.get("name") + ",please roll a DC" + trap.get("bar1_value") + " " + trap.get("bar1_max") + " saving throw"); sendChat("Merrshaulk", "If " + obj.get("name") + " failed his saving throw, he takes [[" + trap.get("bar2_value") + "]]" + " " + trap.get("bar2_max") + " damage!"); moveTokenToTrap(obj, trap);
1435371320
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Yes, traps only work on the map that has the "players" flag on it. The script should be grid-agnostic. All the math is done on the pixel measurements of the tokens and their distances.
I find that resaving the script in another tab periodically will fix the problem. It's a bit annoying but if it works then i don't mind too much.
1435383947

Edited 1435386382
I haven't looked at the code myself yet, but does it have commands to make the trap visible (say if the players rolled high on perception I just click on the trap and say !reveal-trap or something like that? -- and if they disarm it is there a command for disarming it?) Edit1: nevermind - says something about a reveal command at the bottom of this thread: <a href="https://app.roll20.net/forum/post/529899/script-interpolated-trap-detection#post-776572" rel="nofollow">https://app.roll20.net/forum/post/529899/script-interpolated-trap-detection#post-776572</a> -- hadn't actually checked out the main thread before. I'm always tired or sick when I'm on roll20, given that I don't have much time for it otherwise - but it makes me act somewhere between a bit slow and seriously stupid at times :( Edit2: Double-nevermind that's from a different script: <a href="https://app.roll20.net/forum/post/141032/script-re" rel="nofollow">https://app.roll20.net/forum/post/141032/script-re</a>... Edit3: I still can't get the trap thing to run! :(
At this point I've deactivated all other scripts to only test the trap thing. I now have The itsATrap.js, and VecMath.js and TokenCollision.js copied and activated. Also found a .json - I'm unclear on where I'm supposed to put it. I put it as a new scrip with .json ending, but it doesn't help. I have a token on the GM layer that is 2x2 big and has a cobweb as a symbol. I have tokens on the object layer that I can move to that grid point, but nothing happens.
The package.json file is just metadata, which will be used when they implement a "click to install" kind of interface for scripts. You don't need to copy it into your campaign (although it should be valid javascript, so having it there shouldn't hurt anything).
Could you have the text of a json in a js? or would it disturb something there?
1435442468

Edited 1437991873
Ziechael
Forum Champion
Sheet Author
API Scripter
Vampiregoat69 said: would be cool to add something such as damage so when it went off it rolled damage..lol This is my modded version of the script that will allow you to put information into the traps GM notes which will then be outputted to chat when triggered (including any inline rolls for damage etc): /** * A script that checks the interpolation of a token's movement to detect * whether they have passed through a square containing a trap. * * A trap can be any token on the GM layer for which the cobweb status is * active. Flying tokens (ones with the fluffy-wing status or angel-outfit * status active) will not set off traps unless the traps are also flying. * * This script works best for square traps equal or less than 2x2 squares or * circular traps of any size. * * Requires: * Token Collisions <a href="https://gist.github.com/Cazra/348653571dffc16e87b9" rel="nofollow">https://gist.github.com/Cazra/348653571dffc16e87b9</a> * Vector Math <a href="https://gist.github.com/Cazra/8d7fdd5f1975c7b28605" rel="nofollow">https://gist.github.com/Cazra/8d7fdd5f1975c7b28605</a> * */ var itsATrap = (function() { /** * Returns the first trap a token collided with during its last movement. * If it didn't collide with any traps, return false. * @param {Graphic} token * @return {Graphic || false} */ var getTrapCollision = function(token) { var traps = getTrapTokens(); traps = filterList(traps, function(trap) { return !isTokenFlying(token) || isTokenFlying(trap); }); return TokenCollisions.getFirstCollision(token, traps); }; /** * Determines whether a token is currently flying. * @param {Graphic} token * @return {Boolean} */ var isTokenFlying = function(token) { return (token.get("status_fluffy-wing") || token.get("status_angel-outfit")); }; /** * Moves the specified token to the same position as the trap. * @param {Graphic} token * @param {Graphic} trap */ var moveTokenToTrap = function(token, trap) { var x = trap.get("left"); var y = trap.get("top"); token.set("lastmove",""); token.set("left", x); token.set("top", y); }; /** * Returns all trap tokens on the players' page. */ var getTrapTokens = function() { var currentPageId = Campaign().get("playerpageid"); return findObjs({_pageid: currentPageId, _type: "graphic", status_cobweb: true, layer: "gmlayer"}); }; /** * Filters items out from a list using some filtering function. * Only items for which the filtering function returns true are kept in the * filtered list. * @param {Object[]} list * @param {Function} filterFunc Accepts an Object from list as a parameter. * Returns true to keep the item, or false to * discard. * @return {Object[]} */ var filterList = function(list, filterFunc) { var results = []; for(var i=0; i&lt;list.length; i++) { var item = list[i]; if(filterFunc(item)) { results.push(item); } } return results; } /** * When a graphic on the objects layer moves, run the script to see if it * passed through any traps. */ on("change:graphic", function(obj, prev) { // Objects on the GM layer don't set off traps. if(obj.get("layer") === "objects") { var trap = getTrapCollision(obj); if(trap) { var gmnotes = trap.get('gmnotes'); gmnotes = decodeURIComponent(gmnotes); sendChat("Admiral Ackbar", "IT'S A TRAP!!! " + obj.get("name") + " should have been more careful; " + gmnotes); moveTokenToTrap(obj, trap); if(trap.get("status_bleeding-eye")) { trap.set("layer","map"); toFront(trap); } } } }); })();
Sorry for rezzing an old thread, but this scripts has been giving me trouble. I have the requisite Vector, Collision, and Trap scripts up. I actually had the thing running well when I first set up the scripts, but for some reason when I revisited the campaign none of it will work any longer. I have respun the api more times than I can count and tried it on two different campaigns, and it currently works on neither. I have a similar issue as the OP, in that nothing happens when a token moves over a gm-layered trap with the cobweb and bleeding eye. The OP mentioned a poly line, which I attempted (drawing a line around the trap) and it did nothing. I would certainly appreciate some direction with this one.
make sure the Player ribbon is on the map where the trap is, Put token for trap on GM layer, place a poly box around trap, put the bleeding eye and cobweb on the trap icon. When they walk over the poly box it should trigger it. MIND you that I have had players trigger it, then move off when I was busy with another player before I could throw out the damage.
strange I notice it does not bring it to the object layer it erases the trap
I have that same problem Vampiregoat69. It flashes briefly and then disappears from view. It's actually behind my "map". The token of whatever the trap is, that is.
Nevermind, I figured it out. I had to change this section of the API script. if(trap.get("status_bleeding-eye")) { trap.set("layer","objects"); toBack(trap); I changed toBack to toFront and it worked like how I wanted it