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

Teleporting Script

I was looking through posts and came upon this post <a href="https://app.roll20.net/forum/post/3432348/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/3432348/slug%7D</a> In it The Aaron posted his own teleporting script. I copied this script into my game and cannot get it to work. Does anyone have any ideas ? Aaron's Script: /* ************ TELEPORTING SCRIPT ************************** * The intention of this script is to allow the DM to teleport * one or all characters to a location based on a token placed * on the DM layer of the map. * To activate the script, type "!Teleport " and add the name * of the teleport location (must not contrain spaces) and then * the name of the party member to teleport there. They must be * seperated by commas. If you want all to teleport, type all. * ie. !Teleport teleport01, all - teleports all players to teleport01 * * AUTOTELEPORTING: This feature allows you to place a token on * One square (for example stairs) and it will auto move a token * to the linked location and back again should you choose. * Linked locations need to be tokens placed on the GMLayer. * Naming conventions: * Two way doors: XXXXXXXX2A, XXXXXXXXX2B * Three way dooes: XXXXXXXX3A, XXXXXXXXX3B, XXXXXXXXX3C * (in the case of one way doors, dont create a 3C) * This system can handle up to 9 way doors (9I max). ****************************************************************/ var Teleporter = Teleporter || {}; Teleporter.AUTOTELEPORTER = true; //Set to true if you want teleports to be linked Teleporter.Teleport = function (CharName, TargetName) { "use strict"; var LocX = 0; var LocY = 0; //find the target location var location = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", layer: "gmlayer", //target location MUST be on GM layer name: TargetName }); if (location.length === 0) { return; //exit if invalid target location } LocX = location[0].get("left"); LocY = location[0].get("top"); //if all are indicated, it lists all //finds all tokens with the name var targets = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic" }); //Move characters to target location _.each(targets, function(obj) { //Only player tokens if (CharName === "all") { if (obj.get("represents") !== "") { log("Setting all"); obj.set("left", LocX + 1); obj.set("top", LocY); } } else { if (obj.get("name").indexOf(CharName) !== -1) { if (obj.get("represents") !== "") { obj.set("left", LocX + 1); obj.set("top", LocY); } } } }); }; on("chat:message", function(msg) { "use strict"; var cmdName = "!Teleport "; if (msg.type === "api" && msg.content.indexOf(cmdName) !== -1 && playerIsGM(msg.playerid)) { var cleanedMsg = msg.content.replace(cmdName, ""); var commands = cleanedMsg.split(", "); var targetName = commands[0]; var i = 1; while ( i &lt; commands.length ) { Teleporter.Teleport(commands[i], targetName); i = i + 1; } } }); var findContains = function(obj,layer){ "use strict"; var cx = obj.get('left'), cy = obj.get('top'); if(obj) { layer = layer || 'gmlayer'; return _.chain(findObjs({ _pageid: obj.get('pageid'), _type: "graphic", layer: layer })) .reduce(function(m,o){ var l=o.get('left'), t=o.get('top'), w=o.get('width'), h=o.get('height'), ol=l-(w/2), or=l+(w/2), ot=t-(h/2), ob=t+(h/2); if( ol &lt;= cx && cx &lt;= or && ot &lt;= cy && cy &lt;= ob ){ m.push(o); } return m; },[]) .value(); } return []; }; on("change:graphic", function(obj) { "use strict"; if (obj.get("name").indexOf("Teleport") !== -1) { return; //Do not teleport teleport pads!! } if (Teleporter.AUTOTELEPORTER === false) { return; //Exit if auto Teleport is disabled } /* To use this system, you need to name two Teleportation locations the same * with only an A and B distinction. For instance Teleport01A and Teleport01B * will be linked together. When a token gets on one location, it will be * Teleported to the other automatically */ //Finds the current teleportation location var CurrName = ""; var location = findContains(obj,'gmlayer'); if (location.length === 0) { return; } CurrName = location[0].get("name"); var Letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]; //Number of doors in the cycle (second to last character) var doorCount = CurrName.substr(CurrName.length - 2, 1); //Current Letter of the Door var currDoor = CurrName.substr(CurrName.length - 1, 1); //Finds the pair location and moves target to that location var i = 0; if( CurrName.match(/^R:/) ) { i = randomInteger(doorCount)-1; } else { i = Letters.indexOf(currDoor); if (i === doorCount - 1) { i = 0; } else { i = i + 1; } } var NewName = CurrName.substr(0,CurrName.length - 2) + doorCount + Letters[i]; var NewX = 0; var NewY = 0; var newLocation = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", layer: "gmlayer", //target location MUST be on GM layer name: NewName }); _.each(newLocation, function(Loc){ //Get the new Location NewX = Loc.get("left"); NewY = Loc.get("top"); }); if (NewX === 0 ) { return; } obj.set("left", NewX); obj.set("top", NewY); }); on("chat:message", function(msg) { "use strict"; if (msg.content.indexOf("!AUTOTELEPORTER") !== -1 && playerIsGM(msg.playerid)) { if ( Teleporter.AUTOTELEPORTER === true) { sendChat("System", "/w gm Autoteleporting Disabled."); Teleporter.AUTOTELEPORTER = false; } else { sendChat("System", "/w gm Autoteleporting Enabled."); Teleporter.AUTOTELEPORTER = true; } } });
It works fine for me. How did you set it up and what errors are you getting?
Ravenknight said: It works fine for me. How did you set it up and what errors are you getting? Not getting any errors and its not working. I added it in like other scripts and setup two identical icons with 'Teleport01A' & 'Teleport01B' and they are both on the GM layer yet when I move a token to it nothing happens.
Try to name them&nbsp;XXXXXXXX2A, XXXXXXXXX2B and see what happens?
1481191461
Ziechael
Forum Champion
Sheet Author
API Scripter
Make sure you have the player ribbon the page you are testing it on, it uses that as a trigger for making the teleporters 'active'. Also try running !AUTOTELEPORTER to see if it is disabled?
Ravenknight said: Try to name them&nbsp;XXXXXXXX2A, XXXXXXXXX2B and see what happens? When I rename them the 2B one is teleported to the 2A one
Ziechael said: Make sure you have the player ribbon the page you are testing it on, it uses that as a trigger for making the teleporters 'active'. Also try running !AUTOTELEPORTER to see if it is disabled? The ribbon is on the correct page. Autoteleporting is enabled.
1481205103
Ziechael
Forum Champion
Sheet Author
API Scripter
The digit in the TELEPORT2A etc denotes the number of destinations in the chain. The letter gives the chain an order to follow. Aaron's tweak allows for random destinations. So 2A will teleport to 2B normally and then back again. If you want a one way teleporter you'll want to use 3A and 3B but don't add a 3C and the chain will effectively be broken and moving over 3B will not teleport you anywhere.
Xargun said: Ravenknight said: Try to name them&nbsp;XXXXXXXX2A, XXXXXXXXX2B and see what happens? When I rename them the 2B one is teleported to the 2A one Ah, I had the same problem. Place, name and set them up without the player ribbon being on the page before you try them out,.
Ravenknight said: Xargun said: Ravenknight said: Try to name them&nbsp;XXXXXXXX2A, XXXXXXXXX2B and see what happens? When I rename them the 2B one is teleported to the 2A one Ah, I had the same problem. Place, name and set them up without the player ribbon being on the page before you try them out,. That did it. Thanks a lot.
You're welcome. Happy rolling.
1481293281
Ziechael
Forum Champion
Sheet Author
API Scripter
Sorry, should have read more carefully first! An alternative is to run !AUTOTELEPORTER to disable, place, name etc then run !AUTOTELEPORTER again to enable it... or just move the ribbon yes lol.
Ziechael said: Sorry, should have read more carefully first! An alternative is to run !AUTOTELEPORTER to disable, place, name etc then run !AUTOTELEPORTER again to enable it... or just move the ribbon yes lol. I didn't even think of that. :P&nbsp;
1481862747
The Aaron
Pro
API Scripter
(Just for the record: this isn't really my script, I just made a few tweaks to it...)