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

Trouble with Teleporting Script

As the title states me and a friend are trying to make the teleporting script posted at this link work:&nbsp; <a href="https://app.roll20.net/forum/post/193270/script-au" rel="nofollow">https://app.roll20.net/forum/post/193270/script-au</a>... However, we are not having any luck with it whatsoever. We are trying to test it by having some stairs that you would walk onto and it would teleport you to an appropriate location. These locations have been named Teleport2A and Teleport2B. We have not changed the script in any way because we are unsure as to what is wrong with it. The one we are using right now is the script without movement tracker shown at this link:&nbsp; <a href="https://gist.github.com/DarokinB/5806230" rel="nofollow">https://gist.github.com/DarokinB/5806230</a> . I would post this question within the page itself but it is so old of a topic it has closed the discussion. Any help we could get on this would be greatly appreciated.
Well, it works... <a href="https://app.roll20.net/forum/post/859086/trouble-w" rel="nofollow">https://app.roll20.net/forum/post/859086/trouble-w</a>... ... but also, it only works if the token is exactly 1 square big and is not turned at an odd angle. Question now is, how do we make it working with tokens that are either smaler or bigger then 1 square (5 ft) and also turned at an angle?
1464371821
The Aaron
Pro
API Scripter
Here's the version I use, modified to support better collision detection (and maybe some other things? can't remember precisely...). &nbsp; @Necrobane, the script only functions on the page the player ribbon is on (at least in the vanilla version), so if you were testing on a page the players weren't on, it wouldn't do anything. The Aaron's Modified version: /* ************ TELEPORTING SCRIPT &nbsp;************************** * &nbsp; The intention of this script is to allow the DM to teleport * &nbsp; one or all characters to a location based on a token placed&nbsp; * &nbsp; on the DM layer of the map.&nbsp; * &nbsp; &nbsp; To activate the script, type "!Teleport " and add the name * &nbsp; of the teleport location (must not contrain spaces) and then&nbsp; * &nbsp; the name of the party member to teleport there. They must be&nbsp; * &nbsp; seperated by commas. If you want all to teleport, type all.&nbsp; * &nbsp; ie. !Teleport teleport01, all - teleports all players to teleport01 * * &nbsp; AUTOTELEPORTING: This feature allows you to place a token on&nbsp; * &nbsp; One square (for example stairs) and it will auto move a token&nbsp; * &nbsp; to the linked location and back again should you choose. * &nbsp; Linked locations need to be tokens placed on the GMLayer. * &nbsp; Naming conventions: * &nbsp; Two way doors: &nbsp; XXXXXXXX2A, XXXXXXXXX2B * &nbsp; Three way dooes: XXXXXXXX3A, XXXXXXXXX3B, XXXXXXXXX3C * &nbsp; &nbsp; &nbsp; (in the case of one way doors, dont create a 3C) * &nbsp; This system can handle up to 9 way doors (9I max). ****************************************************************/ var Teleporter = Teleporter || {}; &nbsp; Teleporter.AUTOTELEPORTER = true; //Set to true if you want teleports to be linked Teleporter.Teleport = function (CharName, TargetName) { &nbsp; &nbsp; "use strict"; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var LocX = 0; &nbsp; &nbsp; var LocY = 0; &nbsp; &nbsp; &nbsp; //find the target location &nbsp; &nbsp; var location = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; _pageid: Campaign().get("playerpageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "graphic", &nbsp; &nbsp; &nbsp; &nbsp; layer: "gmlayer", //target location MUST be on GM layer &nbsp; &nbsp; &nbsp; &nbsp; name: TargetName &nbsp; &nbsp; }); &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if (location.length === 0) { &nbsp; &nbsp; &nbsp; &nbsp; return; //exit if invalid target location &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; LocX = location[0].get("left"); &nbsp; &nbsp; LocY = location[0].get("top"); &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; //if all are indicated, it lists all &nbsp; &nbsp; //finds all tokens with the name &nbsp; &nbsp; var targets = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; _pageid: Campaign().get("playerpageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "graphic" &nbsp; &nbsp; }); &nbsp; &nbsp; //Move characters to target location &nbsp; &nbsp; _.each(targets, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; //Only player tokens &nbsp; &nbsp; &nbsp; &nbsp; if (CharName === "all") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (obj.get("represents") !== "") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log("Setting all"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.set("left", LocX + 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.set("top", LocY); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (obj.get("name").indexOf(CharName) !== -1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (obj.get("represents") !== "") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.set("left", LocX + 1); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.set("top", LocY); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); }; &nbsp; on("chat:message", function(msg) { &nbsp;&nbsp; &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; var cmdName = "!Teleport "; &nbsp; &nbsp; &nbsp; if (msg.type === "api" && msg.content.indexOf(cmdName) !== -1 && playerIsGM(msg.playerid)) { &nbsp; &nbsp; &nbsp; &nbsp; var cleanedMsg = msg.content.replace(cmdName, ""); &nbsp; &nbsp; &nbsp; &nbsp; var commands = cleanedMsg.split(", "); &nbsp; &nbsp; &nbsp; &nbsp; var targetName = commands[0]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var i = 1; &nbsp; &nbsp; &nbsp; &nbsp; while ( i &lt; commands.length ) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Teleporter.Teleport(commands[i], targetName); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = i + 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } }); &nbsp; &nbsp;var findContains = function(obj,layer){ &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; var cx = obj.get('left'), &nbsp; &nbsp; &nbsp; &nbsp; cy = obj.get('top'); &nbsp; &nbsp; if(obj) { &nbsp; &nbsp; &nbsp; &nbsp; layer = layer || 'gmlayer'; &nbsp; &nbsp; &nbsp; &nbsp; return _.chain(findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _pageid: obj.get('pageid'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "graphic", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: layer&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .reduce(function(m,o){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var l=o.get('left'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t=o.get('top'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w=o.get('width'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h=o.get('height'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ol=l-(w/2), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; or=l+(w/2), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ot=t-(h/2), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ob=t+(h/2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( &nbsp; &nbsp;ol &lt;= cx && cx &lt;= or&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; && ot &lt;= cy && cy &lt;= ob&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m.push(o); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },[]) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .value(); &nbsp; &nbsp; } &nbsp; &nbsp; return []; &nbsp;};&nbsp; &nbsp; on("change:graphic", function(obj) { &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; if (obj.get("name").indexOf("Teleport") !== -1) { &nbsp; &nbsp; &nbsp; &nbsp; return; //Do not teleport teleport pads!! &nbsp; &nbsp; } &nbsp; &nbsp; if (Teleporter.AUTOTELEPORTER === false) { &nbsp; &nbsp; &nbsp; &nbsp; return; //Exit if auto Teleport is disabled &nbsp; &nbsp; } &nbsp; &nbsp; /* &nbsp;To use this system, you need to name two Teleportation locations the same &nbsp; &nbsp; * &nbsp; with only an A and B distinction. For instance Teleport01A and Teleport01B&nbsp; &nbsp; &nbsp; * &nbsp; will be linked together. When a token gets on one location, it will be &nbsp; &nbsp; * &nbsp; Teleported to the other automatically */ &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; //Finds the current teleportation location &nbsp; &nbsp; var CurrName = ""; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var location = findContains(obj,'gmlayer'); &nbsp; &nbsp; if (location.length === 0) { &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; } &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; CurrName = location[0].get("name"); &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var Letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"]; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; //Number of doors in the cycle (second to last character) &nbsp; &nbsp; var doorCount = CurrName.substr(CurrName.length - 2, 1); &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; //Current Letter of the Door &nbsp; &nbsp; var currDoor = CurrName.substr(CurrName.length - 1, 1); &nbsp; &nbsp; //Finds the pair location and moves target to that location &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var i = 0; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if( CurrName.match(/^R:/) ) { &nbsp; &nbsp; &nbsp; &nbsp; i = randomInteger(doorCount)-1; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; i = Letters.indexOf(currDoor); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (i === doorCount - 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = 0; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = i + 1; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var NewName = CurrName.substr(0,CurrName.length - 2) + doorCount + Letters[i]; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var NewX = 0; &nbsp; &nbsp; var NewY = 0; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; var newLocation = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; _pageid: Campaign().get("playerpageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "graphic", &nbsp; &nbsp; &nbsp; &nbsp; layer: "gmlayer", //target location MUST be on GM layer &nbsp; &nbsp; &nbsp; &nbsp; name: NewName &nbsp; &nbsp; }); &nbsp; &nbsp; _.each(newLocation, function(Loc){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the new Location &nbsp; &nbsp; &nbsp; &nbsp; NewX = Loc.get("left"); &nbsp; &nbsp; &nbsp; &nbsp; NewY = Loc.get("top"); &nbsp; &nbsp; }); &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if (NewX === 0 ) { &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; } &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; obj.set("left", NewX); &nbsp; &nbsp; obj.set("top", NewY); }); &nbsp; on("chat:message", function(msg) { &nbsp;&nbsp; &nbsp; &nbsp; "use strict"; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if (msg.content.indexOf("!AUTOTELEPORTER") !== -1 && playerIsGM(msg.playerid)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( Teleporter.AUTOTELEPORTER === true) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("System", "/w gm Autoteleporting Disabled."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Teleporter.AUTOTELEPORTER = false; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("System", "/w gm Autoteleporting Enabled."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Teleporter.AUTOTELEPORTER = true; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } });&nbsp;
1464384639
Ziechael
Forum Champion
Sheet Author
API Scripter
The Aaron said: Here's the version I use, modified to support better collision detection ( and maybe some other things? can't remember precisely...). &nbsp; Your version also allows for the teleport token names to be prefixed with 'R:' which assigns a random teleportation destination in a series of portals :)
1464413140
The Aaron
Pro
API Scripter
Ah right, so it does. Now who could have coerced me into doing that... &nbsp;=D