Created
February 15, 2016 11:55
-
-
Save lagonnebula/def632d18d4b1dadb202 to your computer and use it in GitHub Desktop.
Script de patrouille de token pour Roll20
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
| on("ready", function(){ | |
| /*ToModify*/ | |
| var list = [ | |
| {tokenName: "Guerrier 1", orderList: 0, character: null}, | |
| {tokenName: "Archer", orderList: 0, character: null}, | |
| ]; | |
| var pixelToMove = 70; // 70 ~ 1 case | |
| var turnDuration = 0.5; //In second | |
| var barLifeNumber = 3; | |
| var statusToStopPatroling = "screaming"; | |
| /*Nothing more to do*/ | |
| //var direction = ["N" => 360, "E" => 450, "S" => 540, "O" => 270]; | |
| list.forEach(function(token){ | |
| token.character = findObjs({_type: "graphic", name: token.tokenName})[0]; | |
| }); | |
| var i=0; | |
| var token = null; | |
| setInterval(function() { | |
| if(typeof list[i].character == "undefined"){ | |
| list[i].character = findObjs({_type: "graphic", name: list[i].tokenName})[0]; | |
| i = i>= list.length -1 ? 0 : i + 1; | |
| return; | |
| } | |
| token = list[i]; | |
| token.order = token.character.get("gmnotes", function(gmnotes){ | |
| return gmnotes; | |
| }); | |
| if(token.character.get("bar"+barLifeNumber+"_value") > 0 && !token.character.get("status_"+statusToStopPatroling)){ | |
| log(token.tokenName+" se déplace : "+token.order[token.orderList]); | |
| moveToken(token.character, token.order[token.orderList], pixelToMove); | |
| token.orderList = token.orderList >= token.order.length -1 ? 0 : token.orderList + 1; | |
| } | |
| i = i>= list.length -1 ? 0 : i + 1; | |
| },turnDuration*1000); | |
| function rotate(token, rotation){ | |
| token.set("rotation", rotation); | |
| } | |
| function moveToken(token, ordre, pixelToMove){ | |
| switch(ordre){ | |
| case "N": | |
| rotate(token, 360); | |
| token.set("top", token.get("top") - pixelToMove); | |
| break; | |
| case "E": | |
| rotate(token, 450); | |
| token.set("left", token.get("left") + pixelToMove); | |
| break; | |
| case "S": | |
| rotate(token, 540); | |
| token.set("top", token.get("top") + pixelToMove); | |
| break; | |
| case "O": | |
| rotate(token, 270); | |
| token.set("left", token.get("left") - pixelToMove); | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment