ff_c_act_dice

Roll a die and store the result in a local int on the dialog owner.

Meant for a dummy first line of a one-liner conversation: the roll is made when the line’s condition is evaluated, and the script always returns FALSE so the line is skipped. The following lines can then test the result with ff_c_cnd_var.

Scripts

TextAppearsWhen: ff_c_act_dice

Parameters

VARIABLE: (string) Name of the local int that receives the roll, from 1 to SIDES. Required. The variable is deleted before the roll.

SIDES: (int) Number of sides of the die. Required, at least 1.

Source code

// @code

#include "ff_i_core"

const string VARIABLE = "VARIABLE";

// =============================================================================

int StartingConditional()
{
  string sVariable = GetScriptParam(VARIABLE);
  if (sVariable == "")
  {
    LogError(__FILE__ + ": called with invalid 'VARIABLE' value");
    return FALSE;
  }

  DeleteLocalInt(OBJECT_SELF, sVariable);

  int nSides = StringToInt(GetScriptParam("SIDES"));
  if (nSides < 1)
  {
    LogError(__FILE__ + ": called with invalid 'SIDES' value");
    return FALSE;
  }

  SetLocalInt(OBJECT_SELF, sVariable, Random(nSides) + 1);
  return FALSE;
}