Skip to content

Instantly share code, notes, and snippets.

@DarokinB
Created January 14, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarokinB/8426111 to your computer and use it in GitHub Desktop.
Save DarokinB/8426111 to your computer and use it in GitHub Desktop.
[Roll20 API] Last move culcanater
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