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

Roof removal script

October 08 (7 years ago)
Is there any sort of script that could work similarly to One-Way Dynamic Lighting except have it make a roof disappear when someone stands at the entrance or inside. This would make it so a roof could hide the contents of a building could be hidden by a roof until entered. I don't know if a script like this exists, but if it does: great! If it doesn't is there anyone who could make this script, assuming it's not overly difficult and unreasonable to request?
October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I would suggest using a rollable table token, and put the roof and each floor on a separate face. You can then switch faces with ChangeTokenImage on a macro. It might take some finesse to get the maps to line up, depending on how they are constructed and cropped.
October 08 (7 years ago)

Edited October 10 (7 years ago)
Bast L.
API Scripter
While I really like the idea of this, there are some problems, especially with dynamic lighting. However, if it's just in a town or something, and you don't care about the lighting, it's not too tough to do. It kinda looks bad for the gm, but it should look ok for the players. 

Anyways, I'm sure I violated a dozen proper programming do's and don'ts, and it also kinda brute forces its way with nested loops, but here's what I have for it:

Rooftops + dynamic lighting script: https://gist.github.com/Bastlifa/5a8eaa6f7259c2e9e...

Steps to use this script:
  • Save the script in your APIs
  • Have a token on your map which is either assigned to a player, or represents a character which is assigned to a player
  • Have a roof token which has the name roof. No caps, because I really am that lazy.
  • Have your players flag on the page you're trying to use it on. The flag is the red thing that moves players to a page.
  • enter !RoofReady into the chat as a command. Making a macro would work. Also, if you move the player flag to the page, it should set RoofReady for you.
  • If you change the player tokens, drag out a new one, make a new roof, whatever, you'll need to hit the !RoofReady command.
  • It's easier to draw your dynamic lighting before placing the roof.
  • It will move all paths, including object layer paths, to GM and DL layers, so, fair warning.
  • The screenshots below are before it incorporated dynamic lighting. See another post further down for images of it interacting with DL.


When you move the player page, or you enter !RoofReady into the chat, it updates the player tokens and roof tokens, making them ready. Any time you drag out new players, though, you'll need to use !RoofReady

When you go inside the roof token with a player token, the roof token transfers to the gm layer, when you're outside it, it transfers back to the map layer. You have to name your roof tokens "roof", and my crappy script doesn't even allow for case-insensitivity :) 

Also, keep in mind, sometimes roof tokens extend out a bit, so make sure you're fully out when waiting for it to restore the roof.

Also, it's pretty buggy atm, I'll try to update in a minute or two. Here's some screenshots:





edit: oh, the bug has to do with the token's controller. Until I fix it (or someone else does), have the token not reference a character, then assign it to a player, then reassign to a character. I'll try to fix that though.

Ok, that bug is fixed. I'm sure there are plenty more :)

edit: Maybe I should move it to the DL layer to make it less ugly for the GM

Here's a screenshot from a player perspective though:


October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Ooh, I want to check this out. That sounds  like a great idea!
October 08 (7 years ago)
Bast L.
API Scripter
Please let me know if you find any bugs Keith.
October 08 (7 years ago)
@Bast: I'm trying to test it out now. I've added a room with a roof token named "roof", used the "!RoofReady" command in chat, but nothing happens. I get no indicator in chat that the command worked, and walking under the roof doesn't seem to do anything.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
@G: Are you walking under the roof with a token linked to a character which is assigned to someone (even yourself)? Or with a token which is not linked to a character, but which is assigned to someone?

It should only change if the tokens are controlled by someone (assigned to someone, either via the linked character being assigned to someone, or the token being assigned directly). This way, you can have non-player tokens inside, which don't remove the roof.

edit: also, there shouldn't be any indication that it works, though I could put one in. I'll see about doing that now.

edit again: it now send the gm a message saying the rooftops are ready, how many player tokens there are, and how many roof tokens there are. If either of those values is 0, expect no interaction.

edit further still: just to be sure, the roof token should be named: roof, rather than "roof". That is, don't include the quotes.
October 08 (7 years ago)
Bast L.
API Scripter
Also, just updated the script to look on all layers for tokens named "roof". There was a bug when reloading the game with roofs already on the GM layer.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Okay, I've got it working, except that when the token leaves the roof, it doesn't come back to the object layer.

EDIT: Never mind, I don't know what I did, but it's working now.
October 08 (7 years ago)
Bast L.
API Scripter
You kinda have to go a ways outside of it, and all of the player tokens have to leave. I'm not sure why the entrance is different from the exit, but just make sure to go outside of it a bit further.
October 08 (7 years ago)
New issue, it's moving the roof between the GM and Map layer, which means when they go "under" the roof before it goes to the GM layer, they appear to be walking on top if it.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Do a pull request to roll20 api scripts Basto, if not one of us can. This would be handy if the dm urge strikes again like the infamous Turn Clock script! great work on that one Bast
October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
Update: Now moves the roof to the walls (dynamic lighting) layer, for prettier GM viewing. Mark, mind doing the pull request for me? I have no idea how to use github.

edit: also, my turn clock script was really rewritten by Aaron, maybe he should get credit for it :)

edit further: Given The G's error, maybe we should hold off on the pull request
October 08 (7 years ago)
Getting the following error and no clue why:

TypeError: Cannot read property 'set' of undefined
TypeError: Cannot read property 'set' of undefined
at removeRoof (apiscript.js:12426:34)
at apiscript.js:12455:58
at eval (eval at (/home/node/d20-api-server/api.js:146:1), :65:16)
at Object.publish (eval at (/home/node/d20-api-server/api.js:146:1), :70:8)
at TrackedObj.set (/home/node/d20-api-server/api.js:909:14)
at updateLocalCache (/home/node/d20-api-server/api.js:1194:18)
at /home/node/d20-api-server/api.js:1378:11
at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560
at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546)
October 08 (7 years ago)

Bast L. said:

Update: Now moves the roof to the walls (dynamic lighting) layer, for prettier GM viewing. Mark, mind doing the pull request for me? I have no idea how to use github.

Can you have it go back to the GM layer? I've found a way to use it with dynamic lighting and have it look very pretty (Well, maybe I'm testing but could be wrong.)
October 08 (7 years ago)
Bast L.
API Scripter
On line 66, change 'walls' to 'gmlayer', that should do it.

I'm trying to figure out the error. Do you know what leads to it? I've tried deleting, and messing around with tokens, but I can't replicate it.
October 08 (7 years ago)
I'm not sure; I'm not getting the error now, but I have a different issue. The roof won't change back. It just stays GM layer, and when I try to change it manually, it automatically changes back to GM layer.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
Is there an assigned token inside of the roof token? If so, that result would make sense. (the token limit is the box you see when you select it, not the image that you see)
October 08 (7 years ago)
I found the issue. It was part of my attempt to work around and make dynamic lighting work. Is there a way to make detect all player tokens, but exclude one with a specific name?
October 08 (7 years ago)
Bast L.
API Scripter
On line 52, put a conditional around the if and its nest.

something like,  if (allPlayerTokens[i].get("name") != "yourExcludedName")
October 08 (7 years ago)
Hmm, so, it kinda works. Pretty much, I was the idea was to have the roof token controlled by a "player" that no player actually controlled and have it share vision but change the sight radius to 0, that way they could see it regardless of dynamic lighting but couldn't see it if they weren't close enough. It ended up not working because they could just see the roof floating even if they weren't near it. It could work on an outside daytime map if you wanted to have the walls of building to obstruct view, but if it was outside and night or inside a cave, it wouldn't work as intended. Oh well, your script still works perfectly for my original desire! Which is fine because on an outside map, I wouldn't use enforce line of sight anyway.
October 08 (7 years ago)
Bast L.
API Scripter
So, I thought about it before, and trying to link roof tokens and paths seemed like a pain, but then I realized I can just do the same check to see if a player is inside to deal with dynamic lighting paths.

It may cause even more errors, and it stores the dynamic lighting paths on the gm layer when not used, but here's a new gist for rooftops + dynamic lighting: https://gist.github.com/Bastlifa/5a8eaa6f7259c2e9e...

Some screenshots from player perspective:

player token outside:



Player looking in window:



Player inside:

October 08 (7 years ago)

Edited October 08 (7 years ago)
Wait so, does it store the walls on the gm layer, but then when you "enter" the building, it moves it to the walls layer?
October 08 (7 years ago)
Bast L.
API Scripter
Yeah
October 08 (7 years ago)
How does it detect the player token in order to switch in the dynamic lighting to the walls layer? I can't figure that out.
October 08 (7 years ago)
Bast L.
API Scripter
When the player enters the roof area, the roof switches to the dynamic lighting layer (and does nothing there, since only paths do anything on that layer, unless it emitted light), and at the same time, any paths within that roof area will switch to the dynamic lighting layer, which will make dynamic lighting begin working for that building. 

When the player leaves the roof area, the roof goes to the map layer, and any paths in that roof area will transfer to the gm layer, disabling dynamic lighting walls for the building.

The removeRoof function calls the restorePath function, and the restoreRoof function calls the removePath function. Basically, they toggle.
October 08 (7 years ago)
Hmm, I'm not sure what's wrong then. I've got paths in the GM layer under the roof and they don't seem to be changing. Do they have to be lines or can they be boxes?
October 08 (7 years ago)
Bast L.
API Scripter
I'm not sure about boxes, but I suggest using the polygon tool. Also, did you update the script? There are now two versions, original and rooftops + dynamic lighting.

The way to go about it is:

  1. Have a map with a building.
  2. Draw the dynamic lighting for the building on the dynamic lighting layer (it should be layer independent actually), using polygon tool.
  3. Switch to the map layer.
  4. Drag out a roof token.
  5. Size is and place on building.
  6. Name it roof.
  7. Have a player token somewhere on the map.
  8. enter !RoofReady into chat.
  9. Move player up to the building.

October 08 (7 years ago)
Okay, when I draw the dynamic lighting layer, everything else works properly, but the dynamic lighting just stays as it is.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
I'm not sure what's up with it. Want to invite me, or have me invite you to a test game to see?

edit: though roll20 is being difficult atm, so maybe we can try later.
October 08 (7 years ago)
Invited you to my game. I'll GM you when you join.
October 08 (7 years ago)
Bast L.
API Scripter
Seems sorted now.
October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It's looking really good. I tried the first script with little success. I had better luck with the DL script, though it might be because I also moved the player flag to the map I was on. Would that affect the action?

Also, it looks like it may require cropping roof tokens very tightly. It disappears once my token gets within 5 squares of it, though there is only 1 square of transparent padding.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
Yeah, I mean, it's just based on the token size, so if there's padding, then it'll disappear early. Also, I think it only works on the page where the player flag is.

I suppose that could be an issue if the players are split up into different pages. I'll take a look maybe at making it work on any page that a player (including gm) is on.

edit: oh, as for disappearing within 5 squares, I'll have to test that.
October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Also, I have two PC tokens that are controlled by the GM on the token layer, though neither has specific "controlled by" settings. they are just my personal PCs. One of them it works for, but not the other. I am attaching the edit screens, though I can see no difference between the two. Also, the report shows only 1 player token. Any ideas?


October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
That is very strange. I wonder, if you drag out their tokens onto the map, and then open the tokens, are either of them unlinked from character sheets? If so, are they assigned to anyone? That's the only way I could replicate it.
October 08 (7 years ago)
Bast L.
API Scripter
Also, regarding padding, Mine only turns off when it's actually inside the box on the roof token. I wonder if I could join your game to see what's up.
October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I think I have solved the margin issue. One of my rooftop tokens is rotated, but the script is acting as if it is not. In other words, for a 20 x 40 roof, the token activates as if it were filling a 40 x 20 space.

Keep up the debugging though. I think you have a really hot idea on your hands. This is a very simple and easy to use solution for a problem a lot of people would like solved. This is better and less overhead than a "roof layer" would be. The fact that each roof has its own space and action is fantastic.
October 08 (7 years ago)

keithcurtis said:

I think I have solved the margin issue. One of my rooftop tokens is rotated, but the script is acting as if it is not. In other words, for a 20 x 40 roof, the token activates as if it were filling a 40 x 20 space.
That's an issue that likely needs to be handled. If you were to make a cityscape it could look kinds weird if you couldn't rotate things properly
October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It works fine with other PC tokens.
October 08 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Gotta go now, but I will work more on debugging tonight. Again, great idea for a script!
October 08 (7 years ago)
Bast L.
API Scripter
Hmm, rotated tokens could be an issue. I mean, it's trivial to fix for rotations with multiples of 90 degrees, but 45, or weird rotations might be a problem.
October 08 (7 years ago)

Edited October 08 (7 years ago)
Bast L.
API Scripter
I've updated the script to work with rotations of 90, 180, 270, and 0 degrees. Odd rotations are still off, but.. whatever :)

edit: more bugs, working on it.

edit: bugs fixed, as far as I can tell.
October 09 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Are all changes only to the DL version of the script?
October 09 (7 years ago)
Bast L.
API Scripter
Yeah
October 09 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That is working great. I haven't tested the Dynamic Lighting yet, but I will tonight.
October 09 (7 years ago)
Bast L.
API Scripter
Nice. Thanks for testing it. I think I may end up using this one.
October 09 (7 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It could also be used to reveal something beyond the edge of a cliff. I.e. the area below, which can only be seen when standing on the edge.
October 09 (7 years ago)
The Aaron
Pro
API Scripter

Bast L. said:

edit: also, my turn clock script was really rewritten by Aaron, maybe he should get credit for it :)
Eh?  What Turn Clock Script?  I'm fine with just a mention in the comments, if you put my name on it I'll have to support it! =D (of course, I'd probably help support it anyway...)