Skip to content

Instantly share code, notes, and snippets.

@Bastlifa
Created September 28, 2018 23:17
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 Bastlifa/07aee200dd51f07d02341d13bdcf26b9 to your computer and use it in GitHub Desktop.
Save Bastlifa/07aee200dd51f07d02341d13bdcf26b9 to your computer and use it in GitHub Desktop.
Familiar Sight Swap for Roll20 D&D 5E
//Familiar Sight Swap
// make a macro with body:
// !SwapSight PlayerTokenName FamiliarTokenName
on("ready", function() {
on("chat:message", function (msg) {
if (msg.type === "api" && msg.content.split(' ')[0] === "!SwapSight") {
SwapSight(msg);
}
});
function SwapSight(msg)
{
var campaign = findObjs({type: "campaign"})[0];
var pageID = campaign.get("playerpageid");
var playerToken = findObjs({type: 'graphic', _pageid: pageID, name: msg.content.split(' ')[1]})[0];
var familiarToken = findObjs({type: 'graphic', _pageid: pageID, name: msg.content.split(' ')[2]})[0];
if (!playerToken)
{
sendChat("", "/w " + msg.who + " Player Token Not Found On Page");
return;
}
if (!familiarToken)
{
sendChat("", "/w " + msg.who + " Familiar Token Not Found On Page");
return;
}
if(playerToken.get("light_hassight"))
{
familiarToken.set("light_hassight", true);
playerToken.set("light_hassight", false);
}
else if (familiarToken.get("light_hassight"))
{
familiarToken.set("light_hassight", false);
playerToken.set("light_hassight", true);
}
else
{
playerToken.set("light_hassight", true);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment