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] 4e combat engine

December 27 (11 years ago)
This is my first major api script so it is sorta buggy and the code is a mess, but it is something I feel others will find useful
This script handles 4e combat from buffs to attack rolls to damage, an example macro from one of my characters

/me takes an opportunity attack at @{target|token_name}
!attack @{target|token_id} @{selected|token_id} AC 1d12 @{tohit} @{damage} 12 0 (optionalname) (optionalhalfmiss)

The !attack calls the api then it gets sent the id of the target and selected tokens, then damage type (ac fort reflex will), damage dice, the to hit bonus, the damage bonus, the 12 is the damage it does on a crit, and the 0 is the tohit bonus for certain attacks that get an extra bonus to hit, optional after that is name of attack in case like in the example below you have certain attacks that you want to do special things on hit like say mark a creature and optional "halfmiss" which will make the attack do half on a miss.

There is a bunch of campaign specific stuff in there talking about my characters buffs/hunters quarry but I left it in so people can see how to modify it to their needs stuff like checking to see if a target is marked or if you have combat advantage helps speed up my combat as they have to worry less about the numbers and more about tactics. The roll formatting needs some work but it is readable. This will not handle AOEs I have a second script for that I will upload shortly that works to gather aoe targets then feed them into this one.

https://gist.github.com/stephenhudson/8144136
December 27 (11 years ago)

Edited December 27 (11 years ago)

Uploading a picture of what the macro looks like after it is run. Everything is calculated on the fly based on the enemy stats/markers and it subtracts the HP from the target as it should as long as the enemy hp is bar1.
January 06 (11 years ago)

Edited January 06 (11 years ago)
How do you set up the tokens and such to make this work? I'm new to API and want to have something similar for my campaign. I'm just unsure on how to have my players target the tokens for an attack and all and how monster stats are stored. It looks great from the get go though and I'll try to figure it out myself but help is appreciated.

Edit: I finally thought I got it working but I was unable to get it working and it keeps spouting the error: "You attempted to use a roll command looking for the value of a selected token, but no tokens are selected." When I try using a macro.

2nd Edit: How do you handle extra crit damage with weapons too?
January 06 (11 years ago)

Calhanol said:

How do you set up the tokens and such to make this work? I'm new to API and want to have something similar for my campaign. I'm just unsure on how to have my players target the tokens for an attack and all and how monster stats are stored. It looks great from the get go though and I'll try to figure it out myself but help is appreciated.

Edit: I finally thought I got it working but I was unable to get it working and it keeps spouting the error: "You attempted to use a roll command looking for the value of a selected token, but no tokens are selected." When I try using a macro.

2nd Edit: How do you handle extra crit damage with weapons too?

I suggest getting the latest version from the Gist link it is massively updated over the one shown can't get it to update on the forums here. You have to set the tokens up as a token actionI'm attaching a picture of one of my characters with the attibutes/abilities, mainly everyone needs to have a HP/Ac/Fort/Reflex/Will then you can either give them a tohit and damage stat to feed the macro or just type in numbers like I do for my monsters.

I just have them roll extra crit effects on weapons seperatly I was looking into adding that in but they all have different weapons and are always changing them, there is a crit section it wouldn't be too hard to add that in though.


,
January 08 (11 years ago)
Thank you. I appreciate the help here, it's just what I needed to know and will help greatly in my campaign and speed things up in terms of tracking and attacks.
January 08 (11 years ago)
Alex L.
Pro
Sheet Author
Just so you know if you have the id of an object getObj is far faster than findObjs you should use it for getting your "targetenemytoken" and things like that. I would also recommend using apicmd to handle you chat parsing is extremely well made and very powerful.
January 08 (11 years ago)
Thanks I've been meaning to switch over, I originally was using find because I was searching for parts of the name before I realized a macro can pass along token id's the early drafts of this were very rough.
January 09 (11 years ago)
just updated this on Gisthub, fixed a bunch of the random code that wasn't doing anything anymore and changes some finds to gets,
I also added the ability to handle damage resistance if you give a character the "resnormal" attribute they will resist any number of that untyped damage, it also works for resfire, resthunder etc.

Example macro
!attack @{target|token_id} @{selected|token_id} Fort 1d10 @{tohit} @{damage} 10 0 flare nomiss fire

adding that fire to the end marks it as fire damage and if you attack a monster that has resfire attribute of 5 you will get this


The output is still kinda janky once I get all the underlying stuff working how I want I will work on prettying it up some.
January 09 (11 years ago)
I have to say, I really love the idea of this script. It would take a feat to implement it in my own campaigns, mainly because I am still working on understanding how to set up character sheets and such.

That aside, thank you for all the work you put into this.

I'm curious though, how would a player select another token? Would I have to give them control over said token?
January 10 (11 years ago)
You have to make the macro and set the macro as a token action, by checking the box, that will then default "selected" to be the token that is performing the macro below is one of my monsters

Once that is checked whenever a person clicks on that character that can control it (pcs for the players or monsters for the GM) they will have a button to press in the upper left as you can see below

They click the button and the macro will ask them to pick a target, they do not have to control the target as it will typically be a monster of some sort but since rugged reroll we are allowed to target non-controlled tokens with macros

Once they click the target it will do the attack and push the output to the chat window

January 10 (11 years ago)
well, that explains a lot. Thank you very much for that breakdown, I've been trying to figure that out for about 2 weeks now.
January 11 (11 years ago)

Edited January 11 (11 years ago)
I'm looking forward to seeing the AoE side of this script once it's added but for now this is brilliant and I've figured out how it works and I'll get my players able to learn how to make these macros in the future. Thanks for the awesome script again and I find it cleaver how you've checked the marks and such.
January 11 (11 years ago)

Edited January 11 (11 years ago)
This is the AOE script I am using now, it is awful and uses some borrowed code from Brandon's Marking script to gather distance based targets but it does technically work it is just very much a buggy alpha attempt. I need to roll it into the main attack script but it will require some major doing. Also since sendChat can't seem to pick up API calls anymore you have to make a character called "aoewhisper" and the script will whisper commands to the character to execute it.
This is an example macro I use
!aoe !distance=<1 na na Reflex 2d8 7 5 12 0
Same arguements as an !attack but you can put the !distance in there to determine the targets you can do like <1 for greater then or less then 1 square, it can also do controlledby and based on hp the various targeting methods are commented in there. It has some weird weird issues with tokens that are larger then one square and the source of the attack will always be the character doing the macro so they will need to move over to the origin square temporarily for ranged spells. I wouldn't honestly recommend using this too much but here it is in case someone can see a better way to implement it.



Also go to github to get it the one linked here is the first version which literally doesn't work at all.

https://gist.github.com/stephenhudson/8118636
January 11 (11 years ago)

Edited January 11 (11 years ago)
I'm having a weird bug now since I tried making the mobs on a different map and all I keep getting a scriipt error
TypeError: Cannot call method 'get' of undefined at evalmachine.<anonymous>:233:36 at eval (
What have I done to cause this?

Edit: Nevermind I figured it out.

Anyway thanks for the AoE Script, I'll have a look at it. Since one of my playes is AoE heavy it'll help a lot.
January 11 (11 years ago)
Ah yeah got to move your player tab.
January 12 (11 years ago)

Edited January 12 (11 years ago)
I just get an error saying Target has no Defenses even when iv set up the attributes like you did :<

Nevermind didn't spell Reflex properly >_>
January 12 (11 years ago)

Stephen H. said:

Same arguments as an !attack but you can put the !distance in there to determine the targets you can do like <1 for greater then or less then 1 square, it can also do controlled by and based on hp the various targeting methods are commented in there. It has some weird weird issues with tokens that are larger then one square and the source of the attack will always be the character doing the macro so they will need to move over to the origin square temporarily for ranged spells. I wouldn't honestly recommend using this too much but here it is in case someone can see a better way to implement it.

Here's an idea that I have for that using a method that was implemented in Rumble's 4E framework on maptools. He used a Token called "Burst Center" in it and all the players could move it. When an AoE attack was used it targeted all the tokens on and around the Burst Center token instead, under certain conditions as your AoE script does.

I'm not sure it can be done but it maybe possible seeing how there is an initiative script that moves one token to another token.

It's just an idea to throw out there that could help in making it more user friendly.
January 12 (11 years ago)

Calhanol said:

Stephen H. said:

Same arguments as an !attack but you can put the !distance in there to determine the targets you can do like <1 for greater then or less then 1 square, it can also do controlled by and based on hp the various targeting methods are commented in there. It has some weird weird issues with tokens that are larger then one square and the source of the attack will always be the character doing the macro so they will need to move over to the origin square temporarily for ranged spells. I wouldn't honestly recommend using this too much but here it is in case someone can see a better way to implement it.

Here's an idea that I have for that using a method that was implemented in Rumble's 4E framework on maptools. He used a Token called "Burst Center" in it and all the players could move it. When an AoE attack was used it targeted all the tokens on and around the Burst Center token instead, under certain conditions as your AoE script does.

I'm not sure it can be done but it maybe possible seeing how there is an initiative script that moves one token to another token.

It's just an idea to throw out there that could help in making it more user friendly.

I definitely have wanted to do something like that, the script currently can only calculate space from the selected token, meaning you can make a "targeting token" and just set it to represent a character with the fireball macro and it works. I need to adjust it so it can calculate space based on a target token which is part of the overhaul I have been trying to do, the distance calculations on roll20 are a bit of a mess. Also working on make sure it only rolls damage once per AOE as it is supposed to

Also I just updated the main attack script again, I put in the concept of limited use abilities because my players are always forgetting if they have used their dailies or not. My Bard has a daily called echoes of the guardian here it the macro

!attack @{target|token_id} @{selected|token_id} AC 2d8 @{tohitmelee} @{damage} 16 0 echoes halfmiss normal daily

adding "daily" after the damagetype will make the attack script check to see if the Bard has an attribute called "echoes" goes by whatever attack name in the macro, if he does it will see if it is great then 0 and let them use it then subtract it by 1, then when they hit 0 they will get a message saying they can't do the attack until the next rest.
January 12 (11 years ago)

Edited January 12 (11 years ago)
Great I'll have a look at this daily usage section too. Shame about the AoE thing being a pain, I'll use it once it's more stable.

What do you use for healing and instant damage by way way if you do have those and who's scripts are those?

I've also been messing with the coding myself and have got some of it customized to my player's needs. (Example: Priest Shield Buff giving - 1 attacks to AC based attack against the target). Cutomising it, thanks to your examples, has been easy so far, thank you.

I've also shortened the output message and I feel I could've condense it even more but I'm leaving it as such for now. too. Here's what mines looks like now, what you think?


January 13 (11 years ago)
I like the shortened down format, the chat output does start getting super wordy once all the buffs get in there. I have 2 small scripts for healing and for direct damage

First is the healing, you can do !heal @{selected|token_name} secondwind and a character will second wind, or like
!heal @{target|token_name} Valiant
Valiant is the name of my bard so it does his majestic word heal but it can be easily changed to do whatever. Characters needs to have "surges" and "surgevalue" attributes for this to work and it will subtract a surge from them or return with an message telling them they are out.

https://gist.github.com/stephenhudson/8392771


Second is the direct Damage its rather simple
!damage @{target|token_id} 0 1d8
0 is just static damage, 1d8 is a dice you can set the dice to 0d0 if you don't want to roll anything and just want to do like say 4 damage.


https://gist.github.com/stephenhudson/8392816

January 13 (11 years ago)
Thank you again, this is exactly what I needed for my campaign to work out. Especially the healing stuff will be a great boon.
January 18 (11 years ago)
How's the AoE script coming along if any? I've been looking at it and trying to modifiy it but I've yet to understand the conditions since they just keep saying they're not specified yet.
January 18 (11 years ago)
Two questions for you:

You mentioned that you had updated/modified the original script- is what is posted here the most recent version of it? (also, is the more condensed message version available?)

I see with the direct damage script, it's reliant on bar 1 for the HP bar, but I don't see how the healing script is attributing HP to any of the bars.. would you mind explaining a little for someone who has no scripting knowledge?

Thanks :)
January 18 (11 years ago)
Follow the Gisthub link for the latest revision, the Healing script does not use Bar1 because I mainly use it only for my players not the monsters so I don't worry about bar assignments, and I did HP attribute because I've been modifying it and the main attack script to deal with temp HP.
January 18 (11 years ago)
I've been trying to set up the script and I'm getting this error in the API:

TypeError: Cannot call method 'get' of undefined at Sandbox. (evalmachine.:214:36) at eval (

I've disabled all other scripts to test the 4e combat engine script
January 18 (11 years ago)
That usually happens if you are trying to use tokens that aren't on the active "player" page, I can modify it to stop checking for the players.
January 18 (11 years ago)

Edited January 18 (11 years ago)
Just ran my first session with this script, after customizing it. And my players loved it and did laugh at the fact you could see your damage even though you miss. They took down a huge giant insect with a small group of soldiers and almost all fell to the poison but killed it before any of them could faint/die, thanks to an immediate interrupt lightning teleport move from the Swordmage,

With the amount of passive buffs they have too. Quarry, augment of war, dragonborn fury etc. the status markers for each was a great boon and had better tracking in some regards than maptools. Just need to figure out a good status script maybe for them but this sessoin went very smooth even with me having to select each target manually for AoE with the Acid Breath attack the insect had.

January 18 (11 years ago)

Edited January 18 (11 years ago)
Awesome glad to hear its going well for people, I originally hid the damage on a miss but a few of my players had stuff that effects the roll if it misses like a reroll or a bonus so I put the damage back just in case someone does something.
Yeah 4e has a ton of status effects I actually use https://app.roll20.net/forum/post/248561/script-4e-token-status-reminder#post-249538
this script here it is easy to read and modified it to add in my own status effects so it reminds me what effects each token has then their turn starts also modified it to automatically deal ongoing damage and roll a save for certain effects my version for my campaign is below. I see Honeybadger putting out round tracker scripts I bet people are working on a good way to automatically take off "End of next turn" effects as that would be handy.

https://gist.github.com/stephenhudson/8498305



January 19 (11 years ago)
The Status Script gives me a the error " Unexpected token )" trying to see where exactly that error is right now.
January 19 (11 years ago)
Not sure on that one, I've never had any issue out of and haven't really touched it in months.
January 19 (11 years ago)
Found out the "});" at the bottom was what it wasn't needed, I think you missed the top section or something. But anyway what script or command do you have to increase the ongoing damage stat in that? Or do you just manually enter it?
January 19 (11 years ago)
It just checks for a marker and does whatever damage you put in the script like if you look at the if(current.markers.ongoingthunder) I just have it doing bar1 - 5 and at the top ongoingthunder is defined as

ongoingthunder : current.token.get("status_lightning-helix"),

so at the start of anyones turn if they have the lightning-helix marker on that token it will do 5 damage to them and roll a save, it can be added to do just about anything on any status effect.
January 24 (11 years ago)
Thanks for this, I myself decided since there's so many varying DoT damage on the monster sides that I'd manually check the values, yet have them under one universal marker so I know when to take that DoT damage off. For player Specific Dots, most of the are auto remove and save which eases my pain since they're going to be the most commonly used DoTs used for the game. Apart from a few tweaking issues here and there for my own campaign I can say that this system scripting system, once the back end programming is done in a way that is for your own campaign can be very useful. Making monsters for the system with their moves has been quick and simple (I've made monsters for about 6 encounters with it)

Overall brilliant for my campaigns and I intend ro keep uaing it.