Created
January 10, 2014 05:54
-
-
Save Cazra/8347581 to your computer and use it in GitHub Desktop.
roll20 API familiar summon (broken)
This file contains 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
// This script allows the players to summon their familiars. | |
// When summoned, the familiar appears in their | |
// master's square. | |
on("chat:message", function(msg) { | |
var cmdName = "!familiar"; | |
var msgTxt = msg.content; | |
var curPageID = Campaign().get("playerpageid"); | |
// map of familiars to images. | |
var familiarImages = {}; | |
familiarImages["Furret"] = "https://s3.amazonaws.com/files.d20.io/images/1409306/apzVimdgBQGGWh-f_7jurw/thumb.png?1373339440"; | |
if(msg.type == "api" && msgTxt.indexOf(cmdName) !== -1) { | |
var selectedArray = msg.selected; | |
for(var i in selectedArray) { | |
var _id = selectedArray[i]._id; | |
var masterToken = findObjs({id:_id, _pageid: curPageID})[0]; | |
var familiarName = "Furret"; | |
var familiarToken = findObjs({_pageid:curPageID, layer:"objects", name:familiarName})[0]; | |
if(familiarToken) { | |
familiarToken.set("left", masterToken.get("left")); | |
familiarToken.set("top", masterToken.get("top")); | |
} | |
else { | |
familiarToken = createObj("graphic", | |
{ | |
_pageid:curPageID, | |
layer:"objects", | |
name:familiarName, | |
imgsrc:familiarImages[familiarName], | |
left:masterToken.get("left"), | |
top:masterToken.get("top"), | |
width:70, | |
height:70 | |
} | |
) | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment