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

Auto blood splatter!

I'm trying to write a script that will splatter blood any time a token's hp is reduced. Here's my script so far. It seems  to work, but I'm not seeing the splatter effect. I tried zooming out to see if maybe it was just in a weird location, but as far as I can tell it's not firing at all. I'm also not getting any errors or logs regarding the call. var hpValues = {}; on("change:token", function(obj) { var tokenHp = hpValues[obj.get("id")]; var currentHp = parseInt(obj.get("bar1_value")); if (tokenHp == null){ hpValues[obj.get("id")] = currentHp; } if (tokenHp > currentHp){ sendChat(obj.get("name"), "/em took " + (tokenHp - currentHp).toString() + " damage!") // Right here... I get the above message, then nothin... spawnFx(obj.get("left"), obj.get("top"), "splatter-blood"); } hpValues[obj.get("id")] = currentHp; }); on("add:token", function(obj){ var hpString = obj.get("bar1_value"); if (hpString != null && obj.get("layer") == "objects"){ hpValues[obj.get("id")] = parseInt(hpString); log("Added " + obj.get("name") + " to hp table"); } })
1462402171

Edited 1462402211
Ada L.
Marketplace Creator
Sheet Author
API Scripter
The splatter-X effects require a second point to determine which direction to splatter the particles. Also, for these effects, you'll need to use spawnFxBetweenPoints instead of spawnFx. See: <a href="https://wiki.roll20.net/API:Utility_Functions#Special_Effects_.28FX.29" rel="nofollow">https://wiki.roll20.net/API:Utility_Functions#Special_Effects_.28FX.29</a>
1462402420

Edited 1462402468
There is a script in the API repository called&nbsp; Blood and Honor that does just that but not with the FX engine.
Stephen L. said: The splatter-X effects require a second point to determine which direction to splatter the particles. Also, for these effects, you'll need to use spawnFxBetweenPoints instead of spawnFx. See: <a href="https://wiki.roll20.net/API:Utility_Functions#Special_Effects_.28FX.29" rel="nofollow">https://wiki.roll20.net/API:Utility_Functions#Special_Effects_.28FX.29</a> If you just type /fx splatter-blood blah blah with just one target it works fine. It defaults to a rotation of 0. I just assumed it would work the same from the code. I'll give the other one a try.&nbsp;
Stephen L. said: The splatter-X effects require a second point to determine which direction to splatter the particles. Also, for these effects, you'll need to use spawnFxBetweenPoints instead of spawnFx. See: <a href="https://wiki.roll20.net/API:Utility_Functions#Special_Effects_.28FX.29" rel="nofollow">https://wiki.roll20.net/API:Utility_Functions#Special_Effects_.28FX.29</a> That didn't make any difference. The code is still completing successfully with no visible effect. Is there a way to check which layer the effect is being rendered on? Maybe it's working but it's just under the map tiles?
Ok I deleted all objects between the token and the background and I'm still not seeing the effect. I also divided the left and top properties by 70 and counted the squares to make sure it's in the correct spot; it is. I've tried doing spawnFx, spawnFxBetweenPoints, and sendChat("/fx....") &lt;-- puts it into the text box and I have to press enter, but then it works (without needing to click targets, btw). Is this a bug at this point? I'm still getting zero errors in the console. I've even intentionally invoked errors just to eliminate the variable in my debugging. Logging works. :P What do I dooooooo!? &nbsp;Bllaarrghh!
1462427546
Lithl
Pro
Sheet Author
API Scripter
According to Riley , the third argument to spawnFx needs to be the id &nbsp;of the effect object, not the short name of the object.
1462429451

Edited 1462429468
In one in my scripts, i used : spawnFxBetweenPoints({x: obj.get('left'), y: obj.get('top')}, {x: 400, y: 400}, "splatter-blood"); And it worked like &nbsp;charm. Hope it helps
Thanks everyone for your help! I really really appreciate it. I realized that I'm an idiot. I was calling spawnFxBetweenPoints({obj.get("left"): obj.get("top")}.... And I'm sure you already see the problem. It was firing the entire time, just in really bizarre locations. Thanks again everyone!
1462452219
The Aaron
Pro
API Scripter
Brian said: According to Riley , the third argument to spawnFx needs to be the id &nbsp;of the effect object, not the short name of the object. ... for custom effects.
1462459576

Edited 1462461740
Ada L.
Marketplace Creator
Sheet Author
API Scripter
It looks like the documentation for the FX API in the wiki needs some updating. Some of the built-in effects names&nbsp;are even entirely wrong in the current documentation. Edit: The wiki documentation has been updated.