This is a rather complicated question, because I am not quite sure what the issue is.
This is a custom skill learning system I have been working on for my project. It's pretty straight forward - weapons give skills and certain skills are granted depending on a weapon's "mastery".
@weapon_ms = { 0 => 0,} is the "mastery" array.
I want to add a weapon to the array when an actor equips it, thus initializing a character's mastery of a weapon.
if defined? @weapon_ms[@weapon_id] == false
@current_weap = { @weapon_id => 1, }
@current_weap.merge!(@weapon_ms)
end
This is assume is how I go about doing it.
However I get an error on this line:
if @weapon_ms[@weapon_id][w] >= Jaabi::WSKILL_EXP[@weapon_id][w]
Undefined method '[]' for nil:NilClass.
I suspect that it's trying to add @weapon_id => 1 to the array, rather than the result of @weapon_id to the array. Like 1 => 1,.
Alternatively, if defined? @weapon_ms[@weapon_id] == false is seeing @weapon_ms as being defined, when I want to check if the current @weapon_id is already in the array.
Creating the separate mastery points gaining system sounds easy, but if my second theory is true, I am not sure how I am meant to "update" the appropriate array item's value. (e.g 1 => 1, weapon 1's mastery to 1 => 21 - adding 20 points.)
Note: This worked before when I used normal exp. However I remembered that I wanted a character to be able to master weapons individually (mastery is passed between same weapons intentionally - e.g bronze swords; not swords as a whole). So I tried creating an array that I hoped would add to itself.
The actor and weapon "type" system is not yet sorted out. Ignore it for now.
EDIT: Oh yeah. This is RMVX. Forgot to mention that. XD;
Code:
<span style="color:#000080; font-style:italic;">=begin
<span style="color:#000080; font-style:italic;">╔═════════════════════════════════════════════════════════════════════════════╗
<span style="color:#000080; font-style:italic;">║ Stamina_BATTLE Weapon and Skill System ║
<span style="color:#000080; font-style:italic;">╚═════════════════════════════════════════════════════════════════════════════╝
<span style="color:#000080; font-style:italic;">=end
module Jaabi
#--------------------------------------------------------------------------
# * Custom Actor Data
#--------------------------------------------------------------------------
# Use:
# Defines what type of weapon an actor uses
# Format:
# Actor ID = "type"
ACTORW_TYPE = { 1 => "Ring",
2 => "Arrow",
}
#--------------------------------------------------------------------------
# * Custom Weapon/Skill Data
#--------------------------------------------------------------------------
# Use:
# Defines weapon types
# Format:
# Weapon ID = "type"
WEAPON_TYPE = { 1 => "Ring",
2 => "Ring",
13 => "Arrow",
}
#--------------------------------------------------------------------------
# * Weapon Skill Sets
#--------------------------------------------------------------------------
# Use:
# Defines what skills are learnt from weapons
# Format:
# Weapon ID => [ Skill ID, Skill ID]
WEAPON_SKILLS = { 1 => [ 1, 2, 3, 4, 5, 6,],
2 => [ 7, 8, 9, 10, 11, 12,],
}
# Use:
# Defines when the skills are learnt, based on the skills
# above. As such the EXP must be ordered the same as the
# skills above.
WSKILL_EXP = { 1 => [ 0, 100, 300, 500, 800, 900,],
2 => [ 0, 100, 300, 500, 800, 900,],
}
#--------------------------------------------------------------------------
# * Defaults
#--------------------------------------------------------------------------
ACTORW_TYPE.default = { 0 => 0, }
WEAPON_TYPE.default = { 0 => 0, }
WEAPON_SKILLS.default = { 0 => [ 0, 0, 0, 0, 0, 0,], }
WSKILL_EXP.default = { 0 => [ 0, 0, 0, 0, 0, 0,], }
end
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
class Game_Actor
#--------------------------------------------------------------------------
# * Object aliasing
#--------------------------------------------------------------------------
alias jaabi_sbbs_actor_init initialize
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :weapon_ms
#--------------------------------------------------------------------------
# * Weapon Mastery
#--------------------------------------------------------------------------
def initialize(actor_id)
jaabi_sbbs_actor_init(actor_id)
@weapon_ms = { 0 => 0,}
end
#--------------------------------------------------------------------------
# * Get Skill Object Array
#--------------------------------------------------------------------------
def skills
result = []
for i in @skills
result.push($data_skills[i])
end
unless @weapon_id == 0
if defined? @weapon_ms[@weapon_id] == false
@current_weap = { @weapon_id => 1, }
@current_weap.merge!(@weapon_ms)
end
for w in 0..5
if @weapon_ms[@weapon_id][w] >= Jaabi::WSKILL_EXP[@weapon_id][w]
result.push($data_skills[Jaabi::WEAPON_SKILLS[@weapon_id][w]])
else
result.push(nil)
end
end
end
return result
end
#--------------------------------------------------------------------------
# * Determine Usable Skills
# skill : skill
#--------------------------------------------------------------------------
def skill_can_use?(skill)
#return false unless skill_learn?(skill)
return super
end
end
@weapon_ms = { 0 => 0,} is the "mastery" array.
I want to add a weapon to the array when an actor equips it, thus initializing a character's mastery of a weapon.
if defined? @weapon_ms[@weapon_id] == false
@current_weap = { @weapon_id => 1, }
@current_weap.merge!(@weapon_ms)
end
This is assume is how I go about doing it.
However I get an error on this line:
if @weapon_ms[@weapon_id][w] >= Jaabi::WSKILL_EXP[@weapon_id][w]
Undefined method '[]' for nil:NilClass.
I suspect that it's trying to add @weapon_id => 1 to the array, rather than the result of @weapon_id to the array. Like 1 => 1,.
Alternatively, if defined? @weapon_ms[@weapon_id] == false is seeing @weapon_ms as being defined, when I want to check if the current @weapon_id is already in the array.
Creating the separate mastery points gaining system sounds easy, but if my second theory is true, I am not sure how I am meant to "update" the appropriate array item's value. (e.g 1 => 1, weapon 1's mastery to 1 => 21 - adding 20 points.)
Note: This worked before when I used normal exp. However I remembered that I wanted a character to be able to master weapons individually (mastery is passed between same weapons intentionally - e.g bronze swords; not swords as a whole). So I tried creating an array that I hoped would add to itself.
The actor and weapon "type" system is not yet sorted out. Ignore it for now.
EDIT: Oh yeah. This is RMVX. Forgot to mention that. XD;