Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Allow players ability to delete items on map layer

In my room, I have certain maps that players can control as tokens. I have the token-mod button there for them to be able to set it to map layer. is there a way to allow the players to delete all the tokens that players have control over on the map layer? 
1610090594

Edited 1610092655
Oosh
Sheet Author
API Scripter
An API script could do this, but otherwise I don't think there's any way for players to interact with the map layer. Here's an example - a player just types !delTok into chat (not case sensitive): on('ready', () => { on('chat:message', (msg) => { if (msg.type === 'api' && msg.content.match(/^!delTok/i)) { let playerId = msg.playerid; let pageId = Campaign().get('playerpageid'); let regex = new RegExp(`(${playerId}|all)`); let tokens = findObjs({type: 'graphic', subtype: 'token', layer: 'map', pageid: pageId}); if (tokens) tokens.forEach(t => { if (t.get('controlledby').match(regex)) { t.remove(); } else { let charId = t.get('represents'); if (charId) { let charControl = getObj('character', charId).get('controlledby'); if (charControl.match(regex)) t.remove(); } } }) } }) }) This will also delete tokens with "all players" control. If you don't want that to happen, just change line 6 to: let regex = new RegExp(playerId); This will check both the token controlledby settings, and the character sheet controlledby setting if the token is linked to one.
I tried this, and it didn't work. Would it make a difference if the tokens were attached to character sheets? 
1610500488

Edited 1610500608
Oosh
Sheet Author
API Scripter
If you're using it exactly as is (without the regex change) it should work. Do you have a token controlled by All Players on the Map Layer, on the same Page as the player ribbon? Since this is for use by players, it's not finding the current page by GM view, it's only looking for tokens: - on the player ribbon page - on the Map layer - token controlled by the player sending the !deltok command (does not work for GM) or - token controlled by "All Players" (works for GM) But it will look at token permissions before it looks for a linked character sheet, so you don't need to link it to a character sheet. If you use that regex change so it doesn't delete "All Players" controlled tokens, this will not function for the GM. I might have misunderstood how you want it to function - if it's for the GM to use, and to delete all player-controlled tokens, it'll need to be modified.
AH! That worked when testing it with a player account. Didn't realize it wouldn't work for GM. 
1610524750
Oosh
Sheet Author
API Scripter
Do you want me to change that? I wasn't sure if it was for you all the players. It could function so if a player runs it, it deleted anything they can control, but if the GM runs it, it deletes anything controlled by any player.
it actually works as is, and I love it! Thank you! 
1610613826
Oosh
Sheet Author
API Scripter
No problem!