Created
January 14, 2014 21:29
-
-
Save DarokinB/8426111 to your computer and use it in GitHub Desktop.
[Roll20 API] Last move culcanater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var LastMoved = LastMoved || {}; | |
LastMoved.allowNonTurnMovement = false; //If players can move when it is not | |
// their turn, set to true | |
on("change:graphic", function(obj, prev) { | |
//checks to see if initiative page is up | |
if (Campaign().get("initiativepage") !== true) return; | |
//pulls the turn order | |
var turnorder = JSON.parse(Campaign().get("turnorder")); | |
if (turnorder == "") return; //exit if init is empty | |
//if the id of the token is not matched to the currently moved, it moves it back | |
if (turnorder[0].id !== obj.id && !LastMoved.allowNonTurnMovement) { | |
obj.set("left", prev["left"]); | |
obj.set("top", prev["top"]); | |
} | |
//if it is, it adds the previous location to the move list | |
obj.set("lastmove", prev["lastmove"] + ", " + obj.get("lastmove")) | |
}); | |
on("change:campaign:turnorder", function(turn) { | |
var currTokens = findObjs({ | |
_pageid: Campaign().get("playerpageid"), | |
_type: "graphic", | |
}); | |
//Resets each token's move history as soon as the | |
//initiative page moves to the next person | |
_.each(currTokens, function(obj) { | |
obj.set("lastmove", obj.get("left") + "," + obj.get("top")); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment