forked from Kekilla0/Personal-Macros
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Token Control.js
50 lines (50 loc) · 1.45 KB
/
Token Control.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*Token Control (GM Token Executer)
args [ objectName,updateData,options ]*/
(async () => {
if(args[2] === "create")
{
await create_Token(args[0],args[1]);
}
if(args[2] === "update")
{
await update_Token(args[0],args[1]);
}
if(args[2] === "delete")
{
await delete_Token(args[0],args[1]);
}
})();
async function create_Token(obj = "", data = "")
{
let token = game.actors.find(i=>i.name===args[0]).data.token;
if(!token) return ui.notifications.error(`There is no token by that name in this game.`);
await canvas.tokens.createMany(token,"");
await update_Token(args[0],args[1]);
display(args[0] + " token created");
}
async function update_Token(obj = "", data = "")
{
let token = canvas.tokens.placeables.find(i=>i.name===args[0]);
if(!token) return ui.notifications.error(`There is no token by that name on this canvas.`);
await token.update(args[1]);
display(args[0] + " token updated");
}
async function delete_Token(obj = "", data = "")
{
let token = canvas.tokens.placeables.find(i=>i.name===args[0]);
if(!token) return ui.notifications.error(`There is no token by that name on this canvas.`);
await canvas.tokens.deleteMany(token.data._id,{});
display (args[0] + " token deleted");
}
function display(data = "")
{
if(!data === "")
{
ChatMessage.create({
user : game.user._id,
content : data,
speaker : speaker,
whisper : game.users.entities.filter(u=>u.isGM).map(u=>u._id)
});
}
}