[Script] ChatSetAttr - set character attributes via chat messages

1492386273

Edited 1492386426
I know this is probably asked a lot but how do I round with this? The following is not working (of course): !setattr --allplayers --evaluate --mod --hit_dice|floor(%hit_dice_max%/2) I tried to find the answer my self but couldn't. All help appreciated.
1492389161
Im assuming your building a Long rest macro that adds the players hit dice back based on 1/2 their level? I use this macro !setattr --sel --modb --hit_dice|[[floor(@{selected|level}/2)]]
1492390179
Just so! However, with that system I would have to individually select each character and run the macro, which is what I am trying to avoid. :/
1492390456
If I cannot round without using @selected, could I perhaps set a separate attribute beforehand? eg: !setattr --sel --replace --hit_dice_add|floor(`{selected|level}/2) !setattr --modb --allplayers --hit_dice|%hit_dice_add% However the above example simply results in "nothing to do for character".
1492394281

Edited 1492394392
Well without the selected I dont know how the macro would determine each players level (assuming they were diff levels). I use the one I mentioned as a Token macro for each PC, I also add other stuff based on class. Works great for me. I make it a Token Macro bc then, they are all ready selected :)
1492394478
Try this (after taking the necessary precautions): !setattr --allplayers --evaluate --modb --hit_dice|Math.floor(%hit_dice_max%/2)
1492486887
I am try to get !setattr to work with resource name instead of @{repeating_resource_$0_resource_left} So something like !setattr --name @{selected|character_name} --mod --Potion of Healing|-1 --silent
1492487394

Edited 1492487496
You could do this: Add an Attribute to your Character named Potion of Healing Give that Attribute a Current value of repeating_resource_$0_resource_left (or repeating_resource_ RowID _resource_left) Then, you could use this: !modbattr --silent --name @{character_name} --@{Potion of Healing}|-1
1492643612

Edited 1492643799
Silvyre said: Try this (after taking the necessary precautions): !setattr --allplayers --evaluate --modb --hit_dice|Math.floor(%hit_dice_max%/2) This works perfectly, though I elected to use Math.round() instead of Math.floor() so as to avoid level 1 characters regenerating no Hit Die. Thank you for replying. :)
1497734595

Edited 1497735098
Hello, first i have to say this script is great! It broils my brain while thinking what i can do with it and how :) At the moment, i'm trying to set up a coin loot macro, which automatically rolls the amount of coins and put them on the players sheet (DnD 5OGL). So far i have this for example: !setattr --silent --sel --mod --gp|+[[1d6]] It rolls me 1d6 goldp(whatever the p is for) and kick it right in the selected players face. So far so good. My questions/thoughts to improve this are three points: Can i use a roll-table in there? Like !setattr --silent --sel --mod --gp|+[[table_name]] so that, i can make a loot table and link it directly (edit: found the answer on site 2 of this thread, works great) Is there a way to prompt the result in the chat, so that the players can see it? (use the macro, roll XX and the chat output uses the result: you loot XX gold(penny's?) How can i do this with other loot? I didn't get it to work, that it would put me automatically a short sword, for example, in the players item list after smashing the macro button Thanks and have a nice evening
1497742114
Ziechael
Pro
Sheet Author
pale81 said: It rolls me 1d6 goldp(whatever the p is for) and kick it right in the selected players face. So far so good. Gold Pieces traditionally but go with what works for you ;)
1497759524
Ziechael said: pale81 said: It rolls me 1d6 goldp(whatever the p is for) and kick it right in the selected players face. So far so good. Gold Pieces traditionally but go with what works for you ;) Thank you, sounds obvious. One question resolved : )
1497863167
Jakob
Pro
Sheet Author
API Scripter
pale81 said: Is there a way to prompt the result in the chat, so that the players can see it? (use the macro, roll XX and the chat output uses the result: you loot XX gold(penny's?) So, there's no way for ChatSetAttr itself to output the result to chat, you could however write a listener similar to the one I wrote in  this post to react to your CSA commands and output stuff to chat. How can i do this with other loot? I didn't get it to work, that it would put me automatically a short sword, for example, in the players item list after smashing the macro button Now, this is a bit more complicated, and I don't know how exactly the result of a rollable table with a non-number entry interacts with this this script trying to convert an inline roll to its result. I can offer the following: if you have a repeating section repeating_equipment, and the name of an item in that section is described by the "name" attribute in a given row, the following command will add a short sword to the repeating_equipment section of the selected token/character: !setattr --sel --repeating_equipment_create_name|Short Sword This will add just the name, no stats whatsoever. Look for  this example on page 2 for a command that generates a complete weapon (on the PF sheet, but the general strategy is always the same). This is probably too complicated to work as the result of a rollable table, so while you can make an "add short sword" button, I doubt you can make a "roll random weapon and add it in one go" button without further work. Although I could think of a script that takes a rolled weapon from a table, and creates a matching ChatSetAttr API command button for you to add it to a character.
1497868349

Edited 1497869033
Ziechael
Pro
Sheet Author
I have to admit that this idea intrigued me somewhat so I played a bit... since your players aren't always going to want to use the stuff they loot I would suggest having an area (notes or in my 3.5e hacked version the Stored Items section) where you can build up a list of things collected over time, the players can then distribute or put things into use as needed. They'd still need to add the full info for equipment but players have to do something sometimes right??? The gif below is pretty quick (click to view) but the command is pretty simple (beware, I copy and pasted this and it put a false space before it, if it doesn't work try to delete a space that might not look to be at the beginning lol): !setattr --sel --storeditems|@{selected|storeditems} [[ 1t[loot] ]], I prefix it with the stored item section itself to keep the initial info (since --mod doesn't like NAN fields) and then add the results of a rollable table to it (any number of rolls can be done at once), I then added a ',' at the end so that future additions to the list will retain some kind of order... and now, gif time!
1497883575
Jakob
Pro
Sheet Author
API Scripter
Interesting Ziechael. Just wanted to add that you might want to make it  !setattr --sel --storeditems|%storeditems% [[ 1t[loot] ]], instead such that it works correctly when multiple tokens are selected.
1497884446
Ziechael
Pro
Sheet Author
True, it was more a proof of concept really, I'd also add --silent in there too to avoid chat clutter, although a listener might be handy for outputting the loot to chat for all to see?
1498153395
Thank you again, i have to try this as soon as i can. 
1498663249
Dougansf
Pro
Sheet Author
I recently added GroupInitiative to my game.  I was hoping that a ChatSetAttr macro could help me set up character sheets with the formula needed for initiative.  I figure it would be something like this: !setattr {{ --sel --GroupInitiative|[[ [[{1e3, 8}<[[{@{InitTotal}-@{Wounds} - 11, 0}kh1 % 11]] + floor([[{@{InitTotal}-@{Wounds} - 11, 0}kh1]] / 11)]]d20! + [[{2, 4, 5, 6, 7}=[[{@{InitTotal}-@{Wounds}, 0}kh1 % 11]] + {1, 3}=[[{@{InitTotal}-@{Wounds}, 0}kh1]] + {1e3, 3}=[[{@{InitTotal}-@{Wounds} - 11, 0}kh1 % 11]] * 2]]d[[{{(@{InitTotal}-@{Wounds} - 1) * 2, 4}kh1, {12} }kl1]]! + [[{1e3, 8}<[[{@{InitTotal}-@{Wounds}, 0}kh1]] * (1 - {3, 6, 10}=[[{@{InitTotal}-@{Wounds}, 0}kh1 % 11]] + {1, 4, 8}=[[{@{InitTotal}-@{Wounds}, 0}kh1 % 11]])]]d[[10 - {4, 5, 8, 9}=[[{@{InitTotal}-@{Wounds}, 0}kh1 % 11]] * 4]]! + [[{1e3, 8}<[[{@{InitTotal}-@{Wounds}, 0}kh1]] * ({0, 5, 7, 9}=[[{@{InitTotal}-@{Wounds}, 1}kh1 % 11]] + 2 * {6, 10}=[[{@{InitTotal}-@{Wounds}, 0}kh1 % 11]])]]d8! - [[{1, 2}=[[{@{InitTotal}-@{Wounds}, 0}kh1]] * (3 - [[{@{InitTotal}-@{Wounds}, 0}kh1]])]] ]] }} But it doesn't seem to be working.  I get this error: TypeError: Cannot read property 'substring' of undefined.
1498664956
Jakob
Pro
Sheet Author
API Scripter
Yes, so the problem is that Roll20 wants to evaluate your attributes and inline rolls before they ever arrive for ChatSetAttr to handle them! Solution: add the --replace option, and 1) replace all instances of "[" in your message by "<", and (optionally, I think) "]" by ">" 2) replace all instances of "@" in your message by "`" (backtick). That should do the trick.