ff_i_random

Random and dice roll functions.

Helpers for dice notation (e.g. 2d6+3), weighted random selection, and random element picking from arrays.

int RollDiceFromString(string sRoll = "d6()")
Parameters:
  • sRoll – A mathematical equation that supports d6() syntax.

Return a dice roll from an evaluated string.

Source code

// @code


#include "ff_i_consts"


// -----------------------------------------------------------------------------

//! @brief Return a dice roll from an evaluated string
//! @param sRoll A mathematical equation that supports d6() syntax.
int RollDiceFromString(string sRoll = "d6()");
int RollDiceFromString(string sRoll = "d6()")
{
  object oModule = GetModule();
  if (sRoll == "")
    sRoll = "d6()";

  DeleteLocalInt(oModule, RETVAL);
  string sScript = "SetLocalInt(GetModule(), \"RETVAL\", " +  sRoll + ");";
  ExecuteScriptChunk(sScript, oModule);
  int nAmount = GetLocalInt(oModule, RETVAL);
  DeleteLocalInt(oModule, RETVAL);
  return nAmount;
}