09-07-2013, 03:14 AM
HOWL!!!!
Heyoo, it's the Resident Werewolf to offer the Resident Wiccan a little dice script. And it has all your classic bag o' dice values from the 4-sider right up to the full 20 sided die.
Code:
#==============================================================================
# ** The Dice Module
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 09-06-2013
# RGSS / RPGMaker XP
#------------------------------------------------------------------------------
#
# To use as a basic call, use the command: result = Dice.d20(3) to generate
# a dice_roll of 3 20-sided dice.
#
# Or, you may wish to include this entire module within a class such as the
# Game_Battler class. To do so, you would use an include statement to allow
# all methods within to be used with ease. This would appear as:
#
# class Game_Battler
# include Dice
# #--------------------------------------------------------------------
# # * Public Instance Variables
# #--------------------------------------------------------------------
# attr_reader :battler_name # battler file name
#
# After that, your calls within that class would be simple indeed. It would
# merely be a case of using result = d6(3) to generate a classic '3-18'
# bell curve common to Advanced Dungeons and Dragons games.
#
#==============================================================================
module Dice
# Make methods within function
module_function
#--------------------------------------------------------------------------
# * d4
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def d4(qty=1)
return dice_roll(4, qty)
end
#--------------------------------------------------------------------------
# * d6
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def d6(qty=1)
return dice_roll(6, qty)
end
#--------------------------------------------------------------------------
# * d8
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def d8(qty=1)
return dice_roll(8, qty)
end
#--------------------------------------------------------------------------
# * d10
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def d10(qty=1)
return dice_roll(10, qty)
end
#--------------------------------------------------------------------------
# * d12
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def d12(qty=1)
return dice_roll(12, qty)
end
#--------------------------------------------------------------------------
# * d20
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def d20(qty=1)
return dice_roll(20, qty)
end
#--------------------------------------------------------------------------
# * Rolling the Dice
# dice : type of dice rolled
# qty : quantity of dice rolled
#--------------------------------------------------------------------------
def dice_roll(dice, qty)
# Reset the result
result = 0
# Ensure no value less than 1
qty = 1 if qty < 1
# Cycle through the dice
for i in 1..qty.to_i
# Add the random dice rolls
result += rand(dice)+1
end
# Return the result
return result
end
end
I hope you like it. Now you have little commands to actually make a thing like...
Code:
hit_result = false
hit_result = true if Dice.d20 + attacker.str > target.ac
or
Code:
strength_roll = Dice.d6(3)
The Dice.d20 command generates your d20 dice roll, and the Dice.d6(3) is equivalent to rolling 3 six-siders