Rather simple question regarding macros

If you have searched the other User Creations subforums and an answer to your question has not been found, please post here!

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
IssLance
Kobold
Posts: 12
Joined: Sat Jan 16, 2016 1:04 pm

Rather simple question regarding macros

Post by IssLance »

So I'm trying to create Beholder from D&D 5E in maptool. I want to make macro which rolls 1d10 and according to it's result, it shows only one proper effect, something like that:

[roll 1d10]

[if 1:
-effect1

if 2:
-effect2

(...)
if 10
-effect 10
]

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rather simple question regarding macros

Post by aliasmask »

Also,

Code: Select all

[H: effects = json.append("",
   "effect 1",
   "effect 2"
)]
[H: effect = json.get(json.shuffle(effects),0)]
<!-- or -->
[H: effect = json.get(effects,roll(1,json.length(effects))-1)]

IssLance
Kobold
Posts: 12
Joined: Sat Jan 16, 2016 1:04 pm

Re: Rather simple question regarding macros

Post by IssLance »

@Edit:
Okay, I got it, thank you :)

How do I include dice rolls in effects if they are plain text due to quotas signs?

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rather simple question regarding macros

Post by aliasmask »

Like this?

Code: Select all

[H: die = "1d20"]
[H: result = eval(die)]

IssLance
Kobold
Posts: 12
Joined: Sat Jan 16, 2016 1:04 pm

Re: Rather simple question regarding macros

Post by IssLance »

Code: Select all

[H: effects = json.append("",
   "Desintegrating Ray: Target has to succeed on DC 16 Dexterity saving throw or receive [1d20] damage",
   "Effect 2",
   "Effect 3"
)]
[effect = json.get(effects,roll(1,json.length(effects))-1)]

[H: die = "1d20"]
[H: result = eval(die)]
Code is obviously wrong but could you point me what should I do with it to make it roll dice?

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rather simple question regarding macros

Post by aliasmask »

Code: Select all

[H: effects = json.append("",
   "Desintegrating Ray: Target has to succeed on DC 16 Dexterity saving throw or receive [1d20] damage",
   "Effect 2",
   "Effect 3"
)]
[H: effect = json.get(effects,roll(1,json.length(effects))-1)]
[R: evalMacro(effect)]

IssLance
Kobold
Posts: 12
Joined: Sat Jan 16, 2016 1:04 pm

Re: Rather simple question regarding macros

Post by IssLance »

I get error message

Code: Select all

Error in body of roll.
Statement options (if any): R
Statement Body : evalMacro(effect)

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rather simple question regarding macros

Post by aliasmask »

Did you copy/paste code? I did and it works in 1.4.
Chris: Effect 2
Chris: Desintegrating Ray: Target has to succeed on DC 16 Dexterity saving throw or receive 6 damage
Chris: Effect 3

IssLance
Kobold
Posts: 12
Joined: Sat Jan 16, 2016 1:04 pm

Re: Rather simple question regarding macros

Post by IssLance »

Yes I did. The token which uses the macro is marked as npc and I'm using impersonate option too. Also using 1.4

http://imgur.com/zfKTzwC

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Rather simple question regarding macros

Post by wolph42 »

weird, I just copy pasted the code in mt1.9 and it works like a charm.
edit: its a permission thing. Turn off: allow players to edit token(in the 2nd tab of the macro editor)

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rather simple question regarding macros

Post by aliasmask »

Ah, evalMacro is a Trusted Macro and has to have certain things set up. It has to be on a lib:token or be a campaign macro with player editing turned off in options.

IssLance
Kobold
Posts: 12
Joined: Sat Jan 16, 2016 1:04 pm

Re: Rather simple question regarding macros

Post by IssLance »

Works like charm. I love you guys <3

@Edit:
NVM, it really works!

Can I donate to maptool somehow? Or for your projects

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Rather simple question regarding macros

Post by wolph42 »

IssLance wrote:Can I donate to maptool somehow? Or for your projects
nah we all dot it for free...its a female-canine-in-heat!

User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rather simple question regarding macros

Post by aliasmask »

IssLance wrote:Works like charm. I love you guys <3

@Edit:
NVM, it really works!

Can I donate to maptool somehow? Or for your projects
Sure. Write some great code and share it with the community.

paulstrait
Dragon
Posts: 304
Joined: Mon Mar 23, 2009 4:48 pm

Re: Rather simple question regarding macros

Post by paulstrait »

Another way to deal with this kind of issue is to use tables. Probably not the best way to go for something that is just relevant to a single token, but can be really useful for something like 5e madness. The way I do short-term madness in my 5e framework, for example, is with this simple macro:
<b>Short-Term Madness</b><br>
<b>Duration:</b> [1d10] minutes.<br>
<b>Effect:</b> [table("Short-Term Madness")]
That calls the Short-Term Madness table, which I set to roll a d100, and input the information on page 259 of the DMG. You can do html markup stuff like bolding, but you can't include bracketed dice roll commands (though if you wanted to get really needlessly complicated you could just create a separate result for every possible outcome e.g., if something did d10 damage, you could create ten entries for it, each with a different damage value, since the table involves a roll in the first place and you can make the values whatever you want to create whatever kind of probability distribution you are looking for -- but as I said, there would be no practical reason to do it this way).


There is one other way to do the kind of think you are doing. Instead of
[if 1:
-effect1

if 2:
-effect2

(...)
if 10
-effect 10
]
you could do it like this:
[h:roll=d10]

[if(roll == 1),CODE:
{
-effect 1
};{}]

[if(roll == 2),CODE:
{
-effect 2
};{}]

etc.
The advantage of doing it this way, with the CODE: and braces is that you can include bracketed commands like [d10] or [3d8] or whatever. You can even nest another if branch inside (although I think it will break down if you try to nest more than 1). (There might be some sort of computer sciencey reason why doing it this way is less preferred than a single json command that includes all the outcomes, but this is generally how I code these kinds of situations and I haven't had any problems).

Post Reply

Return to “Requests for HELLLLP!”