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 .
×
Advertisement Create a free account

PvP Dynamic Light Stealth Script

1551274427

Edited 1551274777
Kick
Pro
Hey Roll20! I've been around for a while but it's only recently that I've started looking into the API. I've been working on an Xcom-like game within Roll20 for years, and it's become a fun, special pasttime for me and some of my friends to test out units and mechanics in it. Stealth has been giving me trouble though, and I think I may need an API script to do what I'm trying to do. I was wondering if something meeting the following prerequisites exists, or whether I should start learning how to code something like this myself? The idea is simple enough in and of itself. In this game, some units have access to stealth abilities and some do not. (Ideally I would want to use the dynamic lighting feature for its sheer atmosphere value for this, but I am open to other suggestions as well.) Units without stealth are visible to all players even in the fog of war, while units that have access to stealth can use the fog of war to hide from the opponent player while still being fully visible to the controlling player. Currently the way I'm doing this is incredibly roundabout and breaks easily; I'm using a transparent .png graphic with a 0.2 meter light radius that has sight and light sharing, placing it over each non-stealth unit, and grouping them together. This essentially creates a "ghost double" that follows the unit around and shines a tiny light on it that makes the unit visible to the opponent, without showing the opponent that unit's own sight radius such as when I'd check "all players see light". Obviously the grouping can easily be broken by accidentally dragging without selecting first, and this is extremely tedious to set up, so I'm looking into alternatives Is there an API that can help me with this? For that matter, is it possible to do with the API at all? Because I'm willing to pick up Java and learn what I need to do this if it can be done. (Also quick shoutout to TheAaron! You get enough praise on this forum already, but damn if you don't deserve it. TokenMod lets me change unit type ownership with the press of a macro button for entire groups, which is one less hurdle for what I'm trying to do.)
1551284949
Ammo
Pro
I have not seen that done before (which doesn't mean it does not exist.)   But I think what you would build is exactly what you have already done, only automated a bit by API script (which by the way is JavaScript, so you don't need to learn Java!) Essentially, you could create your little lamps that float over units' heads automatically using the API.   For the API, it is trivial to be notified that tokens (graphics of your units) exist and that they were moved.   So when a token (a unit in this case) is added, you can check in the API script whether it has your stealth attribute in the 'related' sheet (I assume you have your own sheet for your game and your own character attributes.)   If the unit is non-stealth, then it would create the 'lamp' token (if you don't already have it) and store its ID together with the ID of your unit's token.   This information can be stored in the 'state' of your API script, which is a magic JavaScript dictionary that is persisted to disk, so it survives restarts of your script.  On startup, you can enumerate this state to restore any ghost lamp tokens that still have a unit token and remove any stale info from the state, so it doesn't grow forever. Then you create a handler in your API script that is called whenever a token moves.  Now you can detect if someone moved the unit token (or the lamp token, if you don't manage to stuff those on another layer or otherwise prevent them from being selected) and move the other paired token with the API.   
1551285618
Ammo
Pro
PS: That's pretty much an outline of what you'd write.   Yeah, you also need a handler on token removal to check if you need to remove a lamp, but the gist is there.   Honestly, if I had time to code, this would seem like fun.   So I highly recommend you take this opportunity to learn to write code and do this project before TheAaron gets five minutes of free time and writes it himself because he can't help it :)
1551286828
Ziechael
Forum Champion
Sheet Author
API Scripter
It sounds like something that The Aaron's Torch script could be a good start point for.
1551397339
Kick
Pro
Thank you both for your posts! I've started delving into the Roll20 documentation for getting started on writing scripts for the API, and I've taken a closer look at the Torch script and its functions as well. It's going to take some time and effort, but I think this should be doable. I'll post updates as I go! Thanks again for your help and input, it's reassuring to hear that my ramshackle solution was on the right track.
1551413955
The Aaron
Forum Champion
API Scripter
Look at the latest version of Bump.&nbsp; It has a way for Players to bump their tokens so only they (and the GM) can see where they are.&nbsp;&nbsp; <a href="https://app.roll20.net/forum/post/7079958/script-update-bump-now-with-support-for-players-allowing-your-dastardly-rogue-to-hide-from-his-party-and-your-invisible-warlock-to-surprise-her-companions" rel="nofollow">https://app.roll20.net/forum/post/7079958/script-update-bump-now-with-support-for-players-allowing-your-dastardly-rogue-to-hide-from-his-party-and-your-invisible-warlock-to-surprise-her-companions</a> You might need to explicitly also set the visibility of their light source off using TokenMod, just to be sure there isn't an area of light moving about for the other players. =D
1551414021
The Aaron
Forum Champion
API Scripter
Ammo said: PS: That's pretty much an outline of what you'd write. &nbsp; Yeah, you also need a handler on token removal to check if you need to remove a lamp, but the gist is there. &nbsp; Honestly, if I had time to code, this would seem like fun. &nbsp; So I highly recommend you take this opportunity to learn to write code and do this project before TheAaron gets five minutes of free time and writes it himself because he can't help it :) HAHAHAHAHAHAAHAH... Sorry... did it a few weeks ago... =D
1551883526
Kick
Pro
The Aaron said: Look at the latest version of Bump.&nbsp; It has a way for Players to bump their tokens so only they (and the GM) can see where they are.&nbsp;&nbsp; <a href="https://app.roll20.net/forum/post/7079958/script-update-bump-now-with-support-for-players-allowing-your-dastardly-rogue-to-hide-from-his-party-and-your-invisible-warlock-to-surprise-her-companions" rel="nofollow">https://app.roll20.net/forum/post/7079958/script-update-bump-now-with-support-for-players-allowing-your-dastardly-rogue-to-hide-from-his-party-and-your-invisible-warlock-to-surprise-her-companions</a> You might need to explicitly also set the visibility of their light source off using TokenMod, just to be sure there isn't an area of light moving about for the other players. =D I have looked into this actually! Your Bump script was the obvious go-to, though utilizing it comes with two hurdles in this particular case. The first and most minor issue is that we use status markers and images to quickly analyze what types of units are being fielded and what loadout options they're equipped with, since different copies of the same unit may have been kitted out differently in this game. As far as I'm aware there's no way for the controlling player to see this when a token is bumped, since all they see is the aura. I'm a complete beginner though, so I happily invite anyone to correct me if I'm mistaken. The second problem is that the way I'm trying to get this to function is that invisible units are visible within an opposing unit's light radius. Since players cannot see the light radius of each others' tokens to do this manually via a bump macro, I would need to write something that detects whether a token has been swapped with its' slave token counterpart if it is within the light radius of a token with which it does not share a controlling player, then swap it back if this is true. As someone who is literally just now going through the JS tutorials and has zero prior experience...I haven't the faintest clue how to do that or whether that is even possible. This is all stuff I'm very slowly figuring out as I go. It's a little frustrating since the coding is just a means to an end for me, but I'm hoping I'll be able to use either Bump or a solution involving the little lights (presumably using a similar motion mimickry to Bump's slave tokens) in the near future. Either way, I'm happy for all the support, and thank you for pointing these things out!