@SG said:
Does anyone have anything basic laying around? Some features I'm looking for to see how they work:
Sort of.
A command to roll different types of dice, 1d4, 1d6 3d8 etc.
As you note below, the die(n,sides) function is what you want.
I've tried farting around with the dice(x, x) command built in, but I get a lot of huh? messages coming back to me, so I think I'm missing something fundamental here.
It's a function, not a command; functions are evaluated within leading buffer context (which you don't need to worry about yet, it won't be on the test). Put it in a command.
For testing, to yourself:
think dice(3,6)
For outputting to a room, perhaps:
@remit %L=<dice> %N rolled 3d6 for [dice(3,6)].
And putting that into a command on an object:
@create dice code object (dco)
&cmd_dice dco=$+dice *d*:@remit %L=<dice> %N rolled %1d%2 for [dice(%1,%2)].
A command to roll those as explody dice. If a 1d4 gets a 4, then add 1d4.
Mush doesn't have while-loop style iteration unless you restructure things into a @trigger
loop. You don't want to do that, generally. Instead, most nwod dice and other explodey types use recursion-- that is, a function that calls itself, but only for exploding values.
Modifiers to the dice. 1d4-2
For arbitrary syntax, this becomes a problem of lexing and parsing the tokens, which is something that mush is fairly bad at. It can be done, but is more complicated than I can type up right now.
For simple syntax matching what you have there, something like:
&cmd_dice dco=$^\+dice ([0-9]+)d([0-9]+)\+?(-?[0-9]+)?$:@remit %L=<+dice> %N rolled %1d%2[if(strlen(%3),if(gte(%3, 1),+,-)%3,)] for [add(dice(%1,%2),%3)].
@set dco/cmd_dice=regexp
Rolling against a stat on a character
You can read attributes with get(dbref/attr) or the like, but stats should usually be hidden and/or read-only. You may need to set up api functions for accessing them in a global function of some sort.
Parsing dice with stats, especially for multiplayer rolls, e.g.
+roll strength+brawl+item(katar) resisted by PLAYERNAME:defense
And then showing the results but not the number of dice rolled, etc, is... tricky.
Note: just typed this up. Code above not tested, may have stupid typos.
edit: fixing codeblock boundaries in post