PDA

View Full Version : [Script] adding new skills [RMXP/Scripting]


Blizzy
June 5th, 2005, 11:43 AM
ever wanted to make new skills?
like fishing, cooking, etc.
in this toturial, we do fishing.
*the complete script is at the end of the toturial,
but be sure to follow the toturial.*

first, go into the script editor,
and go to the script: Game_Actor.
you'll see attr_reader :level, exp, skills, and some more.
(attr stands for attribute)
attr_reader means it's defined in rmxp itself,
in the database.
now, we are going to add 3 attr_accessors.
with attr_accessor, you can do:
$game_party.actors[ID].fishing_level
now, underneath attr_reader :skills, add 3 new accessors:

attr_accessor :fishing_level
attr_accessor :fishing_exp
attr_accessor :fishing_next_exp

now this is done, let's go on to the next step.
we now need to initialize the level, exp and next_exp.
(give it a value)
scroll down, and look for the line:
@int_plus = 0
beneath it. add:

@fishing_level = 1 #standard level
@fishing_exp = 0 #current exp (which starts at 0)
@fishing_next_exp = 25 #the exp needed for next level.

if you have this done, let's move on :P

now we need to make a formula to level up.
scroll a bit down, and look for:

def id
return @actor_id
end


above it, bewteen "def id" & "end", add the following.

def fishing_level
if @fishing_exp >= @fishing_next_exp
@fishing_next_exp = (@fishing_exp + 65)
return @fishing_level += 1
end
end

i'll explain what this will do.

line 1, is the method,
which has the name of the attr_accessor :fishing_level
line 2, is an if-statement.
this takes care for leveling up.
when @fishing_exp (the current exp) is equal to
@fishing_next_exp (exp needed for next level),
something will happen(in this case: at line 3 & 4)
line 3, increase the number of @fishing_next_exp,
so the number won't be the same. in this case,
it's set equal to the current fishing exp + 65.
line 4
this adds everytime that @fishing_exp is equal to @fishing_next_exp,
1 level to @fishing_level.
line 5 + 6
this ends the if statement & the method.

to test if this is true,
put the following in a call script:

$game_party.actors[0].fishing_exp += 30 #adds 30 exp
#print the current level
print "fishing level: " +
$game_party.actors[0].fishing_level.to_s
#print the current fishing exp
print "current fishing exp: " +
$game_party.actors[0].fishing_exp.to_s
#prints the exp needed for next level
print "fishing exp for next level: " +
$game_party.actors[0].fishing_next_exp.to_s


to add exp, simply do:
$game_party.actors[0].fishing_exp += number
you don't need anything to do with the next exp.

this is the toturial.
i hope this is useful.

comments & questions are welcome.

here's the complete script, for the people who don't know where to put it.

#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
# This class defines an actor, with all of the typical data elements such as level,
# equipment, and skill progression. This class refers to the global arrays $game_actors
# and $game_party.
#==============================================================================

class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# ● Properties
#--------------------------------------------------------------------------
attr_reader :name # name of the character
attr_reader :character_name # character sheet name
attr_reader :character_hue # character hue
attr_reader :class_id # ID of the class that the character is assigned to
attr_reader :weapon_id # ID of the weapon that the character has
attr_reader :armor1_id # ID of the shield that the character is using
attr_reader :armor2_id # ID of the helmet that the character is wearing
attr_reader :armor3_id # ID of the armor that the character is wearing
attr_reader :armor4_id # ID of the accessory that the character is wearing
attr_reader :level # level of the character
attr_reader :exp # experience that the character has
attr_reader :skills # array of skills that the character can use
attr_accessor :fishing_level
attr_accessor :fishing_exp
attr_accessor :fishing_next_exp
#--------------------------------------------------------------------------
# ● Initialize
#--------------------------------------------------------------------------
def initialize(actor_id)
super()
setup(actor_id)
end
#--------------------------------------------------------------------------
# ● Set up characters
#--------------------------------------------------------------------------
def setup(actor_id)
actor = $data_actors[actor_id]
@actor_id = actor_id
@name = actor.name
@character_name = actor.character_name
@character_hue = actor.character_hue
@battler_name = actor.battler_name
@battler_hue = actor.battler_hue
@class_id = actor.class_id
@weapon_id = actor.weapon_id
@armor1_id = actor.armor1_id
@armor2_id = actor.armor2_id
@armor3_id = actor.armor3_id
@armor4_id = actor.armor4_id
@level = actor.initial_level
@exp_list = Array.new(101)
make_exp_list
@exp = @exp_list[@level]
@skills = []
@hp = maxhp
@sp = maxsp
@states = []
@states_turn = {}
@maxhp_plus = 0
@maxsp_plus = 0
@str_plus = 0
@dex_plus = 0
@agi_plus = 0
@int_plus = 0
@fishing_level = 1
@fishing_exp = 0
@fishing_next_exp = 25
for i in 1..@level
for j in $data_classes[@class_id].learnings
if j.level == i
learn_skill(j.skill_id)
end
end
end
update_auto_state(nil, $data_armors[@armor1_id])
update_auto_state(nil, $data_armors[@armor2_id])
update_auto_state(nil, $data_armors[@armor3_id])
update_auto_state(nil, $data_armors[@armor4_id])
end
#---------------------------------------------------------------------
# ● fishing level of the actor
#---------------------------------------------------------------------
def fishing_level
if @fishing_exp >= @fishing_next_exp
@fishing_next_exp = (@fishing_exp + 65)
return @fishing_level += 1
end
end
#---------------------------------------------------------------------
# ● Return the ID assigned to the character
#---------------------------------------------------------------------
def id
return @actor_id
end
#---------------------------------------------------------------------
# ● Return the position of the character in the party
#---------------------------------------------------------------------
def index
return $game_party.actors.index(self)
end
#---------------------------------------------------------------------
# ● Create the character's experience progression table
#---------------------------------------------------------------------
def make_exp_list
actor = $data_actors[@actor_id]
@exp_list[1] = 0
pow_i = 2.4 + actor.exp_inflation / 100.0
for i in 2..100
if i > actor.final_level
@exp_list[i] = 0
else
n = actor.exp_basis * ((i + 3) ** pow_i) / (5 ** pow_i)
@exp_list[i] = @exp_list[i-1] + Integer(n)
end
end
end
#---------------------------------------------------------------------
# ● Returns the character's damage multiplier
#---------------------------------------------------------------------
def element_rate(element_id)
table = [0,200,150,100,50,0,-100]
result = table[$data_classes[@class_id].element_ranks[element_id]]
for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
armor = $data_armors[i]
if armor != nil and armor.guard_element_set.include?(element_id)
result /= 2
end
end
for i in @states
if $data_states[i].guard_element_set.include?(element_id)
result /= 2
end
end
return result
end
#---------------------------------------------------------------------
# ● Return the status resistance values for the character's class
#---------------------------------------------------------------------
def state_ranks
return $data_classes[@class_id].state_ranks
end
#---------------------------------------------------------------------
# ● Check if the character's equipment can resist statuses used on the character
#---------------------------------------------------------------------
def state_guard?(state_id)
for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
armor = $data_armors[i]
if armor != nil
if armor.guard_state_set.include?(state_id)
return true
end
end
end
return false
end
#---------------------------------------------------------------------
# ● Set attributes for the character's weapon
#---------------------------------------------------------------------
def element_set
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.element_set : []
end
#---------------------------------------------------------------------
# ● Set positive statuses for the character's weapon
#---------------------------------------------------------------------
def plus_state_set
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.plus_state_set : []
end
#---------------------------------------------------------------------
# ● Set negative statuses for the character's weapon
#---------------------------------------------------------------------
def minus_state_set
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.minus_state_set : []
end
#---------------------------------------------------------------------
# ● Return the character's maximum HP (includes adjustments)
#---------------------------------------------------------------------
def maxhp
n = [[base_maxhp + @maxhp_plus, 1].max, 9999].min
for i in @states
n *= $data_states[i].maxhp_rate / 100.0
end
n = [[Integer(n), 1].max, 9999].min
return n
end
#---------------------------------------------------------------------
# ● Return the character's maximum HP (no adjustments)
#---------------------------------------------------------------------
def base_maxhp
return $data_actors[@actor_id].parameters[0, @level]
end
#---------------------------------------------------------------------
# ● Return the character's maximum SP (no adjustments)
#---------------------------------------------------------------------
def base_maxsp
return $data_actors[@actor_id].parameters[1, @level]
end
#---------------------------------------------------------------------
# ● Return the character's strength (no adjustments)
#---------------------------------------------------------------------
def base_str
n = $data_actors[@actor_id].parameters[2, @level]
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.str_plus : 0
n += armor1 != nil ? armor1.str_plus : 0
n += armor2 != nil ? armor2.str_plus : 0
n += armor3 != nil ? armor3.str_plus : 0
n += armor4 != nil ? armor4.str_plus : 0
return [[n, 1].max, 999].min
end
#---------------------------------------------------------------------
# ● Return the character's dexterity (no adjustments)
#---------------------------------------------------------------------
def base_dex
n = $data_actors[@actor_id].parameters[3, @level]
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.dex_plus : 0
n += armor1 != nil ? armor1.dex_plus : 0
n += armor2 != nil ? armor2.dex_plus : 0
n += armor3 != nil ? armor3.dex_plus : 0
n += armor4 != nil ? armor4.dex_plus : 0
return [[n, 1].max, 999].min
end
#---------------------------------------------------------------------
# ● Return the character's agility (no adjustments)
#---------------------------------------------------------------------
def base_agi
n = $data_actors[@actor_id].parameters[4, @level]
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.agi_plus : 0
n += armor1 != nil ? armor1.agi_plus : 0
n += armor2 != nil ? armor2.agi_plus : 0
n += armor3 != nil ? armor3.agi_plus : 0
n += armor4 != nil ? armor4.agi_plus : 0
return [[n, 1].max, 999].min
end
#---------------------------------------------------------------------
# ● Return the character's intelligence (no adjustments)
#---------------------------------------------------------------------
def base_int
n = $data_actors[@actor_id].parameters[5, @level]
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.int_plus : 0
n += armor1 != nil ? armor1.int_plus : 0
n += armor2 != nil ? armor2.int_plus : 0
n += armor3 != nil ? armor3.int_plus : 0
n += armor4 != nil ? armor4.int_plus : 0
return [[n, 1].max, 999].min
end
#---------------------------------------------------------------------
# ● Return the character's weapon attack strength (weapon only)
#---------------------------------------------------------------------
def base_atk
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.atk : 0
end
#---------------------------------------------------------------------
# ● Return the character's defense strength (weapon/armor only)
#---------------------------------------------------------------------
def base_pdef
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
pdef1 = weapon != nil ? weapon.pdef : 0
pdef2 = armor1 != nil ? armor1.pdef : 0
pdef3 = armor2 != nil ? armor2.pdef : 0
pdef4 = armor3 != nil ? armor3.pdef : 0
pdef5 = armor4 != nil ? armor4.pdef : 0
return pdef1 + pdef2 + pdef3 + pdef4 + pdef5
end
#---------------------------------------------------------------------
# ● Return the character's magical defense strength
#---------------------------------------------------------------------
def base_mdef
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
mdef1 = weapon != nil ? weapon.mdef : 0
mdef2 = armor1 != nil ? armor1.mdef : 0
mdef3 = armor2 != nil ? armor2.mdef : 0
mdef4 = armor3 != nil ? armor3.mdef : 0
mdef5 = armor4 != nil ? armor4.mdef : 0
return mdef1 + mdef2 + mdef3 + mdef4 + mdef5
end
#---------------------------------------------------------------------
# ● Return the character's evasion percentage
#---------------------------------------------------------------------
def base_eva
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
eva1 = armor1 != nil ? armor1.eva : 0
eva2 = armor2 != nil ? armor2.eva : 0
eva3 = armor3 != nil ? armor3.eva : 0
eva4 = armor4 != nil ? armor4.eva : 0
return eva1 + eva2 + eva3 + eva4
end
#---------------------------------------------------------------------
# ● Return the character's weapon animation on the attaker
#---------------------------------------------------------------------
def animation1_id
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.animation1_id : 0
end
#---------------------------------------------------------------------
# ● Return the character's weapon animation on the attacker's target
#---------------------------------------------------------------------
def animation2_id
weapon = $data_weapons[@weapon_id]
return weapon != nil ? weapon.animation2_id : 0
end
#---------------------------------------------------------------------
# ● Return the name of the character's class
#---------------------------------------------------------------------
def class_name
return $data_classes[@class_id].name
end
#---------------------------------------------------------------------
# ● Return the character's current EXP
#---------------------------------------------------------------------
def exp_s
return @exp_list[@level+1] > 0 ? @exp.to_s : "-------"
end
#---------------------------------------------------------------------
# ● Return the number of EXP the character needs to advance to the next level
#---------------------------------------------------------------------
def next_exp_s
return @exp_list[@level+1] > 0 ? @exp_list[@level+1].to_s : "-------"
end
#---------------------------------------------------------------------
# ● Return the number of remaining EXP the character needs to advance to the next level
#---------------------------------------------------------------------
def next_rest_exp_s
return @exp_list[@level+1] > 0 ?
(@exp_list[@level+1] - @exp).to_s : "-------"
end
#---------------------------------------------------------------------
# ● Removes the automatically inflicted status effects from a piece of equipment that
# was removed and adds the automatically inflicted status effects from a newly-equipped
# piece of equipment.
#---------------------------------------------------------------------
def update_auto_state(old_armor, new_armor)
if old_armor != nil and old_armor.auto_state_id != 0
remove_state(old_armor.auto_state_id, true)
end
if new_armor != nil and new_armor.auto_state_id != 0
add_state(new_armor.auto_state_id, true)
end
end
#---------------------------------------------------------------------
# ● Check if the an equipment slot is locked for the character
#--------------------------------------------------------------------
def equip_fix?(equip_type)
case equip_type
when 0 # Weapon
return $data_actors[@actor_id].weapon_fix
when 1 # Shield
return $data_actors[@actor_id].armor1_fix
when 2 # Helmet
return $data_actors[@actor_id].armor2_fix
when 3 # Armor
return $data_actors[@actor_id].armor3_fix
when 4 # Accessory
return $data_actors[@actor_id].armor4_fix
end
return false
end
#---------------------------------------------------------------------
# ● Equip an item on the character
#---------------------------------------------------------------------
def equip(equip_type, id)
case equip_type
when 0 # Weapon
if id == 0 or $game_party.weapon_number(id) > 0
$game_party.gain_weapon(@weapon_id, 1)
@weapon_id = id
$game_party.lose_weapon(id, 1)
end
when 1 # Shield
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor1_id], $data_armors[id])
$game_party.gain_armor(@armor1_id, 1)
@armor1_id = id
$game_party.lose_armor(id, 1)
end
when 2 # Helmet
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor2_id], $data_armors[id])
$game_party.gain_armor(@armor2_id, 1)
@armor2_id = id
$game_party.lose_armor(id, 1)
end
when 3 # Armor
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor3_id], $data_armors[id])
$game_party.gain_armor(@armor3_id, 1)
@armor3_id = id
$game_party.lose_armor(id, 1)
end
when 4 # Accessory
if id == 0 or $game_party.armor_number(id) > 0
update_auto_state($data_armors[@armor4_id], $data_armors[id])
$game_party.gain_armor(@armor4_id, 1)
@armor4_id = id
$game_party.lose_armor(id, 1)
end
end
end
#---------------------------------------------------------------------
# ● Check if the character can equip a weapon (Class dependent)
#---------------------------------------------------------------------
def equippable?(item)
if item.is_a?(RPG::Weapon)
if $data_classes[@class_id].weapon_set.include?(item.id)
return true
end
end
if item.is_a?(RPG::Armor)
if $data_classes[@class_id].armor_set.include?(item.id)
return true
end
end
return false
end
#---------------------------------------------------------------------
# ● Manually set the character's EXP
#---------------------------------------------------------------------
def exp=(exp)
@exp = [[exp, 9999999].min, 0].max
while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
@level += 1
for j in $data_classes[@class_id].learnings
if j.level == @level
learn_skill(j.skill_id)
end
end
end
while @exp < @exp_list[@level]
@level -= 1
end
@hp = [@hp, self.maxhp].min
@sp = [@sp, self.maxsp].min
end
#---------------------------------------------------------------------
# ● Manually set the character's level
#---------------------------------------------------------------------
def level=(level)
# 上下限チェック
level = [[level, $data_actors[@actor_id].final_level].min, 1].max
# EXP を変更
self.exp = @exp_list[level]
end
#---------------------------------------------------------------------
# ● Give the character a new skill
#---------------------------------------------------------------------
def learn_skill(skill_id)
if skill_id > 0 and not skill_learn?(skill_id)
@skills.push(skill_id)
@skills.sort!
end
end
#---------------------------------------------------------------------
# ● Remove a skill from a character
#---------------------------------------------------------------------
def forget_skill(skill_id)
@skills.delete(skill_id)
end
#---------------------------------------------------------------------
# ● Check if a skill has been learned by a character
#---------------------------------------------------------------------
def skill_learn?(skill_id)
return @skills.include?(skill_id)
end
#---------------------------------------------------------------------
# ● Check if the skill can currently be used
#---------------------------------------------------------------------
def skill_can_use?(skill_id)
if not skill_learn?(skill_id)
return false
end
return super
end
#---------------------------------------------------------------------
# ● Change the character's name
#---------------------------------------------------------------------
def name=(name)
@name = name
end
#---------------------------------------------------------------------
# ● Change the character's class
#---------------------------------------------------------------------
def class_id=(class_id)
if $data_classes[class_id] != nil
@class_id = class_id
# 装備できなくなったアイテムを外す
unless equippable?($data_weapons[@weapon_id])
equip(0, 0)
end
unless equippable?($data_armors[@armor1_id])
equip(1, 0)
end
unless equippable?($data_armors[@armor2_id])
equip(2, 0)
end
unless equippable?($data_armors[@armor3_id])
equip(3, 0)
end
unless equippable?($data_armors[@armor4_id])
equip(4, 0)
end
end
end
#---------------------------------------------------------------------
# ● Change the character's sprite sheet
#---------------------------------------------------------------------
def set_graphic(character_name, character_hue, battler_name, battler_hue)
@character_name = character_name
@character_hue = character_hue
@battler_name = battler_name
@battler_hue = battler_hue
end
#---------------------------------------------------------------------
# ● Return the X coordinate of the actor's battle image on the battle screen
#---------------------------------------------------------------------
def screen_x
if self.index != nil
return self.index * 160 + 80
else
return 0
end
end
#---------------------------------------------------------------------
# ● Return the Y coordinate of the actor's battle image on the battle screen
#---------------------------------------------------------------------
def screen_y
return 464
end
#---------------------------------------------------------------------
# ● Return the Z coordinate of the actor's battle image on the battle screen
#---------------------------------------------------------------------
def screen_z
if self.index != nil
return 4 - self.index
else
return 0
end
end
end

Vash-X
June 9th, 2005, 11:17 AM
What does this script do now?

freakboy
June 10th, 2005, 04:07 AM
you can make your own skills with that script.
it allows you to do it with experience points(exp) like the one in the battle!

Jeff_PKLight
June 10th, 2005, 04:45 AM
Very cool, -virtual-! :D It looks awesome.

Datriot
June 17th, 2005, 01:03 AM
Err....this did nothing, I put the whole code in the Game_Actor script but it's done nothing, I don't see a change in anything...;/

Blizzy
June 17th, 2005, 01:41 AM
Err....this did nothing, I put the whole code in the Game_Actor script but it's done nothing, I don't see a change in anything...;/
erm....because i didn't do anything with it yet.
you can only store exp, next_exp, and level with it

Datriot
June 18th, 2005, 09:35 AM
Oh, okay.(too short, stupid thingy)

Budgie_boy
June 23rd, 2005, 02:48 AM
Hi there, does this also allow you to make the characters level higher than lvl99? If not, how do you make it higher? How do you make the battle screen like POKEMON?

I'm using rm2k/3 and its proving difficult to get the battle sprites in...

freakboy
June 23rd, 2005, 04:55 AM
Hi there, does this also allow you to make the characters level higher than lvl99? If not, how do you make it higher? How do you make the battle screen like POKEMON?

I'm using rm2k/3 and its proving difficult to get the battle sprites in...
this is only for rpgmaker xp, not for rpgmaker 2003, sorry

kanto123326
February 28th, 2011, 03:59 PM
I've got the script and everything, but how do you lvl up in the actual game?
sorry if youve already said this somewhere!:P

Cilerba
February 28th, 2011, 07:03 PM
This threads a little over 5 years old. Try and read the rules next time.

-locked-