06-14-2024, 07:18 PM
(This post was last modified: 06-14-2024, 07:20 PM by DerVVulfman.)
VARIABLE ENEMY HP & SP
Version: 1.0
Version: 1.0
Introduction
This script allows one to make the HP and SP scores of enemies variable. That is to say, any enemy defined within the hash arrays provided, will have randomly generated hit and/or skill points rather than those defined in the database.
There are two methods which may be employed to generate these scores, the basic 'Ranged Score' approach and the 'Dice-Rolling' method. Both methods involve randomly generated values, but there are certain differences.
Screenshots
It generates numbers! What more do you want?
Demo
Nah.
Script
Variable Stats right here!
Code:
#==============================================================================
# ** VARIABLE ENEMY HP & SP
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 06-14-2024 MM/DD/YYYY
# RGSS / RPGMaker XP
#==============================================================================
#
# INTRODUCTION:
#
# This script allows one to make the HP and SP scores of enemies variable.
# That is to say, any enemy defined within the hash arrays provided, will
# have randomly generated hit and/or skill points rather than those defined
# in the database.
#
# There are two methods which may be employed to generate these scores, the
# basic 'Ranged Score' approach and the 'Dice-Rolling' method. Both methods
# involve randomly generated values, but there are certain differences.
#
# The random value generated by the Ranged method is a single numeric score
# that has as much an equal shot across the board. For an example, assume
# that an enemy's HP would be based on a range of 1 to 50. The chance of
# the enemy having an HP of 1 is just as likely as the enemy having 50 as
# its HP score.
#
# As to the random value generated by the Dice-Rolling method, it assumes
# that multiple random values of equal range are being generated and added
# together to form a final value. This creates a basic range between the
# lowest possible result of all values generated (or rolled) to the highest
# number possible. However, it also supports the notion of a mean average
# score with the 'rolled' values. A classic example of this is familiar to
# those whom play "Dungeons & Dragons" when rolling three six-sided dice.
# The range of the score would hover between 3 to 18. But the mean average
# for the dice hovers between 8 to 12, a general bell-curve created by the
# possible random rolls. Ergo, the Dice-Rolling method may deliver a more
# controlled output.
#
# In both cases, a fixed value may be added to the score under the assump-
# tion that the HP and/or SP cannot below a certain value.
#
#------------------------------------------------------------------------------
#
# NOTE:
#
# The bulk of this was done last night. Do note that as a system, it may be
# adapted to include a separate MP (or like) category for systems that have
# such enemy stats. But I cannot guide how to introduce other than recom-
# mending that one study this script.
#
#------------------------------------------------------------------------------
#
# COMPATABILITY:
#
# Designed for the RPGMaker XP environment. No methods were overwritten, so
# it should work with most any system that does not adversely alter either
# methods enemies generate their hp or sp scores.
#
#==============================================================================
#
# TERMS AND CONDITIONS:
#
# Free for use, even in commercial games. Due credit is the only requirement.
#
#==============================================================================
module VaryStats
#----------------------------------------------------------------------------
# > DO NOT TOUCH <
ENEMY_HP_RANGED, ENEMY_HP_DICE, ENEMY_SP_RANGED, ENEMY_SP_DICE = {},{},{},{}
#----------------------------------------------------------------------------
# RANDOMIZED HP in RANGE
# ======================
# Enemies defined here will have their hit points generated randomly by
# means of a simple random value range coupled with a fixed score.
#--------------------------------------------------------------------------
#
# ID Random Fixed
# =================== ====== =====
ENEMY_HP_RANGED[1] = [180, 450] # Ghost (range 451-630)
ENEMY_HP_RANGED[4] = [325, 600] # Hellhound (range 601-925)
# RANDOMIZED HP by DICE
# =====================
# Enemies defined here will have their hit points generated randomly by
# simulated dice rolls added together, coupled with a fixed score.
#--------------------------------------------------------------------------
#
# ID Rolls Die Fixed
# ================ ===== === =====
ENEMY_HP_DICE[2] = [5, 20, 500] # Basilisk ( 5 d20 + 500)
ENEMY_HP_DICE[7] = [16, 12, 900] # Imp (16 d12 + 900)
# ---------------------------
# The mean average for d20
# would be between 7 to 14
# so the Basilisk's HP would
# be between 505 to 600 HP
# with the average rolls
# between 535-570 HP.
# RANDOMIZED SP in RANGE
# ======================
# Enemies defined here will have their skill points generated randomly by
# means of a simple random value range coupled with a fixed score.
#--------------------------------------------------------------------------
#
# ID Random Fixed
# =================== ====== =====
ENEMY_SP_RANGED[3] = [300, 225] # Sahagin (range 226-525)
# ---------------------------
# Would limit use of 'Water'
# at 75sp between 3-7 uses.
# RANDOMIZED SP by DICE
# =====================
# Enemies defined here will have their skill points generated randomly by
# simulated dice rolls added together, coupled with a fixed score.
#--------------------------------------------------------------------------
#
# ID Rolls Die Fixed
# ================ ===== === =====
ENEMY_SP_DICE[8] = [8, 12, 12] # Angel ( 8 d12 + 700)
ENEMY_SP_DICE[10] = [45, 20, 0] # Lamia ( 45 d20)
# ---------------------------
# With a 5-8 mean average on
# a d12, this generates SP
# from 708 to 796 for the
# Angel with an average
# score of 740 to 764 SP.
# ---------------------------
# The Lamia rolls 45 d20
# which allows for a range
# between 45 to 900 SP with
# an averate of 315 to 630.
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :vary_hp_start # Generate varied HP flag
attr_accessor :vary_hp_array # Randomized HP hash array
attr_accessor :vary_sp_start # Generate varied SP flag
attr_accessor :vary_sp_array # Randomized SP hash array
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias vary_stats_game_system_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
#
# Perform the original method
vary_stats_game_system_initialize
#
# Define random HP start and hash array values
@vary_hp_start = false
@vary_hp_array = ()
# Define random SP start and hash array values
@vary_sp_start = false
@vary_sp_array = ()
#
end
end
#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
# This class handles enemies. It's used within the Game_Troop class
# ($game_troop).
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# * Get Maximum HP
#--------------------------------------------------------------------------
def maxhp
#
# Assume enemy not identified
effective = false
#
# Identify enemy in either hash arrays
effective = true if VaryStats::ENEMY_HP_RANGED.has_key?(id)
effective = true if VaryStats::ENEMY_HP_DICE.has_key?(id)
#
# Perform normal operation if enemy not in arrays
return super() unless effective
#
# Exit method with value from alternate hp
return maxhp_varied(id)
#
end
#--------------------------------------------------------------------------
# * Get Alternate Maximum HP
# id : enemy database ID
#--------------------------------------------------------------------------
def maxhp_varied(id)
#
# Exit if no discernable index (troop not generated)
return if @member_index.nil?
#
# If already generated (not starting over)
unless $game_system.vary_hp_start == true
return $game_system.vary_hp_array[@member_index]
end
#
# Generate value based on enemy hash type
if VaryStats::ENEMY_HP_RANGED.has_key?(id)
value = vary_stat_ranged(VaryStats::ENEMY_HP_RANGED[id])
end
if VaryStats::ENEMY_HP_DICE.has_key?(id)
value = vary_stat_dice(VaryStats::ENEMY_HP_DICE[id])
end
#
# Push into the random hp array and return the calculated HP
$game_system.vary_hp_array[@member_index] = value
return value
#
end
#--------------------------------------------------------------------------
# * Get Maximum SP
#--------------------------------------------------------------------------
def maxsp
#
# Assume enemy not identified
effective = false
#
# Identify enemy in either hash arrays
effective = true if VaryStats::ENEMY_SP_RANGED.has_key?(id)
effective = true if VaryStats::ENEMY_SP_DICE.has_key?(id)
#
# Perform normal operation if enemy not in arrays
return super() unless effective
#
# Exit method with value from alternate hp
return maxsp_varied(id)
#
end
#--------------------------------------------------------------------------
# * Get Alternate Maximum SP
# id : enemy database ID
#--------------------------------------------------------------------------
def maxsp_varied(id)
#
# Exit if no discernable index (troop not generated)
return if @member_index.nil?
#
# If already generated (not starting over)
unless $game_system.vary_sp_start == true
return $game_system.vary_sp_array[@member_index]
end
#
# Generate value based on enemy hash type
if VaryStats::ENEMY_SP_RANGED.has_key?(id)
value = vary_stat_ranged(VaryStats::ENEMY_SP_RANGED[id])
end
if VaryStats::ENEMY_SP_DICE.has_key?(id)
value = vary_stat_dice(VaryStats::ENEMY_SP_DICE[id])
end
#
# Push into the random hp array and return the calculated HP
$game_system.vary_sp_array[@member_index] = value
return value
#
end
#--------------------------------------------------------------------------
# * Generate alternate stat value based on ranged value calculation
# array_val : data array for specific creature
#--------------------------------------------------------------------------
def vary_stat_ranged(array_val)
#
# Acquire values for subject Creature
random_val = array_val[0]
fixed_val = array_val[1]
#
# Calculate
final_val = rand(random_val) + 1 + fixed_val
#
# Exit with the final value
return final_val
#
end
#--------------------------------------------------------------------------
# * Generate alternate stat value based on dice-based calculation
# array_val : data array for specific creature
#--------------------------------------------------------------------------
def vary_stat_dice(array_val)
#
# Acquire values for subject Creature
num_rolls = array_val[0]
die_type = array_val[1]
fixed_val = array_val[2]
#
# Start calculation
final_val = fixed_val
#
# Cycle through dice rolls
for i in 0...num_rolls
dice_roll = rand(die_type) + 1 # Generate individual die roll
final_val += dice_roll # Add to calculation
end
#
# Exit with the final value
return final_val
#
end
end
#==============================================================================
# ** Game_Troop
#------------------------------------------------------------------------------
# This class deals with troops. Refer to "$game_troop" for the instance of
# this class.
#==============================================================================
class Game_Troop
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias vary_stats_game_troop_setup setup
#--------------------------------------------------------------------------
# * Setup
# troop_id : troop ID
#--------------------------------------------------------------------------
def setup(troop_id)
#
# Reset random HP start and clear array
$game_system.vary_hp_start = true
$game_system.vary_hp_array = {}
# Reset random HP start and clear array
$game_system.vary_sp_start = true
$game_system.vary_sp_array = {}
#
# Perform the original call
vary_stats_game_troop_setup(troop_id)
#
# Set random HP value generation done
$game_system.vary_hp_start = false
# Set random SP value generation done
$game_system.vary_sp_start = false
#
end
end
Instructions
Not really. But I hope the VaryStats module should be very clear to understand.
FAQ
I was bored last night.
Compatibility
Designed for the RPGMaker XP environment. No methods were overwritten, so it should work with most any system that does not adversely alter either methods enemies generate their hp or sp scores.
Credits and Thanks
Thanks to the Cherry Koolaid I had last night?
Author's Notes
Its designed in a simple manner and could be used to design other random stat value options like MP scores for those adding a third form of points. But I'm not going there.
Terms and Conditions
Free for use, even in commercial games. Due credit is the only requirement.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links