Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Triggered Cleanup/script.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "Triggered Cleanup",
"script": "Triggered Cleanup.js",
"version": "1.0",
"version": "1.1",
"previousversions": [],
"description": "Originally designed for a specific table, this script was made with one-offs and LC/Westmarches in mind. Many APIs find difficulties in running scripts when numerous tokens are left on a table. This script removes all tokens linked to a character sheet when using the command [!cleanup] in the chat. It also deletes tokens when the linked character sheet is deleted. It will ignore any tokens on a map that has the word [bullpen] in the name (not case-sensitive)",
"description": "Originally designed for a specific table, this script was made with one-offs and LCs/Westmarches in mind. Many APIs find difficulties in running scripts when numerous tokens are left on a table. This script removes all tokens linked to a character sheet when using the command [!cleanup] in the chat. It also deletes tokens when the linked character sheet is deleted. It will ignore any tokens on a map that has the word [bullpen] in the name (not case-sensitive)",
"authors": "Jeffrey Simons",
"roll20userid": "4069317",
"useroptions": [],
"dependencies": [],
"conflicts": []
}
}
3 changes: 3 additions & 0 deletions Triggered Cleanup/v1.1/Release Notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Improved efficiency by reorganizing when certain calls were made.

Found that two findObjs calls were performed with every chat entry. This should now only trigger when the API command is used.
55 changes: 55 additions & 0 deletions Triggered Cleanup/v1.1/Triggered Cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* This script wildelete all tokens that are linked to a character when entering [!cleanup] in the chat (not case-sensitive).
The script will also delete tokens for character sheets that are deleted.
The script will not delete any tokens on a map with the phrase "Bullpen" (not case sensitive) in the name.
*/
on('destroy:character',function(obj){
log(obj.get('_id'))
let tokens = findObjs({ type: 'graphic', represents: obj.get('_id') });
const inMap = new Array()
let maps = findObjs({type: 'page'})
for (let i = 0; i < maps.length; i++) {
if (maps[i].get('name').toLowerCase().includes('bullpen')){
inMap.push(maps[i])
}
}
for(let i = 0; i < tokens.length; i++){
let flag = 1
for(let j = 0; j < inMap.length; j++){
if(tokens[i].get('_pageid')===inMap[j].get('_id')){
log("inMap Name: " + inMap[j].get('name'))
flag = 0
}
}
if (flag){
tokens[i].remove();
}
}
})

on("chat:message", function(msg) {
if(msg.content.toLowerCase() === "!cleanup"){
let tokens = findObjs({ type: 'graphic' });
const inMap = new Array()
let maps = findObjs({type: 'page'})
for (let i = 0; i < maps.length; i++) {
if (maps[i].get('name').toLowerCase().includes('bullpen')){
inMap.push(maps[i])
}
}
for(let i = 0; i < tokens.length; i++){
log("Token: " + tokens[i].get('_id') + " & " + tokens[i].get('represents'))
let flag = 1
for(let j = 0; j < inMap.length; j++){
if(tokens[i].get('represents') === ''){
flag = 0
}
if(tokens[i].get('_pageid')===inMap[j].get('_id')){
flag = 0
}
}
if (flag){
tokens[i].remove();
}
}
}
})
Loading