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

A Little help with a remove Token from map with a macro/api?

All my players have normal vision, so they have to uses torches for light in dark areas. Some of them have to drop their torch if they get into an encounter. I have a macro that will switch their token vision from Torch to Normal, while also spawning a torch Token at their feet. !scriptcard {{ --#Title|Drop Torch --+@{selected|character_name}| drops their torch. --@forselected+|Spawn _name|Torch --@forselected+|token-mod _on bright_vision _off night_vision emits_bright_light emits_low_light has_directional_bright_light has_directional_dim_light }} I don't know if this is possible or not, but I was wondering if you can macro or if there is an API that can do it, I want to have a macro that will remove/delete the torch token from the map when the player decides to pick up the said torch. Kinda of like the drop torch macro that I have that changes the player tokens vision and spawns the torch token, but in reverse, remove the torch token and give the player token the vision of the torch again.
I think the Spawn script has an option for deleting a selected token, but I can't remember if that works without having to have it spawn a new token. Might be worth trying out!

Edited 1621428598
The Aaron
Roll20 Production Team
API Scripter
The biggest problem is how to selected it. I actually wrote a little script for someone that drops a torch (for LDL, but it could be modified for UDL), not sure if it's of interest, but I'll put it here just in case: on('ready',()=&gt;{ const torchSrc = "<a href="" rel="nofollow"></a>"; const dropTorch = (obj) =&gt; { if(obj.get('light_hassight') &amp;&amp; obj.get('light_otherplayers')){ let size = Math.min(parseFloat(obj.get('width')),parseFloat(obj.get('width'))); let torch = createObj('graphic',{ imgsrc: torchSrc, pageid: obj.get('pageid'), layer: obj.get('layer'), controlledby: 'all', width: size, height: size, left: obj.get('left'), top: obj.get('top'), light_otherplayers: true, light_angle: obj.get('light_angle'), light_radius: obj.get('light_radius'), light_dimradius: obj.get('light_dimradius') }); setTimeout(()=&gt;toBack(torch),50); obj.set({ light_angle: 360, light_radius: 0, light_dimradius: 0 }); } }; on('chat:message',(msg)=&gt;{ if('api'===msg.type &amp;&amp; /^!drop-torch(\b\s|$)/i.test(msg.content)){ (msg.selected || []) .map(o=&gt;getObj('graphic',o._id)) .filter(g=&gt;undefined !== g) .forEach(dropTorch) ; } }); });

Edited 1621437019
David M.
API Scripter
Interesting. Never tried it before, but it turns out with Spawn you can have a token delete itself. If you selected your torch and then ran the following command, the source token would delete itself, then the spawned copy of that token would utilize the delete-after-expand functionality to rapidly expand to full size (1 frame animation in 1ms) and then delete itself. It appears instant. !Spawn {{ --name|@{selected|character_name} --deleteSource|true --expand|1,1, true&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//the "true" triggers the delete after animation. This was originally meant for instantaneous AoEs, but works for this case as well }} If you modified your scriptcard to have the torch be the selected token and the character in question to be a target, you could try running the above Spawn code within a new scriptcard and pass the target tokenid to token-mod with the --ids command. Just make sure you have the "players can use ids" option enabled for token-mod or else it will fail. EDIT - Since this would require the light source token to be selected (opposite from your "I'm lighting a torch" scriptcard), I would manage it by adding a "pick me up" token action ability calling the new scriptcard that is located in the light source character sheet, with a target prompt saying something like "who is picking me up?"&nbsp; EDIT 2 - I removed the --offset line from my example above. It was not necessary and was just left in there from my testing. A bit hacky, but seems like it would work.

Edited 1621435586
API Scripter
So, there isn't, afaik, a way to delete a token with the API. ... EDIT : I might be wrong with the above, and David's solution might be all you need. The rest of my post should still all be an option, too. ...However, you can move it to the gmlayer with tokenmod (so it's hidden from the players): !token-mod --set layer|gmlayer Like Aaron said, the trick is getting it selected. You are already using SelectManager in the macro you posted, so you can work around this using a targeting statement and virtually selecting the *actually* selected token. I'll use APILogic, too, but I know ScriptCards has its own logical structures: 1 2 3 4 5 6 7 8 9 10 11 12 !scriptcard {{ --#Title|The Great Torch Snatching {&amp; select @{selected|token_id}} {&amp; if "@{target|Torch|token_name}" = Torch} --+@{selected|character_name}| snatches up a torch. --@token-mod _ignore-selected _ids @{target|Torch|token_id} _set layer|gmlayer --@forselected+|token-mod _off bright_vision _on night_vision emits_bright_light emits_low_light has_directional_bright_light has_directional_dim_light {&amp; else } --+That isn't a torch, and I'll thank you for not bothering my chinchilla. {&amp; end} }} In line 3, we tell SelectManager to re-select the token that is selected. Since we're using a targeting statement, we'll lose the array of selected tokens that would normally accompany the message. The @{selected|token_id} construction will be parsed already by then, so we use it to re-select the token. Note that this isn't necessary if you want to change the TokenMod line in line 6 to ignore selected and operate on an --ids argument the way I did in line 7. In that case, you'd just pass the @{selected|token_id} to the line 7 call of TokenMod. I am including the process to actually/virtually select the token because a lot of times people post a simplified version of their question. If there is more you want to do to the token (like feed it to another script that doesn't allow you to input the IDs to affect instead of the selected tokens, the way TokenMod does), then you might actually need it to be selected. In line 4, we double check that the targeted token is named "Torch", since that's what your former macro was labeling all of the Spawned Torch tokens. You don't want your players deciding to "pick up" your campaign-culminating Grand Boss-o-mancer. =D If the targeted token is named "Torch", the targeted token gets sent to the GM layer and the proper settings are adjusted on the selected token (I think -- I just reversed your on/off out of your first macro). In other words, APILogic includes lines 5-7 in what reaches ScriptCards. If the targeted token is not named "Torch", then only line 9 survives to reach ScriptCards.