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] Interpolated trap detection

December 20 (11 years ago)

Edited February 21 (9 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
I've created a trap script that is not only very easy to define traps with, but also detects if your players move through a trapped square during their movement. This works even if they didn't end their movement on the trap!

If the player activates a trap during their movement, Admiral Ackbar will alert everyone, the player's token will be moved to the trap, and the player's token will receive a status marker to indicate that they are trapped. This system also supports flying tokens. If a character token is flying, they will only activate traps that are also flying.

To create traps:
Create a token on the GM layer with the "cobweb" status marker enabled. That is all. Easy, with no need to manually set trap coordinates in the script! If the trap also affects flying characters, also enable either the "fluffy-wing" or "angel-outfit" status.

I'll have fun with this in my campaign. I hope other GMs find this useful as well!

https://github.com/Roll20/roll20-api-scripts/tree/master/Its%20A%20Trap

Notice: Requires the additional scripts mentioned in the header comment.

December 20 (11 years ago)
aRotondi
Sheet Author
Fantastic sounding! Will have to test with this later tonight.
December 20 (11 years ago)

Edited December 20 (11 years ago)
Just tested this... works great! Here's what else I'd like to see...

  1. A way to set a trap token on the GM Layer that is moved to the Map layer when the trap is triggered. This would be most useful for a pit trap that opens up beneath the character.
  2. Prevent the TRAP message from being sent when moving a trap around on the GM Layer.
  3. A way to turn off logging.
December 20 (11 years ago)

Edited December 20 (11 years ago)
Also, it doesn't behave if the player uses waypoints.
December 20 (11 years ago)

Edited December 20 (11 years ago)
Very interesting script. Which actually makes me wonder, can we use something like this and call it against the waypoint system?

--Edit
Apparently not. That's what I get for having the page up for a while before hitting submit.
December 20 (11 years ago)
It sorta works with waypoints... but it's messy.
December 20 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Thanks for checking the script out, guys!

HoneyBadger, I like those suggestions. I'm currently working on implementing them into the script.

I've never done anything with waypoint movement, so I did not design the script around that system. I'm working on providing an interface for the script that would make it easy to see if the token passed through a trap during one of its waypoint segments though.
December 20 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Updates:
*You can now set traps to move to the objects layer when they're activated. To do this, simply enable the "bleeding-eye" status on the trap.
*Only tokens on the objects layer can now activate traps.
*Commented out the logging messages.
*Made an interface function for running the script on an object moving in a straight line between two points.
December 20 (11 years ago)
For your logging messages, you should just create a variable at the beginning of the script to turn logging on or off instead of commenting them out. I only asked for that because I use logging in some of my other scripts and didn't want to have to wade through the trap spam.
December 20 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Ah, I see. I'm just going to leave them commented out for now though.

I think you'll be happy to hear though...

Update:
*Works with waypoints!
December 20 (11 years ago)
Alright, now you're awesome. :P

Now, last question. Will an larger person (10' or 15' spacing) trigger a trap, since their top/left doesn't match a 5' trap when they step on it?
December 20 (11 years ago)
Awesome.
December 20 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Brandon, yes. It works for larger tokens too.
December 20 (11 years ago)
Awesome. Time to rebuild a few traps for my game tomorrow then.
January 20 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Script update.
Discovered and fixed some bugs in the script.
https://gist.github.com/Cazra/8059943
January 22 (11 years ago)
Definitely an interesting script, and one I'm curious to see in action. My one question is; Say I have a pit trap that only activates when moving from one "trapped" square to another within it's 2x2 area? I can probably come up with a dozen other trap problems a script might be hard-pressed to overcome, but that seems to be the easiest.
January 22 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
On its own, this script handles traps that activate when a character steps into their square. Special cases like that are beyond the scope of this script.
February 07 (11 years ago)
Konrad J.
Pro
API Scripter
This is awesome, I haven't been here for awhile and just getting back into scripts. I was wanting to make this myself, but decided to check and see if anyone else did. :)

A Suggestion, I checked and I don't think the script does this.

When the token is moved back to the trap, instead of making lastmove = "" make it equal to all the moves up to the trap. That way the player knows how much movement they have left, where they moved from, etc.

Other than that I can't think of anything else to add, its just perfect.
February 07 (11 years ago)
Konrad J.
Pro
API Scripter
Stephen a request if you have the time since you seem to have all the math down. If not I'll work on it.

Could you write up a function that when passed the lastmoved property of a token if returns the distance moved based on the page's Grid and Diagonal's settings?

Someone might have already done this, I better go look.

Thanks!
March 28 (11 years ago)
I get an error 'Unexpected token var' when attempting to save the script. Any suggestions? I tried to put it in code academy and test it but I am new at javascript. Thanks in advance!
April 04 (11 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
No idea. Did the error give you a line number?
April 09 (11 years ago)
I am getting the same error but only when i am using !reveal command. If i turn one off the other works.