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

[Script] Light-Crumb Trail (to let players see where they've been with dynamic lighting on)

January 09 (8 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

plexsoup said:

Regarding the whisper, I'll try and change it so it only whispers to the gm when the gm joins the game (and not the other players). I can definitely add a button to disable that feature.

I might suggest just having the help be user triggered rather than having it be a message that is displayed to the GM every time they log in. If it displays every time they log in, they could get it multiple times in a session if they have to reload the tabletop for lag issues/video&voice issues.
January 09 (8 years ago)
Pat S.
Forum Champion
Sheet Author

Scott C. said:

plexsoup said:

Regarding the whisper, I'll try and change it so it only whispers to the gm when the gm joins the game (and not the other players). I can definitely add a button to disable that feature.

I might suggest just having the help be user triggered rather than having it be a message that is displayed to the GM every time they log in. If it displays every time they log in, they could get it multiple times in a session if they have to reload the tabletop for lag issues/video&voice issues.

I agree with Scott on this. I run text based games and I would rather not have it constantly showing up in the log when I hop into the game mutliple times to work on stuff that does not even involve the use of the script.
January 09 (8 years ago)
Is it possible to get this to view terrain only?  While I can have my monsters talk the PCs on the GM layer, it'd simplify my life to keep doing it on the token layer.

Thank you very much for this; I'll be sure to give it a go after 1 click install is done.
January 09 (8 years ago)
The Aaron
Pro
API Scripter
Not possible with the API.  You could write a script (like bump) that automatically pushes non-PCs to the GM layer if they are moved into the range of a dropped light source.  That might get a bit complicated and possibly confusing.
January 09 (8 years ago)

Edited January 09 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I could make NPC tokens invisible (transparent icon with an aura only visible to the GM), but I can't make them reappear unless their images were uploaded by the user. (Set imgsrc restriction in the api.)

If Roll20 devs could make set imgsrc work for marketplace assets, we could store the imgsrc, set a status and aura, make them transparent, then change them back to original when the status changes.

Bump is probably a better way to go.

January 09 (8 years ago)
The Aaron
Pro
API Scripter
That has been on the API promised list for at least 2 gencons... I harass Riley about it every time I see him. =D (sorry Riley!)
January 11 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Something's gone wrong. I might need some help.

When i drop tokens, the light doesn't show up. If I look at the token details, they appear to have all the correct settings for light radius and dim light radius. If I then select the (unlit) tokens on the map, they suddenly start emitting light.

Here's a video of the strange behaviour in action.

Strangely, I haven't noticed this behaviour before now. So I don't think the dropped light-crumbs were misbehaving on previous versions.
(I haven't updated the original Gist because the new version is borked. Here's a link to the broken version.)

Anyone have any ideas?


Here's the relevant section of code:

currentLightCrumb = createObj('graphic',{
imgsrc: config.IMAGE,
subtype: 'token',
pageid: currentPage,
width: size,
height: size,
left: targetLocation[0],
top: targetLocation[1],
light_radius: config.LIGHT_RADIUS,
light_dimradius: config.DIM_RADIUS,
light_hassight: true,
light_otherplayers: true,
controlledby: "all",
layer: 'objects',
isdrawing: true
});


log( "dropped brand new currentLightCrumb: " + JSON.stringify(currentLightCrumb) );

-----------------
LOG:
"dropped brand new currentLightCrumb: {\"_id\":\"-KaBgkV5eGItZbk7yyIb\",\"_pageid\":\"7F73B956-71C3-4C5B-8C72-576EE4F15EA4\",\"left\":\"595\",\"top\":\"1085\",\"width\":35,\"height\":35,\"rotation\":0,\"layer\":\"objects\",\"isdrawing\":true,\"flipv\":false,\"fliph\":false,\"imgsrc\":\"https://s3.amazonaws.com/files.d20.io/images/17247606/Wbr841_bq9ka1FmamWo38w/thumb.png?1458169656\",\"name\":\"\",\"gmnotes\":\"\",\"controlledby\":\"all\",\"bar1_value\":\"\",\"bar1_max\":\"\",\"bar1_link\":\"\",\"bar2_value\":\"\",\"bar2_max\":\"\",\"bar2_link\":\"\",\"bar3_value\":\"\",\"bar3_max\":\"\",\"bar3_link\":\"\",\"represents\":\"\",\"aura1_radius\":\"\",\"aura1_color\":\"#FFFF99\",\"aura1_square\":false,\"aura2_radius\":\"\",\"aura2_color\":\"#59E594\",\"aura2_square\":false,\"tint_color\":\"transparent\",\"statusmarkers\":\"\",\"showname\":false,\"showplayers_name\":false,\"showplayers_bar1\":false,\"showplayers_bar2\":false,\"showplayers_bar3\":false,\"showplayers_aura1\":false,\"showplayers_aura2\":false,\"playersedit_name\":true,\"playersedit_bar1\":true,\"playersedit_bar2\":true,\"playersedit_bar3\":true,\"playersedit_aura1\":true,\"playersedit_aura2\":true,\"light_radius\":\"15\",\"light_dimradius\":\"5\",\"light_otherplayers\":true,\"light_hassight\":true,\"light_angle\":\"\",\"light_losangle\":\"\",\"light_multiplier\":1,\"sides\":\"\",\"currentSide\":0,\"lastmove\":\"\",\"_type\":\"graphic\",\"_subtype\":\"token\",\"_cardid\":\"\"}"

January 11 (8 years ago)
The Aaron
Pro
API Scripter
That's super strange.  I would suggest restarting your browser.  I tried the linked script and it is working fine for me.  A display issue like that is almost certainly on the client side (browser), rather than the server side (API). 
January 11 (8 years ago)

Edited January 11 (8 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
I see from the TODO list in your script's comments that you're looking for some occlusion code for handling line-of-sight to the breadcrumbs. I do this for checking line-of-sight to traps in my It's A Trap script.

Check out the below snippet from It's A Trap:
...

  /**
   * Gets the tokens that a token has line of sight to.
   * @private
   * @param  {Graphic} token
   * @param  {Graphic[]} otherTokens
   * @param  {number} [range=Infinity]
   *         The line-of-sight range in pixels.
   * @param {boolean} [isSquareRange=false]
   * @return {Graphic[]}
   */
  function _getTokensInLineOfSight(token, otherTokens, range, isSquareRange) {
    if(_.isUndefined(range))
      range = Infinity;

    var pageId = token.get('_pageid');
    var tokenPt = [
      token.get('left'),
      token.get('top'),
      1
    ];
    var tokenRW = token.get('width')/2-1;
    var tokenRH = token.get('height')/2-1;

    var wallPaths = findObjs({
      _type: 'path',
      _pageid: pageId,
      layer: 'walls'
    });
    var wallSegments = PathMath.toSegments(wallPaths);

    return _.filter(otherTokens, other => {
      var otherPt = [
        other.get('left'),
        other.get('top'),
        1
      ];
      var otherRW = other.get('width')/2;
      var otherRH = other.get('height')/2;

      // Skip tokens that are out of range.
      if(isSquareRange && (
        Math.abs(tokenPt[0]-otherPt[0]) >= range + otherRW + tokenRW ||
        Math.abs(tokenPt[1]-otherPt[1]) >= range + otherRH + tokenRH))
        return false
      else if(!isSquareRange && VecMath.dist(tokenPt, otherPt) >= range + tokenRW + otherRW)
        return false;

      var segToOther = [tokenPt, otherPt];
      return !_.find(wallSegments, wallSeg => {
        return PathMath.segmentIntersection(segToOther, wallSeg);
      });
    });
  }

...
January 11 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter

The Aaron said:

That's super strange.  I would suggest restarting your browser.  I tried the linked script and it is working fine for me.  A display issue like that is almost certainly on the client side (browser), rather than the server side (API). 

That makes sense. I'll give it another go. Thanks.


Stephen L. said:
I see from the TODO list in your script's comments that you're looking for some occlusion code for handling line-of-sight to the breadcrumbs. I do this for checking line-of-sight to traps in my It's A Trap script

Sweet! Thanks. I'll definitely incorporate this.
January 11 (8 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Go right ahead! Just note that the snippet requires both PathMath and VecMath.
January 13 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter

plexsoup said:

Something's gone wrong. I might need some help.

When i drop tokens, the light doesn't show up. If I look at the token details, they appear to have all the correct settings for light radius and dim light radius. If I then select the (unlit) tokens on the map, they suddenly start emitting light.

Here's a video of the strange behaviour in action

Found my bug!

For anyone curious...

var movementPath = token.get("lastmove");  // produces a string of comma delimited numbers.
var travelLocationsArray = token.get("lastmove").split(","); // produces an array of strings, not numbers.
//var X = travelLocationsArray[0]; // is a string.
var X = Number(travelLocationsArray[0]); // works better

// don't try creating dynamically lit objects with strings as parameters for "left" and "top". They'll go where you expect, but won't be lit until moved.


January 13 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
The Gist is updated... torches now appear at the token's last known location, instead of their current one. 

Should solve problems with torches appearing on top of characters, and also torches appearing on the other side of walls.

January 13 (8 years ago)
Pat S.
Forum Champion
Sheet Author
Goofing around with the script and noticed something. I get nothing from the GUI if I'm using the talktomyself function.
January 13 (8 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Pat S. said:

Goofing around with the script and noticed something. I get nothing from the GUI if I'm using the talktomyself function.

Yep, API commands don't work with /talktomyself as the chat message is not sent anywhere besides the dice roller.
January 13 (8 years ago)
Pat S.
Forum Champion
Sheet Author
I figured that but since I don't use it much, I thought I might mention it.
January 13 (8 years ago)
The Aaron
Pro
API Scripter

plexsoup said:

plexsoup said:


Found my bug!

For anyone curious...

var movementPath = token.get("lastmove");  // produces a string of comma delimited numbers.
var travelLocationsArray = token.get("lastmove").split(","); // produces an array of strings, not numbers.
//var X = travelLocationsArray[0]; // is a string.
var X = Number(travelLocationsArray[0]); // works better

// don't try creating dynamically lit objects with strings as parameters for "left" and "top". They'll go where you expect, but won't be lit until moved.

Interesting!  parseFloat() or parseInt() are what I'd usually use to convert from a string.  Technically you shouldn't instance a class like Number without the new operator.
January 14 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Some updates:

You can now decide whether lightcrumbs will have shared vision, or unique vision for the player who dropped them.

I haven't tested the unique vision with a group. Let me know if it behaves as expected.
(Changing the vision sets the "controlledby" parameter on the token, by adding or removing "all players".)

I've also reincorporated optional offsets. You can decide whether you prefer dropping the lightcrumbs at the token's last location or the current location plus some directional offset. (I think the offset looks cooler, but I understand how it might penetrate walls now and then.)

Now that each character can have their own trail, Crumbs are identified with the character's initials. You can toggle name displays to make it a bit easier to identify who owns which trail.

https://gist.github.com/plexsoup/64852540504101b52...



January 14 (8 years ago)
Kryx
Pro
Sheet Author
API Scripter
Making the case again for the vision based on the current token:

This feature is basically Blizzard style fog of war. In games that incorporate fog of war the vision that is left is based on the unit that gave the vision. For example in Starcraft an Overlord who is flying gives a much large vision radius than a burrowed zergling.
For that reason I'd encourage you to base the vision of the light object on the token from which it originates.
January 14 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I'll work on that next, Kryx
January 15 (8 years ago)

Edited January 15 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Added a few things, including inherited light settings per Kryx.

https://gist.github.com/plexsoup/64852540504101b52...

There's a couple of little gremlins, but it works ok for the most part.
Next priority is bugfixing. Then maybe refactoring.

Video in action
January 15 (8 years ago)
Arthur B
API Scripter
Love that script! Any chance it will be part of the roll20-api-scripts repository?
January 15 (8 years ago)
Kryx
Pro
Sheet Author
API Scripter
Thanks for doing that plex. I'll be sure to get it running for my game on Tuesday and report back.
January 16 (8 years ago)

Edited January 16 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter

Arthur B said:

Love that script! Any chance it will be part of the roll20-api-scripts repository?

Eventually. But first I need to seriously test it for bugs.
I'd hate to release it as 1-click and have everyone mad cause it breaks.

You can help by... testing it for bugs.

January 16 (8 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

plexsoup said:

Eventually. But first I need to seriously test it for bugs.
I'd hate to release it as 1-click and have everyone mad cause it breaks.

Can attest that this sucks to do
January 16 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Got a few bugs fixed.

The revised script is at the same address.

Let me know if it works for you.
January 16 (8 years ago)
Arthur B
API Scripter

plexsoup said:

Arthur B said:

Love that script! Any chance it will be part of the roll20-api-scripts repository?

Eventually. But first I need to seriously test it for bugs.
I'd hate to release it as 1-click and have everyone mad cause it breaks.

You can help by... testing it for bugs.


Ah, I'm doing that right now. Testing, I mean. I'm spamming my map with torches right now.

But I'm actually not (yet) talking about a 1-click installation. I'd just like to have it as part of the roll20 repository on github. I have a script that combines all the scripts that I'm using into one, and it's taking the original scripts directly from the cloned repository (the script triggers a git pull before). So I always have the newest scripts in one big file, without manual work. :)
January 16 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Ah. Yeah. I can probably do that.


January 18 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Hopefully it's working well for people in actual games.

I've submitted a pull request to the API repository for 1-click.

In the meantime, you can still grab it from the same old gist.

Latest version just changed the help document and reorganized the config options a bit.

January 19 (8 years ago)
To answer the question of: would it be cool if they burnt out over time?  Hell yes!  Any luck on getting them visible only to the player that dropped them?
January 19 (8 years ago)

Edited January 19 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter

Sudain said:

Any luck on getting them visible only to the player that dropped them?
Yes. By default, players only see through their own torches, but if you click "Toggle Shared Vision", it should switch to a mode where players see through everyone's torches. You can verify be looking at one of the torches. It'll be controlled either by the player, or by "all players".
 
Players can still see each other's torches when they're not hidden by walls. I might need to tweak the "all players see light" setting.
January 19 (8 years ago)
Sweetness!  :)
January 19 (8 years ago)

Edited January 19 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I've just updated it. In the latest version, torches only cast light to the players who made them. (Unless you turn on Shared Vision mode).
https://gist.github.com/plexsoup/64852540504101b52...

Please let me know if you have any problems with the script. Errors, confusion, feature requests, whatever.
January 20 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Grab the new script to avoid a bug where it broke if no character was assigned to the registered token. 

https://gist.github.com/plexsoup/64852540504101b52...

January 20 (8 years ago)

Edited January 20 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Updated again to fix a couple more edge cases. Same URL
January 20 (8 years ago)
Awesome, thank you.
January 23 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
New video shows the latest GUI
January 30 (8 years ago)
The LightCrumb API is in the Roll20 API Script Library but when I installed it if does not work.  When I type !LightCrumb nothing happens.

Any ideas?
January 30 (8 years ago)

Edited January 30 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
The script.json had a typo in it. So the 1-click version doesn't work yet.

For now, just make a new script and cut and paste the text of the script from the gist.
https://gist.github.com/plexsoup/64852540504101b52...

It may be a few weeks before the 1-click version works.
February 07 (8 years ago)
Hey, @plexsoup. I added an option to the script to change the size of the aura, which I think would be useful to others as well. Could you take a look at it and maybe add the changes to your script?

https://gist.github.com/Tritlo/fd26b55bba363ef0dc2ef26ccde28b7b
February 07 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
Awesome! Sounds like a good addition. I'll take a look.
February 07 (8 years ago)
plexsoup
Marketplace Creator
Sheet Author
API Scripter
I posted your changes back to my Gist and tweaked the units slightly.