Jump to content
  • entries
    65
  • comments
    526
  • views
    68,804

Grathnode Stuff and Improved Note Field Stuff

Kayzee

1,460 views

I have been experimenting quite a bit with the grathnode install script, and made more then a few changes and additions to how it works. The main differences I made is allowing skills in addition to items to be attached to skills, allowing attaching stuff to "Attack" and "Guard", a minimum skill cost, and only allowing grathnodes to be attached to some skill types or skills I also made a module for searching note fields on grathnodes.

 

Here is the code I have so far:

 

if $imported['KRX-GrathnodeInstall']

 

if $imported["Notes Field System"]

 

module GrathSearch

 

def self.find_note(skill, user, note)

if user.is_a?(Game_Actor) && user.installs[skill.id]

for node in user.installs[skill.id]

next if node.nil? || node.note_field[note].nil?

return node.note_field[note]

end

end

end

 

def self.find_note_all(skill, user, note)

a = []

if user.is_a?(Game_Actor) && user.installs[skill.id]

for node in user.installs[skill.id]

next if node.nil? || node.note_field[note].nil?

a.push node.note_field[note]

end

end

return a

end

 

end

 

end

 

#==========================================================================

# ? RPG::UsableItem

#==========================================================================

 

class RPG::UsableItem

#--------------------------------------------------------------------------

# ? Public instance variables

#--------------------------------------------------------------------------

attr_reader :grathnode_scope

attr_reader :mp_inflation

attr_reader :tp_inflation

#--------------------------------------------------------------------------

# ? Loads the note tags

#--------------------------------------------------------------------------

def load_grathnode_notetags

@mp_inflation = @tp_inflation = 0

@grathnode_set_scope = nil

@note.split(/[\r\n]+/).each do |line|

case line

when KRX::REGEXP::GRATHNODE_ITEM

@is_grathnode = true

when KRX::REGEXP::GRATHNODE_SCOPE

@grathnode_scope = $1

when KRX::REGEXP::MP_INFLATION

@mp_inflation = $1.to_i

when KRX::REGEXP::TP_INFLATION

@tp_inflation = $1.to_i

end

end

end

#--------------------------------------------------------------------------

# ? Determine if the item is a grathnode crystal

#--------------------------------------------------------------------------

def grathnode?

@is_grathnode

end

end

 

#==========================================================================

# ? RPG::Item

#==========================================================================

 

class RPG::Item < RPG::UsableItem

#--------------------------------------------------------------------------

# ? Public instance variables

#--------------------------------------------------------------------------

attr_reader :grathnode_scope

attr_reader :mp_inflation

attr_reader :tp_inflation

#--------------------------------------------------------------------------

# ? Loads the note tags

#--------------------------------------------------------------------------

def load_grathnode_notetags

super

end

#--------------------------------------------------------------------------

# ? Determine if the item is a grathnode crystal

#--------------------------------------------------------------------------

def grathnode?

super

end

end

 

 

#==========================================================================

# ? RPG::Skill

#==========================================================================

 

class RPG::Skill < RPG::UsableItem

 

#--------------------------------------------------------------------------

# ? Loads the note tags

#--------------------------------------------------------------------------

alias_method :load_grathnode_notetags_grathnode_base, :load_grathnode_notetags

def load_grathnode_notetags

load_grathnode_notetags_grathnode_base

super

end

 

end

 

#==========================================================================

# ? Game_Actor

#==========================================================================

 

class Game_Actor < Game_Battler

#--------------------------------------------------------------------------

# ? Adds a grathnode crystal to a specific skill slot

#--------------------------------------------------------------------------

def add_grathnode(skill, crystal, slot)

if @installs[skill.id].nil?

@installs[skill.id] = Array.new(skill.grathnode_slots, nil)

elsif @installs[skill.id][slot] != nil &&

@installs[skill.id][slot].is_a?(RPG::Item)

$game_party.gain_item(@installs[skill.id][slot], 1)

end

if crystal.is_a?(RPG::Item) && !crystal.nil?

$game_party.lose_item(crystal, 1)

end

@installs[skill.id][slot] = crystal

end

 

#--------------------------------------------------------------------------

# ? Returns the TP cost for a skill

#--------------------------------------------------------------------------

def skill_tp_cost(skill)

cost = super

tp_rate = process_grathnode_tp_cost(skill)

mp_rate = process_grathnode_mp_cost(skill)

if cost+skill_mp_cost(skill) < 5

if tp_rate + mp_rate > 5

cost = 5

end

end

(cost + cost * tp_rate / 100).round

end

 

end

 

 

#==========================================================================

# ? Window_UpSkillList

#==========================================================================

 

class Window_UpSkillList < Window_SkillList

 

def make_item_list

@data = []

if @stype_id == 0

@data.push($data_skills[1]) if $data_skills[1].grathnode_slots > 0

@data.push($data_skills[2]) if $data_skills[2].grathnode_slots > 0

end

@data += @actor ? @actor.skills.select {|skill| include?(skill) } : []

end

 

end

 

#==========================================================================

# ? Window_GrathnodeList

#==========================================================================

 

class Window_GrathnodeList < Window_ItemList

#--------------------------------------------------------------------------

# ? Determine if an item goes in the list

#--------------------------------------------------------------------------

def include?(item)

item.is_a?(RPG::UsableItem) && item.grathnode?

end

#--------------------------------------------------------------------------

# ? Determine if the grathnode can be used

#--------------------------------------------------------------------------

alias_method :enable_grathnode_base?, :enable?

def enable?(item)

return false unless enable_grathnode_base?(item)

skill = $game_party.last_selected_skill

return true if item.nil?

if $imported["Notes Field System"]

return false unless item.note_field[:meta_skill_id].nil? ||

item.note_field[:meta_skill_id] == skill.id

return false unless item.note_field[:meta_stype].nil? ||

item.note_field[:meta_stype] == skill.stype_id

end

return true

end

#--------------------------------------------------------------------------

# ? Creates the list based on the recipes

#--------------------------------------------------------------------------

def make_item_list

@data = $game_party.menu_actor.skills.select {|item| include?(item)}

@data += $game_party.items.select {|item| include?(item)}

@data.push(nil)

end

 

def draw_item_number(rect, item)

return unless item.is_a?(RPG::Item)

super

end

 

end

 

## Menu inclusion, with Yanfly's Ace Skill Menu

if $imported["YEA-SkillMenu"]

 

class Window_SkillCommand < Window_Command

 

alias make_command_list_grathnode_base make_command_list

def make_command_list

return unless @actor

if SceneManager.scene_is?(Scene_Grathnode)

add_command("Normal Actions", :skill, true, 0)

end

make_command_list_grathnode_base

end

 

#--------------------------------------------------------------------------

# new method: add_learn_skill_command

#--------------------------------------------------------------------------

def add_grathnodes_command

name = KRX::VOCAB::GRATHNODE

add_command(name, :grathnode, true, :grathnode_mode)

end

 

end # Window_SkillCommand

 

class Window_SkillList < Window_Selectable

 

#--------------------------------------------------------------------------

# new method: tp_mode?

#--------------------------------------------------------------------------

def grathnode_mode?; return @stype_id == :grathnode_mode; end

 

#--------------------------------------------------------------------------

# alias method: make_item_list

#--------------------------------------------------------------------------

alias make_item_list_grathnode_base make_item_list

def make_item_list

if grathnode_mode?

@data = $game_party.menu_actor.skills.select {|item| item.is_a?(RPG::UsableItem) && item.grathnode?}

@data += $game_party.items.select {|item| item.is_a?(RPG::UsableItem) && item.grathnode?}

else

make_item_list_grathnode_base

end

end

 

alias draw_item_grathnode_base draw_item

def draw_item(index)

if grathnode_mode?

rect = item_rect(index)

rect.width -= 4

draw_item_name(@data[index], rect.x, rect.y, true)

else

draw_item_grathnode_base(index)

end

end

 

end

 

end ## End of Yanfly's Ace Skill Menu inclusion

 

end #End of Grathnode import check

 

 

Also speaking of note fields, I have been using a version of this script to get a note hash. I posted a little of my changes in the thread, mostly changing the regex to not need to surround existing notes with anything.

 

Here is the version I am using:

 

#==============================================================================

# ** Notes Field System (KZ Edit)

#------------------------------------------------------------------------------

# By Syvkal

# Version 1.2

# 29-03-12

#------------------------------------------------------------------------------

# * Original available at:

# www.rpgmakervxace.net & forums.rpgmakerweb.com

# Please redistribute this script ;)

#==============================================================================

#

# - INTRODUCTION -

#

# I want to standardise how we use the notes field from the database to make

# scripting and compatibility easier

#

# So feel free to use this script in conjunction with any of your own scripts

#

#------------------------------------------------------------------------------

#

# - USAGE -

#

# The System will take the contents of the notes field and convert it into a

# Hash. The '{' and '}' are added on automatically, so these can be omitted

# from the notes field.

#

# --- Setting Tags ----------------------------------

#

# To add a tag to the notes field simply write its name as a symbol

# ie. start it with a colon ':' For Example:

# :this_is_a_tag

#

# As this is a Hash, define the tags value as follows:

# :tag => x

#

# Where x can be a string (wrapped in quote marks) eg.

# :tag => 'Helloooo'

# or x can be a number eg.

# :tag => 3423

# or x can be an array eg.

# :tag => [567, 'hello', [0]]

# or x can be another Hash eg.

# :tag => {:thing => 'hello', :etc => [54, [0,1], 5] }

#

# Finally as this is a Hash, each tag must be separated by a comma

# For Example:

# :tag1 => 1,

# :tag2 => [2],

# :tag3 => 'Three' <----- No Comma at the end!

#

# --- Scripting -------------------------------------

#

# Making your own scripts using this should be fairly simple

# A base items note field can be called by:

# item.note_field

#

# Checking for tags can be done like this:

# item.note_field.include?(:tag)

#

# And finally taking that tags value is done like this:

# item.note_field[:tag]

#

# Make sure you check that the tag exists before trying to take its value,

# as if it doesn't it will most likely end in errors.

#

#==============================================================================

 

#==============================================================================

# ** Script Import

#==============================================================================

 

$imported = {} if $imported == nil

$imported["Notes Field System"] = true

 

#==============================================================================

# ** NOTES Module

#------------------------------------------------------------------------------

# Handles Notes Field System operations

#==============================================================================

 

module NOTES

#--------------------------------------------------------------------------

# * Gets the Field

#--------------------------------------------------------------------------

def field(note)

notestr = ''+note

notes=[]

notestr.split(/[\r\n]+/).each do |line|

if line =~ /\A\s*(:.*\s*=>\s*.*[^\s,])/

notes.push($1)

end

end

return eval('{'+notes.join(', ')+'}')

end

 

end

 

#==============================================================================

# ** RPG::BaseItem

#------------------------------------------------------------------------------

# Defines the Note Field

#==============================================================================

 

class RPG::BaseItem

#--------------------------------------------------------------------------

# * Includes The NOTES Module

#--------------------------------------------------------------------------

include NOTES

#--------------------------------------------------------------------------

# * Gets the Note Field

#--------------------------------------------------------------------------

def note_field

@note_field = field(note) if @note_field.nil?

return @note_field

end

 

end

 

class Game_Actor < Game_Battler

 

def note_field

self.actor.note_field

end

 

end

 

class Game_Enemy < Game_Battler

 

def note_field

self.enemy.note_field

end

 

end

 

 

It should be 100% backwards compatible.

  • Like 1

×
Top ArrowTop Arrow Highlighted