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] CorpseCart

May 15 (2 years ago)

Edited July 15 (2 years ago)
EE
Pro

I've always liked keeping defeated enemy tokens around on the map for players to get a sense of change and achievement in a battle. But it can be a bit annoying having tokens move on top of bodies, having issues clicking, or not knowing which is dead. Unfortunately, I have no backend coding background but there are some real good tutorials and examples in this community and I had some time to burn post-exam.

CorpseCart

(click to play gif)

CorpseCart is a simple script that does 2.5 things. You can either tell it to:

  • move all dead NPCs to the map (and tint them)
  • remove all dead NPCs entirely

You can also ask it to flag all NPCs with HP of 0 or lower to be tagged with the "dead" status marker (for other reasons or so that the two options above can detect them).

It's designed to only work on tokens that represent a character but that players don't have control of (so they don't get their bleeding out characters buried).


Automatic

By default corpse cart will automatically bury corpses that are marked as dead and at or below 0 health, to change this simply change the line "const autoBury = true;" at the top of the script to false.

Note that this does not allow corpse cart to bury tokens killed by other scripts bring them to 0hp. Roll20 prevents one script detecting a change made by another script.

Hint: You may undo the burial of a token (or tokens) by clicking the message in chat!


Command structure

!corpsecart [command] [tag - optional]

The commands are:

  • del/delete/remove/rem: this removes dead NPCs from the map
  • map/bury/dig: this places dead NPCs on the map layer and tints them
  • tag/look/find/search/flag: this looks for NPCs that are at 0 or lower health but who haven't been marked dead and marks them as such
Example: "!corpsecart del" deletes dead NPCs on the map you are on.

You can also include tag and its aliases as an extra parameter so that it will tag and then remove or bury NPCs in the same command.

Example: "!corpsecart map tag" tags untagged dead NPCs and then places all dead NPCs on the map later.

I apologise for the state of the code. I literally have almost no idea what I am doing, when I did webdev I never touched the backend (and I ain't done that in a decade). Critique appreciated!

Code link.


Version History

v0.01 - Workable release

v0.02 - Tag and del now working on map layer (bugs introduced in release version)

v0.03 - Added undo functionality, prettier chat messages, and automatic burying.

May 15 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Novel idea, and automates a common procedure. Great first script!

May 16 (2 years ago)
EE
Pro


keithcurtis said:

Novel idea, and automates a common procedure. Great first script!

Thanks, I greatly appreciate that!



May 16 (2 years ago)
Ziechael
Forum Champion
Sheet Author
API Scripter

Having just run an encounter in tight confines where the corpses were piling up and sitting on top of active/alive tokens I can see the real benefits of this script.

Definitely gonna give it a go, will feed back any issues :)

What an excellent idea. I have adopted your script. Thanks 

May 20 (2 years ago)
EE
Pro

Thank you! Let me know how it goes.

June 24 (2 years ago)
Nick O.
Forum Champion

This script looks really cool, but I can't seem to get it to work. I have several zombie tokens on the Objects layer that have 0 hp, but when I run !corpsecart map tag I get a "No corpses found to cart" message. Are there any prerequisites or other setup steps that need to be followed?


Nick O. said:

This script looks really cool, but I can't seem to get it to work. I have several zombie tokens on the Objects layer that have 0 hp, but when I run !corpsecart map tag I get a "No corpses found to cart" message. Are there any prerequisites or other setup steps that need to be followed?

I noticed that when my NPCs didn't have the big red dead "X" that the script gave me the same error message. When I use the red X it works as intended. At least, that's my experience with the script. 


June 24 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter


Nick O. said:

This script looks really cool, but I can't seem to get it to work. I have several zombie tokens on the Objects layer that have 0 hp, but when I run !corpsecart map tag I get a "No corpses found to cart" message. Are there any prerequisites or other setup steps that need to be followed?


Are you using bar1 for HP? It looks like a constant.

June 24 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

This seems to work. It tags and then buries them:

!corpsecart map tag


June 24 (2 years ago)
Nick O.
Forum Champion


keithcurtis said:


Are you using bar1 for HP? It looks like a constant.

Yep, I am using bar 1 for HP. Doing some debugging, this line

var mapID = player.get("_lastpage");

is returning "" and I think that might be where the problem is. Does anyone know how "_lastpage" gets set?


June 25 (2 years ago)

Edited June 25 (2 years ago)
Nick O.
Forum Champion

I was able to solve this by making the following change:

//var mapID = player.get("_lastpage");
var mapID = Campaign().get("playerpageid");

This tells the script to search whatever page the player ribbon is on. Once I made that change the script was able to find tokens that had 0 hp or less, mark them as dead, and move them to the map layer. This is a handy script, thanks for making it, EE!

July 04 (2 years ago)

Edited July 04 (2 years ago)
Styx
Pro


Nick O. said:

This script looks really cool, but I can't seem to get it to work. I have several zombie tokens on the Objects layer that have 0 hp, but when I run !corpsecart map tag I get a "No corpses found to cart" message. Are there any prerequisites or other setup steps that need to be followed?


I'm getting the same message

Nick O. said:

I was able to solve this by making the following change:

//var mapID = player.get("_lastpage");
var mapID = Campaign().get("playerpageid");

This tells the script to search whatever page the player ribbon is on. Once I made that change the script was able to find tokens that had 0 hp or less, mark them as dead, and move them to the map layer. This is a handy script, thanks for making it, EE!

I also made this edit, but still getting the same "No corpses found to cart".

I'd already moved these tokens out of the way (still on token layer), and I also use Bar 1 for HP, though as I also use MonsterHitDice I don't usually have the monster tokens set with hp as the attribute. Not sure if that made a difference, so I set one and it didn't work.

Might have to just wait and watch your anticipated video on this, Nick!

EDIT: Actually, I realised I hadn't moved the Player Ribbon to this map first and it then worked!




just an idea - not sure if it's something people would want. 

But perhaps the ability of - if moving the corpse to a designated spot, then they should have the ability to move it back to it's original point.
Only reason i can think of this is - when combat is over, the players can see the massacre they have committed on the map, and to RP/Loot specific named NPCs/boss(es).

July 04 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter


Nover C. said:

just an idea - not sure if it's something people would want. 

But perhaps the ability of - if moving the corpse to a designated spot, then they should have the ability to move it back to it's original point.
Only reason i can think of this is - when combat is over, the players can see the massacre they have committed on the map, and to RP/Loot specific named NPCs/boss(es).


That would be a good feature. Another use case would be correcting an error. "Hey DM, my sword is only +1 vs undead. That goblin should still be alive."

July 05 (2 years ago)

Is there a way to make this also move tokens with less than zero HP?  I only ask because I was testing SmartAOE and had this script also installed, and SmartAOE overkilled the creatures (brought HGP below zero to negative numbers).

July 08 (2 years ago)
Nick O.
Forum Champion


Styx said:


Might have to just wait and watch your anticipated video on this, Nick!



Here you go! https://youtu.be/GY7ayJje_zs :)

July 09 (2 years ago)

Edited July 09 (2 years ago)
Joe
Pro

This seems like a great script, thank you for the work on it!  Maybe someday it could listen for the dead marker being applied and auto-run, but I imagine that is a much more complicated scenario than the user-triggered way it works now.  :-)


In case it is helpful to anyone, when I made the change to the mapID line suggested by Nick O., I got an immediate "invalid or missing token" (might be paraphrasing) error that disabled my scripts.  However, running the 0.02 code as-is seems to be working so far. *shrug*


P.S.  Found via Nick's YouTube video - thanks for making those! :-)

July 15 (2 years ago)
EE
Pro

Sorry for the late replies, completely missed this somehow!

Nick O. said:

I was able to solve this by making the following change:

//var mapID = player.get("_lastpage");
var mapID = Campaign().get("playerpageid");

...This is a handy script, thanks for making it, EE!

Derp, yup I've update this. This is a much better flag and no idea why I used the other method prior.

Also thanks for the shout Nick, really appreciate your videos - used them for a couple of jumpstarts to understand the platform. MacroMover has been a lifesaver.

Styx said:

EDIT: Actually, I realised I hadn't moved the Player Ribbon to this map first and it then worked!

That's a lot of bodies! Glad you're finding it useful!

Novercalis said:

just an idea... moving the corpse to a designated spot, then they should have the ability to move it back to it's original point.

Mmm, this might work. But it would be a little more annoying as since its technically token based I'd have to find a simple way to store to the old location - plus getting the location to move things to is a bit of a pain as you can't get click or cursor locations. It'd have to be next to a selected token, and then place all corpses in a way that doesn't overlay other tokens? You'd have to detect tokens and then write the layout pattern... suffice to say that probably more than I can be bother with for now. Perhaps when I have a utility that does something similar that I can repurpose for this later on...

keithcurtis said:

That would be a good feature. Another use case would be correcting an error. "Hey DM, my sword is only +1 vs undead. That goblin should still be alive."

Undo burial (but not deletion) now implemented! Chat messages can be clicked (which sends a "!corpsecart undo [id(s)]" message) to reverse the burial. This includes reversing automatic burials. Doesn't removed the dead status just in case that's meant to be there.


Darryn said:

Is there a way to make this also move tokens with less than zero HP?  I only ask because I was testing SmartAOE and had this script also installed, and SmartAOE overkilled the creatures (brought HGP below zero to negative numbers).

Made it so the script automatically buries creatures now. However scripts can't detect changes made by others scripts - its a deliberate Roll20 things designed to avoid scripts firing in an infinite loop. If SmartAoE has a hook or something I can use to integrate with then I could. But at the moment you'd have to manually fire it after scripts that change health values. Note: If anyone knows if SmartAoE has such a hook and what it is lemme know!

Nick O. said:

Here you go! https://youtu.be/GY7ayJje_zs :)

:D

Joe said:

This seems like a great script, thank you for the work on it!  Maybe someday it could listen for the dead marker being applied and auto-run, but I imagine that is a much more complicated scenario than the user-triggered way it works now.  :-)

In case it is helpful to anyone, when I made the change to the mapID line suggested by Nick O., I got an immediate "invalid or missing token" (might be paraphrasing) error that disabled my scripts.  However, running the 0.02 code as-is seems to be working so far. *shrug*

It now auto-applies for the marker if the health is 0 or lower. I have switched the code to the player tab like Nick mentioned, if this causes issues with the 0.03 v lemme know! And thanks!

August 22 (2 years ago)

Edited August 22 (2 years ago)

I'm running into an issue where the script is not applying the red x when it automatically sends the corpse to the map layer. I know this can be solved by including a macro to search for the corpses but I was hoping to look into the code and see if I could find and fix the issue but I am not really familiar with roll20 or js.

I thought the issue could've been on line 64 because it is not setting the status marker. I also couldn't find another area where it set the status marker, only places where it looked for it. 

obj.set({layer:"map",tint_color:"000000"});

Whenever I tried to fix it, I just ended up breaking it lol so I just thought I would mention it and see if anyone else ran into this issue!

Update: I added the following line to the beginning of the if statement so it now looks like this:

if(npc){
    obj.set(corpseMarker,true);
    log(`Burying away: ${obj.get("name")}`);
    obj.set({layer:"map",tint_color:"000000"});
    let ids = [obj.id];
    let msgContents = msgConstructor(`Buried ${obj.get("name")}.`,`down`,ids);
    chatter(msgContents,`w`,`gm`,`noarchive`);
		}

for some reason, it not it did not like it when i tried to add it to the other obj.set as an additional flag so i just tried it in its own line and it worked!

September 05 (2 years ago)

Hey, I was just wondering if there was a way to grab other non corpses and bury them too?

I wrote a macro to spawn an animated blood spatter as I kill a token (unfortunately I still need to manually activate its animation), but and I was looking for a way to bury it with the corpse when carting it all away. Does anyone here know how I'd need to modify the script to bury all instances of a specific token?

I've created a Rollable Table and assigned it to a specific NPC character sheet, I just don't want to put an X over it to mark it as dead as the X would ruin the effect (the blood pool is a larger token than the corpse token).

September 08 (2 years ago)

Edited September 08 (2 years ago)

Hello! Just got the pro version of Roll20, and have started messing around with scripts.

I'm running into an issue with your script, which I originally found through one of Nick O's videos. In his video, the bars are removed when the token is sent to the map layer, but when I do the same thing, the bar remains - which is kinda annoying when dealing with large groups of dead monsters.

Any clue why that happens?

Thanks in advance,
- Jakob

(Screenshot attached for proof. Left ogre is alive and well, goblin and right ogre are dead and have been moved with CorpseCart API)

Edit: I use bar 3 for hit points, and have adjusted line 12 to look for "bar3_value" instead of "bar1_value".

September 08 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Hi Jakob!

This is not an issue on your end. This is a bug that came to be with the latest token bar update, and is being worked on.

September 09 (2 years ago)

keithcurtis said:

Hi Jakob!

This is not an issue on your end. This is a bug that came to be with the latest token bar update, and is being worked on.

Thanks for the quick reply :D I'm sure I'll manage to live with it until the fix goes live :)

September 10 (2 years ago)
David M.
Pro
API Scripter

EE said:

Made it so the script automatically buries creatures now. However scripts can't detect changes made by others scripts - its a deliberate Roll20 things designed to avoid scripts firing in an infinite loop. If SmartAoE has a hook or something I can use to integrate with then I could. But at the moment you'd have to manually fire it after scripts that change health values. Note: If anyone knows if SmartAoE has such a hook and what it is lemme know!

Just ran across this thread (only a month after you asked haha). You can register SmartAoE to your script as explained in this wiki section. Hope that helps!



Having an issue with CorpseCart not burying tokens that are clearly marked dead. I have tried manually setting a token to 0 hp/dead and through other automated scripts. When issuing the command: !corpsecart bury get the message "no corpses found to cart". Any thoughts? Confirmed I have the updated script with the page issue resolved.