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

Change trap script from playerpageid to playerspecificpages

How do I change the "It's a Trap" script from the player's map page to a split party map page. I need to have multiple maps open by different playersand I need the trap script to work on all the map pages. Please help.
1448685989
The Aaron
Roll20 Production Team
API Scripter
(Moved to API)
1448686334
The Aaron
Pro
API Scripter
See if this completely untested modified version works for that case: /**  * 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.  */ 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( token.get('pageid'));       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(currentPageId) {       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<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" ) {         //  log('last move for ' + obj.get('name') + ':');         //  log(obj.get('lastmove'));           var trap = getTrapCollision(obj);           if(trap) {               var trapName = trap.get("name");               if(trapName) {                 sendChat("Admiral Ackbar", "IT'S A TRAP!!! " + obj.get("name") + " set off a trap: " + trapName + "!");               }               else {                 sendChat("Admiral Ackbar", "IT'S A TRAP!!! " + obj.get("name") + " set off a trap!");               }               moveTokenToTrap(obj, trap);               if(trap.get("status_bleeding-eye")) {                   trap.set("layer","objects");                   toBack(trap);               }           }       }   }); })();
Thank you very much The Aaron. It seems to work great. I have been working for months on this dungeon which I have somewhat automated using the It's a Trap script to make messages pop up in the comments. I am very happy that you fixed the script. Again . . . thank you thank you very much.
1448737520
The Aaron
Pro
API Scripter
No problem, I'm happy to help!  Happy Rolling!
What I really need is for the text I the comments to say, Dungeonmaster, the players name who triggered the trap, then the GM notes.
Here is the original script I was using. /** * 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("Dungeon Master", "" + gmnotes); moveTokenToTrap(obj, trap); if(trap.get("status_bleeding-eye")) { trap.set("layer","map"); toFront(trap); } } } }); })();
What i was using the script for was to trigger the text I had written in the gmnotes of the token on the gm page if I had the cobweb on it, then bring it to the map layer if it had the bleeding eye. I think I was using someone's variation of it's a trap and they had it set up with the gmnotes.
I think the other script I am using to make invisible barriers is working fine so it is just the trap script that had problems when the party split up. I don't really know a lot about Java. Roll20 is the first time I have ever had to use it. I did some of the tutorial and can see that it would take some time to learn how to use it. I am very thankful for your help. It would probably take me a long time to figure it out on my own. I tried to change the text but what I did, did not work. Hopefully this will be the only help that I need.
I might have gotten it. Let me see if it works. I will still need some help about how to put the player's name into the comments. How do I write that?
What I did won't work. I don't understand the differences between the scripts.
Where I am at, all I need to do is add the gm notes. I don't know how to do this yet.
OK, I think I got it to work now.
Here is the script I altered that works to give the gm notes in case it is useful for anyone. It seems to work fine. I don't know how to paste it so it looks right on the comments. This script will say, Dungeonmaster: Triggered by (the name of the player) then the gm notes on the token that was triggered. /** &nbsp;* A script that checks the interpolation of a token's movement to detect &nbsp;* whether they have passed through a square containing a trap. &nbsp;* &nbsp;* A trap can be any token on the GM layer for which the cobweb status is &nbsp;* active. Flying tokens (ones with the fluffy-wing status or angel-outfit &nbsp;* status active) will not set off traps unless the traps are also flying. &nbsp;* &nbsp;* This script works best for square traps equal or less than 2x2 squares or &nbsp;* circular traps of any size. &nbsp;*/ var ItsATrap = (function() { &nbsp; &nbsp; /** &nbsp; &nbsp; &nbsp;* Returns the first trap a token collided with during its last movement. &nbsp; &nbsp; &nbsp;* If it didn't collide with any traps, return false. &nbsp; &nbsp; &nbsp;* @param {Graphic} token &nbsp; &nbsp; &nbsp;* @return {Graphic || false} &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; var getTrapCollision = function(token) { &nbsp; &nbsp; &nbsp; &nbsp; var traps = getTrapTokens(token.get('pageid')); &nbsp; &nbsp; &nbsp; &nbsp; traps = filterList(traps, function(trap) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return !isTokenFlying(token) || isTokenFlying(trap); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; return TokenCollisions.getFirstCollision(token, traps); &nbsp; &nbsp; }; &nbsp; &nbsp; /** &nbsp; &nbsp; &nbsp;* Determines whether a token is currently flying. &nbsp; &nbsp; &nbsp;* @param {Graphic} token &nbsp; &nbsp; &nbsp;* @return {Boolean} &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; var isTokenFlying = function(token) { &nbsp; &nbsp; &nbsp; &nbsp; return (token.get("status_fluffy-wing") || &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; token.get("status_angel-outfit")); &nbsp; &nbsp; }; &nbsp; &nbsp; /** &nbsp; &nbsp; &nbsp;* Moves the specified token to the same position as the trap. &nbsp; &nbsp; &nbsp;* @param {Graphic} token &nbsp; &nbsp; &nbsp;* @param {Graphic} trap &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; var moveTokenToTrap = function(token, trap) { &nbsp; &nbsp; &nbsp; &nbsp; var x = trap.get("left"); &nbsp; &nbsp; &nbsp; &nbsp; var y = trap.get("top"); &nbsp; &nbsp; &nbsp; &nbsp; token.set("lastmove", ""); &nbsp; &nbsp; &nbsp; &nbsp; token.set("left", x); &nbsp; &nbsp; &nbsp; &nbsp; token.set("top", y); &nbsp; &nbsp; }; &nbsp; &nbsp; /** &nbsp; &nbsp; &nbsp;* Returns all trap tokens on the players' page. &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; var getTrapTokens = function(currentPageId) { &nbsp; &nbsp; &nbsp; &nbsp; return findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _pageid: currentPageId, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "graphic", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status_cobweb: true, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: "gmlayer" &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }; &nbsp; &nbsp; /** &nbsp; &nbsp; &nbsp;* Filters items out from a list using some filtering function. &nbsp; &nbsp; &nbsp;* Only items for which the filtering function returns true are kept in the &nbsp; &nbsp; &nbsp;* filtered list. &nbsp; &nbsp; &nbsp;* @param {Object[]} list &nbsp; &nbsp; &nbsp;* @param {Function} filterFunc &nbsp;Accepts an Object from list as a parameter. &nbsp; &nbsp; &nbsp;* &nbsp;Returns true to keep the item, or false to &nbsp; &nbsp; &nbsp;* &nbsp;discard. &nbsp; &nbsp; &nbsp;* @return {Object[]} &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; var filterList = function(list, filterFunc) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var results = []; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i &lt; list.length; i++) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var item = list[i]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (filterFunc(item)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; results.push(item); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return results; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; /** &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* When a graphic on the objects layer moves, run the script to see if it &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* passed through any traps. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/ &nbsp; &nbsp; on("change:graphic", function(obj, prev) { &nbsp; &nbsp; &nbsp; &nbsp; // Objects on the GM layer don't set off traps. &nbsp; &nbsp; &nbsp; &nbsp; if (obj.get("layer") === "objects") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;log('last move for ' + obj.get('name') + ':'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;log(obj.get('lastmove')); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var trap = getTrapCollision(obj); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (trap) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var gmnotes = trap.get("gmnotes"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gmnotes = decodeURIComponent(gmnotes); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (gmnotes) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Dungeonmaster", "triggered by " + obj.get("name") + ": " + gmnotes + ""); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Dungeonmaster", "triggered by " + obj.get("name") + ": " + gmnotes + ""); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moveTokenToTrap(obj, trap); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (trap.get("status_bleeding-eye")) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trap.set("layer", "objects"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toBack(trap); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); })();
1448893713
The Aaron
Roll20 Production Team
API Scripter
Glad you got it working and thanks for sharing it! You can adjust your formatting by selecting the text and choosing code &nbsp;from the paragraph dropdown at the top left of the editor. &nbsp;There are instructions on this wiki page: &nbsp;<a href="https://wiki.roll20.net/Forum_Posting" rel="nofollow">https://wiki.roll20.net/Forum_Posting</a>
1448903575

Edited 1448904086
DK Heinrich
Marketplace Creator
Sheet Author
for us simple-minded script abusers - I put a 'trap' token on the GM layer with the cobweb icon active, write a description in the GM notes section of the token. When a player moves their token 'over' the 'trap' the description will pop in chat... correct? edit: when I do the above it crashes the script with the following error - so I must be missing a step.&nbsp; /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ ReferenceError: TokenCollisions is not defined at getTrapCollision (evalmachine.&lt;anonymous&gt;:5288:16) at evalmachine.&lt;anonymous&gt;:5351:24 at eval (
yes. You need two other scripts, token collisions and vector math.
<a href="https://wiki.roll20.net/API:Script_Index" rel="nofollow">https://wiki.roll20.net/API:Script_Index</a>
1448976243
DK Heinrich
Marketplace Creator
Sheet Author
ahh, ok that makes sense. :) &nbsp;I have vector math already, i will add in the collisions and give it a whirl.&nbsp;