04-10-2007, 01:00 PM
Luck Script
by Darklord3652
Version: 1.0
Apr 10, 2007
Introduction
This Script allows each actor to have luck, a hidden stat which affect critical hit chance, item gained chance, and gold gained chance.
Features
Script
Instructions
As long as you've defined the actor's luck around line 64, put this above main, below the default scripts, and it should work fine.
Compatibility
Probably incompatible with SDK and most other Battle Systems, I rewrite too many methods.
Credits and Thanks
Give credit to The_Darklord.
Thanks to DragoonNouman and Modern Algebra for the testing.
by Darklord3652
Version: 1.0
Apr 10, 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
Introduction
This Script allows each actor to have luck, a hidden stat which affect critical hit chance, item gained chance, and gold gained chance.
Features
- The party's average luck effects the percent of getting an item in battle
- The party's average luck effects the amount of gold gained in battle
- Each actor's luck effects their critical hit chance
Script
Code:
#==============================================================================
# Luck Script 1.0
#------------------------------------------------------------------------------
# By The_Darklord
#==============================================================================
#==============================================================================
# Instructions
#------------------------------------------------------------------------------
# To use this script, go down to line 64 and define each actor's luck
# Luck can also be altered in game with the following call script command:
# $game_actors[X].luck = Y
# With X being the actor id number and Y beeing the luck value.
# It's worth noting you can have unlucky characters by assign a negative value
#==============================================================================
#==============================================================================
# The following default methods are rewritten:
# Scene_Battle : start_phase5
# Game_Battler : attack_effect
#------------------------------------------------------------------------------
# The following default methods are aliased
# Scene_Title : command_new_game
#==============================================================================
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :luck # luck
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias luckinitialize initialize
def initialize
luckinitialize
@luck = 0
end
#--------------------------------------------------------------------------
# * Change Luck
# newluck : new luck
#--------------------------------------------------------------------------
def luck=(newluck)
# Change luck
@luck = newluck
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs title screen processing.
#==============================================================================
class Scene_Title
alias new_game_luck command_new_game
def command_new_game
new_game_luck
#==============================================================================
# Set the actor's luck here!
#==============================================================================
$game_actors[1].luck = 50
$game_actors[2].luck = 30
$game_actors[3].luck = -30
$game_actors[4].luck = 10
$game_actors[5].luck = 30
$game_actors[6].luck = 40
$game_actors[7].luck = 100
$game_actors[8].luck = 70
#==============================================================================
end
end
#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Start After Battle Phase
#--------------------------------------------------------------------------
def start_phase5
# Shift to phase 5
@phase = 5
# Play battle end ME
$game_system.me_play($game_system.battle_end_me)
# Return to BGM before battle started
$game_system.bgm_play($game_temp.map_bgm)
# Initialize EXP, amount of gold, and treasure
exp = 0
gold = 0
treasures = []
# Initialize the variable while the party's combined luck will be stored
partyluck = 0
# Calculate the party's combined luck
for i in 0...$game_party.actors.size
partyluckold = partyluck
partyluck = $game_party.actors[i].luck + partyluckold
end
# Loop
for enemy in $game_troop.enemies
# If enemy is not hidden
unless enemy.hidden
# Add EXP and amount of gold obtained
exp += enemy.exp
gold += enemy.gold
# Increase/decrease the chance of getting an item based on luck
random = (rand(100) - (Integer(Float(partyluck/$game_party.actors.size))/10))
# Determine if treasure appears
if random < enemy.treasure_prob
if enemy.item_id > 0
treasures.push($data_items[enemy.item_id])
end
if enemy.weapon_id > 0
treasures.push($data_weapons[enemy.weapon_id])
end
if enemy.armor_id > 0
treasures.push($data_armors[enemy.armor_id])
end
end
end
end
# Treasure is limited to a maximum of 6 items
treasures = treasures[0..5]
# Obtaining EXP
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.cant_get_exp? == false
last_level = actor.level
actor.exp += ((exp * $game_party.actors[i].luck/10) + exp)
if actor.level > last_level
@status_window.level_up(i)
end
end
end
# Calculate the extra gold the party will recieve
extragold = Integer(gold * ((Float(partyluck/$game_party.actors.size))/1000))
# Obtaining gold
$game_party.gain_gold(extragold + gold)
# Obtaining treasure
for item in treasures
case item
when RPG::Item
$game_party.gain_item(item.id, 1)
when RPG::Weapon
$game_party.gain_weapon(item.id, 1)
when RPG::Armor
$game_party.gain_armor(item.id, 1)
end
end
# Make battle result window
@result_window = Window_BattleResult.new(exp, extragold + gold, treasures)
# Set wait count
@phase5_wait_count = 100
end
end
#==============================================================================
# ** Game_Battler (part 3)
#------------------------------------------------------------------------------
# This class deals with battlers. It's used as a superclass for the Game_Actor
# and Game_Enemy classes.
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# * Applying Normal Attack Effects
# attacker : battler
#--------------------------------------------------------------------------
def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < attacker.hit)
# If hit occurs
if hit_result == true
# Calculate basic damage
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20
# Element correction
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Critical correction
random = (rand(100) - (Integer(attacker.luck/10)))
if random < 4 * attacker.dex / self.agi
self.damage *= 2
self.critical = true
end
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
eva = 8 * self.agi / attacker.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
end
# If hit occurs
if hit_result == true
# State Removed by Shock
remove_states_shock
# Substract damage from HP
self.hp -= self.damage
# State change
@state_changed = false
states_plus(attacker.plus_state_set)
states_minus(attacker.minus_state_set)
# When missing
else
# Set damage to "Miss"
self.damage = "Miss"
# Clear critical flag
self.critical = false
end
# End Method
return true
end
end
Instructions
As long as you've defined the actor's luck around line 64, put this above main, below the default scripts, and it should work fine.
Compatibility
Probably incompatible with SDK and most other Battle Systems, I rewrite too many methods.
Credits and Thanks
Give credit to The_Darklord.
Thanks to DragoonNouman and Modern Algebra for the testing.