hey guys im pretty stumped on this one, i have been trying to check an attr variables value within an if stament in a seperate class, so say i have got this class:
class Interpreter
attr_accessor :variable
i have tried checking the value in the following ways:
class New_Class
$interpreter::variable
$interpreter.variable
var = Interpreter.new
var::variable
var.variable
end
so far i have had no success on checking the value :(
class MyClass
attr_reader :myVar
def initialize
@myVar = "Hello world"
end
end
klass = MyClass.new
p klass.myVar
All those double semi-colons and global variables are the complete wrong syntax with what you are trying to do.
ok i have noted what you said, but when i try using that code all i get is an error, how would i incorporate that into an if statment? heres the code im trying to do the check with:
def add_hatchet_sprite(sprite)
inter = Interpreter.new
return if $game_party == nil
if p inter.cutting == true
for i in 0...$game_party.actors.size
@tool[i+1].push(sprite)
end
end
end
end
heres the variable in iterpreter:
class Interpreter
attr_accessor :cutting
end
That code does not give an error. If it does, you are changing it.
if p inter.cutting == true
Um...why is there a "print" function here?
That's better. :rite:
ok i re inserted the code and it makes the check now, i must have made a typo somewhere, the only problem now is that it is returning false even though i set the variable to true before i make the call, heres the code of each section:
this one sets the variable to true and calls the script that adds to the graphic:
def hacking
a = $game_actors[1]
@old_graphic = a.character_name
wc_graphic = a.character_name + "_mine"
a.set_graphic(wc_graphic, a.character_hue, a.battler_name, a.battler_hue)
ctree = Wcconfig::tree_setup(@tree)
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.wclevel >= ctree[4]
@cutting = true
@wc_count = ctree[0] * 2 - 1
#last_wclevel = actor.wclevel
#gainitemhere
Tool.tool_update
$game_temp.visual_transfer = true
$game_player.step_enable
$game_player.refresh
else
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
end
end
end
the code that checks if its true adds to the character sprite:
def add_hatchet_sprite(sprite)
inter = Interpreter.new
return if $game_party == nil
if inter.cutting == true
for i in 0...$game_party.actors.size
@tool[i+1].push(sprite)
end
end
end
end
then this code is added to the update method in Interpreter:
if @wc_count > 0
# Decrease wait count
@wc_count -= 1
if $game_player.moving?
@wc_count = 0
@cutting = false
$game_player.step_disable
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
$game_player.refresh
end
return
end
if @cutting == true
ctree = Wcconfig::tree_setup(@tree)
if @wc_count == 0
$game_player.step_disable
@cutting = false
for i in 0...$game_party.actors.size
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
actor = $game_party.actors[i]
actor.wcexp += ctree[2]
$game_player.refresh
end
end
end
end
the first code that is the initial call is also inside interpreter and the timer in the update acts corectly so it is definatly setting it to true, i just dont understand why its not picking up that the value is true in the code that changes the graphic :/
@kk20 i know that there was a print function there, i left it in so the value would come up on screen :P
To be honest, your whole approach is flawed. Using the Interpreter for this is a very bad idea, and really doesn't make any sense.
All three of these code snippets are in the Interpreter class? Also, when does 'add_hatchet_sprite' even get called?
Side note, when you do 'inter = Interpreter.new' you are calling an entirely new object with its own variables (you are not calling the "currently running right now" Interpreter--you're making a brand new one). Since @cutting is only being set to true when method 'hacking' is called, inter.cutting is either nil or false. It's hard to pinpoint where the solution can be made when I don't even know the process of how these methods are being called.
ok here is both code segments, the one that draws the tools over the actor:
module Tool
module_function
#--------------------------------------------------------------------------
# * Update Equipment
#--------------------------------------------------------------------------
def tool_update
@tool = Array.new
for i in 0..$game_party.actors.size
@tool[i+1] = []
end
#========================================================================
# ** C O N F I G U R A T I O N S Y S T E M ** #
#========================================================================
add_pickaxe_sprite("pickaxe")
add_hatchet_sprite("hatchet")
#========================================================================
# **** E N D O F C O N F I G U R A T I O N S Y S T E M **** #
#========================================================================
#------------------------------------------------------------------------
# * Equipment Functions
#------------------------------------------------------------------------
RPG::Cache.clear
return if $game_party == nil
for i in 0...$game_party.actors.size
for img in @tool[i+1]
bitmap = RPG::Cache.character($game_party.actors[i].character_name,
$game_party.actors[i].character_hue)
if img!=true and img!=false
add_tool(bitmap,img,i)
end
end
end
end
#--------------------------------------------------------------------------
# * Add Equipment
# sprite : Original sprite bitmap
# to_add : Equipment characterset
# character : Member in party
#--------------------------------------------------------------------------
def add_tool(sprite, to_add, character)
return if $game_party == nil
bmp = Sprite.new
bmp.visible = false
bmp.bitmap = RPG::Cache.character(to_add,
$game_party.actors[character].character_hue)
color = bmp.bitmap.get_pixel(0, 0)
x = sprite.width
y = sprite.height
if @tool[0]
x = x/4
y = y/4
end
for i in 0..x
for j in 0..y
color_get = bmp.bitmap.get_pixel(i, j)
if color_get != color
sprite.set_pixel(i, j ,color_get)
end
end
end
bmp = nil
end
#--------------------------------------------------------------------------
# * Add Pickaxe Sprite
# sprite : Pickaxe characterset
#--------------------------------------------------------------------------
def add_pickaxe_sprite(sprite)
inter = Interpreter.new
return if $game_party == nil
if $mining == true
for i in 0...$game_party.actors.size
@tool[i+1].push(sprite)
end
end
end
#--------------------------------------------------------------------------
# * Add Hatchet Sprite
# sprite : hatchet characterset
#--------------------------------------------------------------------------
def add_hatchet_sprite(sprite)
inter = Interpreter.new
return if $game_party == nil
if inter.cutting == true
for i in 0...$game_party.actors.size
@tool[i+1].push(sprite)
end
end
end
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :visual_transfer # Equipment changed in field switch
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias pickaxe_initialize initialize
def initialize
# Perform the original call
pickaxe_initialize
@visual_transfer = false # Equipment changed in field
end
end
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. Its functions include event starting
# determinants and map scrolling. Refer to "$game_player" for the one
# instance of this class.
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias visual_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Do not perform during equipment transfer
return if $game_temp.visual_transfer == true
# Perform the original call
visual_update
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias visual_update update
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Perform the original call
visual_update
# Turns equipment transfer system off
$game_temp.visual_transfer = false if $game_temp.visual_transfer == true
end
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :character_hue
end
#==============================================================================
# ** 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_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias visual_setup setup
#--------------------------------------------------------------------------
# * Setup
# actor_id : actor ID
#--------------------------------------------------------------------------
def setup(actor_id)
# Perform the original call
visual_setup(actor_id)
@character_hue = (@character_hue+1)%256
end
end
then this one is is everything else, the calls are right at the bottom:
module Wcconfig
def self.tree_setup(tree)
return case tree
#when TREE_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
when 1 then [60, 100, 5, 1, 1]
when 2 then [40, 100, 10, 2, 5]
else ''
end
end
end
module Mineconfig
def self.rock_setup(rock)
return case rock
#when ROCK_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
when 1 then [60, 100, 5, 1, 1]
when 2 then [40, 100, 10, 2, 5]
else ''
end
end
end
#---------------------------------------------------------------------------
# *create new skills
#---------------------------------------------------------------------------
class Game_Actor
attr_reader :minelevel # mining level
attr_accessor :mineexp # mining exp
attr_reader :wclevel # woodcutting level
attr_accessor :wcexp # woodcutting exp
#--------------------------------------------------------------------------
alias setup_mod setup
def setup(actor_id)
setup_mod(actor_id)
@minelevel = 1
@mineexp_list = Array.new(101)
make_mineexp_list
@mineexp = @mineexp_list[@minelevel]
#-------------------------------------
@wclevel = 1
@wcexp_list = Array.new(101)
make_wcexp_list
@wcexp = @wcexp_list[@wclevel]
end
#--------------------------------------------------------------------------
# * CALCULATE mine XP
#--------------------------------------------------------------------------
def make_mineexp_list
actor = $data_actors[@actor_id]
@mineexp_list[1] = 0
@mineexp_list[2] = 35 # Level 2 requires 35 exp
for i in 3..100 # Now let's use an equation to do the rest of the exp values
if i > actor.final_level
@mineexp_list[i] = 0
else
@mineexp_list[i] = (35*(i-1) + @mineexp_list[i-1]) * 2
end
end
end
#--------------------------------------------------------------------------
# * Change mine EXP
# mineexp : new mine xp
#--------------------------------------------------------------------------
def mineexp=(mineexp)
@mineexp = [[mineexp, 9999999].min, 0].max
# Level up
while @mineexp >= @mineexp_list[@minelevel+1] and @mineexp_list[@minelevel+1] > 0
@minelevel += 1
end
# Level down
while @mineexp < @mineexp_list[@minelevel]
@minelevel -= 1
end
end
#--------------------------------------------------------------------------
# * Get mine EXP String
#--------------------------------------------------------------------------
def mineexp_s
return @mineexp_list[@minelevel+1] > 0 ? @mineexp.to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Next Level mine EXP String
#--------------------------------------------------------------------------
def next_mineexp_s
return @mineexp_list[@minelevel+1] > 0 ? @mineexp_list[@minelevel+1].to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Until Next Level mine EXP String
#--------------------------------------------------------------------------
def next_rest_mineexp_s
return @mineexp_list[@minelevel+1] > 0 ?
(@mineexp_list[@minelevel+1] - @mineexp).to_s : "-------"
end
#--------------------------------------------------------------------------
# * CALCULATE WC XP
#--------------------------------------------------------------------------
def make_wcexp_list
actor = $data_actors[@actor_id]
@wcexp_list[1] = 0
@wcexp_list[2] = 35 # Level 2 requires 35 exp
for i in 3..100 # Now let's use an equation to do the rest of the exp values
if i > actor.final_level
@wcexp_list[i] = 0
else
@wcexp_list[i] = (35*(i-1) + @wcexp_list[i-1]) * 2
end
end
end
#--------------------------------------------------------------------------
# * Change WC EXP
# wcexp : new WC EXP
#--------------------------------------------------------------------------
def wcexp=(wcexp)
@wcexp = [[wcexp, 9999999].min, 0].max
# Level up
while @wcexp >= @wcexp_list[@wclevel+1] and @wcexp_list[@wclevel+1] > 0
@wclevel += 1
end
# Level down
while @wcexp < @wcexp_list[@wclevel]
@wclevel -= 1
end
end
#--------------------------------------------------------------------------
# * Get WC EXP String
#--------------------------------------------------------------------------
def wcexp_s
return @wcexp_list[@wclevel+1] > 0 ? @wcexp.to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Next Level WC EXP String
#--------------------------------------------------------------------------
def next_wcexp_s
return @wcexp_list[@wclevel+1] > 0 ? @wcexp_list[@wclevel+1].to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Until Next Level WC EXP String
#--------------------------------------------------------------------------
def next_rest_wcexp_s
return @wcexp_list[@wclevel+1] > 0 ?
(@wcexp_list[@wclevel+1] - @wcexp).to_s : "-------"
end
end
#---------------------------------------------------------------------------
# *class Interpreter(adds timers and conditions)
#---------------------------------------------------------------------------
class Interpreter
attr_accessor :mining
attr_accessor :cutting
attr_accessor :old_graphic
alias clear_mod clear
def clear
@wc_count = 0
@mine_count = 0
clear_mod
end
alias update_mod update
def update
update_mod
a = $game_actors[1]
if @mine_count > 0
# Decrease wait count
@mine_count -= 1
if $game_player.moving?
@mine_count = 0
@mining = false
$mining = false
$game_player.step_disable
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
$game_player.refresh
end
return
end
if @mining == true
crock = Mineconfig::rock_setup(@rock)
if @mine_count == 0
$game_player.step_disable
@mining = false
$mining = false
for i in 0...$game_party.actors.size
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
actor = $game_party.actors[i]
actor.mineexp += crock[2]
$game_player.refresh
end
end
end
if @wc_count > 0
# Decrease wait count
@wc_count -= 1
if $game_player.moving?
@wc_count = 0
@cutting = false
$game_player.step_disable
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
$game_player.refresh
end
return
end
if @cutting == true
ctree = Wcconfig::tree_setup(@tree)
if @wc_count == 0
$game_player.step_disable
@cutting = false
for i in 0...$game_party.actors.size
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
actor = $game_party.actors[i]
actor.wcexp += ctree[2]
$game_player.refresh
end
end
end
end
def rock=(rock)
@rock = rock
end
def tree=(tree)
@tree = tree
end
#--------------------------------------------------------------------------
# *my call when mining
#--------------------------------------------------------------------------
def mining
a = $game_actors[1]
@old_graphic = a.character_name
mine_graphic = a.character_name + "_mine"
a.set_graphic(mine_graphic, a.character_hue, a.battler_name, a.battler_hue)
crock = Mineconfig::rock_setup(@rock)
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.minelevel >= crock[4]
@mining = true
$mining = true
@mine_count = crock[0] * 2 - 1
#last_Minelevel = actor.minelevel
#gainitemhere
Tool.tool_update
$game_temp.visual_transfer = true
$game_player.step_enable
$game_player.refresh
else
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
end
end
end
def my_call2
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
actor.mineexp += 100
$game_player.refresh
end
end
#--------------------------------------------------------------------------
# *my call when cutting a tree
#--------------------------------------------------------------------------
def hacking
a = $game_actors[1]
@old_graphic = a.character_name
wc_graphic = a.character_name + "_mine"
a.set_graphic(wc_graphic, a.character_hue, a.battler_name, a.battler_hue)
ctree = Wcconfig::tree_setup(@tree)
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
if actor.wclevel >= ctree[4]
@cutting = true
@wc_count = ctree[0] * 2 - 1
#last_wclevel = actor.wclevel
#gainitemhere
Tool.tool_update
$game_temp.visual_transfer = true
$game_player.step_enable
$game_player.refresh
else
a.set_graphic(@old_graphic, a.character_hue, a.battler_name, a.battler_hue)
end
end
end
def my_call3
for i in 0...$game_party.actors.size
actor = $game_party.actors[i]
actor.wcexp += 100
$game_player.refresh
end
end
end
#----------------------------------------------------------------------------
# *Game player (activate/deactivate step_anime)
#----------------------------------------------------------------------------
class Game_Player
def step_enable
@step_anime = true
end
def step_disable
@step_anime = false
end
end
add_hatchet_sprite is called when Tool.tool_update is called, i understand that im creating a new Interpreter, so how would i get the values from the already existing one? i can do it with global variables but i know thats it best of to avoid them
@ forever zero i built my calls up in interpreter because i knew how to call them from there, i have learnt how to actually call them from another class so i can easily move them over but as for the methods i added to the update method, should i keep them there or just allias scene_map to call a custom update method?
The only solution I can think of is to make variables be passed on as arguments to other methods or by putting all the related methods under the same class. Honestly though, I can't understand what is going on. For example, this makes no sense to me:
def add_tool(sprite, to_add, character)
return if $game_party == nil
bmp = Sprite.new
bmp.visible = false
bmp.bitmap = RPG::Cache.character(to_add,
$game_party.actors[character].character_hue)
color = bmp.bitmap.get_pixel(0, 0)
x = sprite.width
y = sprite.height
if @tool[0]
x = x/4
y = y/4
end
for i in 0..x
for j in 0..y
color_get = bmp.bitmap.get_pixel(i, j)
if color_get != color
sprite.set_pixel(i, j ,color_get)
end
end
end
bmp = nil
end
I understand you're trying to learn scripting, but I really think you are over complicating something that sounds like it could be easily done with eventing.
what that part of the script is doing is it adds to the character sprite when you are mining or woodcutting, ie, overlaying a hatchet for example, i actually came up with that code from reading through someones visual equipment script, it works how i want it to, even though it could probably be done easier, and yes i could probably do it all with eventing, but for how i want it to work it would require alot of eventing, also i cant show the lvls etc under a window if i create it all in an event.
so how would i pass them of as arguments to other methods?
if you want to see how its all works i have a working project here: http://www.mediafire.com/?7ze8sbwfz1aw8vx
With a lot of freetime and sheer boredom, I whipped this up for you. It does everything your demo does but simplifies it.
=begin
------------
HOW TO USE:
------------
In an event, use a script call and by putting one of the following:
$game_party.cut_wood(id)
$game_party.mine_rock(id)
Where 'id' is the type of wood/rock you want to cut/mine depending on the
values configured in the Configuration below.
The script processes the animation and adds the EXP upon successful harvest.
=end
#---------------------------------------------------------------------------
# Configuration for different types of trees and rocks to cut and mine.
# Defines how long it takes to cut/mine, EXP gained, and level requirement.
#---------------------------------------------------------------------------
module Config
Hatchet_spr = 'hatchet'
Pickaxe_spr = 'pickaxe'
def self.tree_setup(tree)
return case tree
#when TREE_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
when 1 then [60, 100, 5, 1, 1]
when 2 then [40, 100, 10, 2, 5]
else ''
end
end
def self.rock_setup(rock)
return case rock
#when ROCK_ID then [WAIT_TIME, EXP_GAINED, ITEM_GAINED, LEVEL_REQUIRED]
when 1 then [60, 100, 5, 1, 1]
when 2 then [40, 100, 10, 2, 5]
else ''
end
end
end
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#
# E N D C O N F I G U R A T I O N
#
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
#---------------------------------------------------------------------------
# * Game Actor
# Creates woodcutting and mining attributes to the actor. Sets up the EXP chart
# as well as set/get methods for their levels and EXP.
#---------------------------------------------------------------------------
class Game_Actor
attr_reader :minelevel # mining level
attr_accessor :mineexp # mining exp
attr_reader :wclevel # woodcutting level
attr_accessor :wcexp # woodcutting exp
#--------------------------------------------------------------------------
alias setup_mod setup
def setup(actor_id)
setup_mod(actor_id)
@minelevel = 1
@mineexp_list = Array.new(101)
make_mineexp_list
@mineexp = @mineexp_list[@minelevel]
#-------------------------------------
@wclevel = 1
@wcexp_list = Array.new(101)
make_wcexp_list
@wcexp = @wcexp_list[@wclevel]
end
#--------------------------------------------------------------------------
# * CALCULATE mine XP
#--------------------------------------------------------------------------
def make_mineexp_list
actor = $data_actors[@actor_id]
@mineexp_list[1] = 0
@mineexp_list[2] = 35 # Level 2 requires 35 exp
for i in 3..100 # Now let's use an equation to do the rest of the exp values
if i > actor.final_level
@mineexp_list[i] = 0
else
@mineexp_list[i] = (35*(i-1) + @mineexp_list[i-1]) * 2
end
end
end
#--------------------------------------------------------------------------
# * Change mine EXP
# mineexp : new mine xp
#--------------------------------------------------------------------------
def mineexp=(mineexp)
@mineexp = [[mineexp, 9999999].min, 0].max
# Level up
while @mineexp >= @mineexp_list[@minelevel+1] and @mineexp_list[@minelevel+1] > 0
@minelevel += 1
end
# Level down
while @mineexp < @mineexp_list[@minelevel]
@minelevel -= 1
end
end
#--------------------------------------------------------------------------
# * Get mine EXP String
#--------------------------------------------------------------------------
def mineexp_s
return @mineexp_list[@minelevel+1] > 0 ? @mineexp.to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Next Level mine EXP String
#--------------------------------------------------------------------------
def next_mineexp_s
return @mineexp_list[@minelevel+1] > 0 ? @mineexp_list[@minelevel+1].to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Until Next Level mine EXP String
#--------------------------------------------------------------------------
def next_rest_mineexp_s
return @mineexp_list[@minelevel+1] > 0 ?
(@mineexp_list[@minelevel+1] - @mineexp).to_s : "-------"
end
#--------------------------------------------------------------------------
# * CALCULATE WC XP
#--------------------------------------------------------------------------
def make_wcexp_list
actor = $data_actors[@actor_id]
@wcexp_list[1] = 0
@wcexp_list[2] = 35 # Level 2 requires 35 exp
for i in 3..100 # Now let's use an equation to do the rest of the exp values
if i > actor.final_level
@wcexp_list[i] = 0
else
@wcexp_list[i] = (35*(i-1) + @wcexp_list[i-1]) * 2
end
end
end
#--------------------------------------------------------------------------
# * Change WC EXP
# wcexp : new WC EXP
#--------------------------------------------------------------------------
def wcexp=(wcexp)
@wcexp = [[wcexp, 9999999].min, 0].max
# Level up
while @wcexp >= @wcexp_list[@wclevel+1] and @wcexp_list[@wclevel+1] > 0
@wclevel += 1
end
# Level down
while @wcexp < @wcexp_list[@wclevel]
@wclevel -= 1
end
end
#--------------------------------------------------------------------------
# * Get WC EXP String
#--------------------------------------------------------------------------
def wcexp_s
return @wcexp_list[@wclevel+1] > 0 ? @wcexp.to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Next Level WC EXP String
#--------------------------------------------------------------------------
def next_wcexp_s
return @wcexp_list[@wclevel+1] > 0 ? @wcexp_list[@wclevel+1].to_s : "-------"
end
#--------------------------------------------------------------------------
# * Get Until Next Level WC EXP String
#--------------------------------------------------------------------------
def next_rest_wcexp_s
return @wcexp_list[@wclevel+1] > 0 ?
(@wcexp_list[@wclevel+1] - @wcexp).to_s : "-------"
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
# *Game_Player (activate/deactivate step_anime)
# Also processes the action of cutting and mining
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
class Game_Player < Game_Character
attr_accessor :step_anime, :wc_count, :mine_count, :character_name
def initialize
super
@wc_count, @mine_count = 0, 0
end
alias call_update_after_counting_down_timers update
def update
if @wc_count > 0 or @mine_count > 0
super
# A direction was pressed or canceled
if Input.dir4 != 0 or Input.trigger?(Input::B)
@wc_count, @mine_count = 0, 0
$game_party.finalize(false) # Failed to complete task
return
end
@wc_count -= 1 if @wc_count > 0
@mine_count -= 1 if @mine_count > 0
# Call the last steps when cutting/mining completes
$game_party.finalize(true) if (@wc_count == 0 and @mine_count == 0)
else
call_update_after_counting_down_timers
end
end
end
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
# *Game_Party
# Controls the majority of cutting/mining functions
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
class Game_Party
attr_accessor :cutting, :mining
alias init_before_cutting_mining initialize
def initialize
init_before_cutting_mining
@cutting = false
@mining = false
@object = nil
end
def cut_tree(id)
@object = Config.tree_setup(id)
@actors.each{|actor| $game_player.wc_count = (@object[0] * 2 - 1) if actor.wclevel >= @object[4] }
return if $game_player.wc_count == 0
@cutting = true
player = @actors[0]
mine_graphic = player.character_name + "_mine"
$game_player.character_name = mine_graphic
player.set_graphic(mine_graphic, player.character_hue, player.battler_name, player.battler_hue)
$game_player.step_anime = true
end
def mine_rock(id)
@object = Config.rock_setup(id)
@actors.each{|actor| $game_player.mine_count = (@object[0] * 2 - 1) if actor.minelevel >= @object[4] }
return if $game_player.mine_count == 0
@mining = true
player = @actors[0]
mine_graphic = player.character_name + "_mine"
$game_player.character_name = mine_graphic
player.set_graphic(mine_graphic, player.character_hue, player.battler_name, player.battler_hue)
$game_player.step_anime = true
end
def finalize(task_completed)
type = 1 if @cutting
type = 2 if @mining
player = @actors[0]
orig_name = player.character_name.split('_mine')
$game_player.character_name = orig_name[0]
player.set_graphic(orig_name[0], player.character_hue, player.battler_name, player.battler_hue)
$game_player.step_anime = false
@cutting, @mining = false, false
return unless task_completed
# Reward EXP to the actors with high enough levels
if type == 1
@actors.each{|a| a.wcexp += @object[2] if a.wclevel >= @object[4] }
else #type == 2
@actors.each{|a| a.mineexp += @object[2] if a.minelevel >= @object[4] }
end
end
end
#==============================================================================
# ** Sprite_Character
# Editted to include the hatchet and pickaxe sprites
#==============================================================================
class Sprite_Character < RPG::Sprite
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
if @character_name == $game_player.character_name and
($game_party.cutting or $game_party.mining)
RPG::Cache.clear
type = ($game_party.cutting ? Config::Hatchet_spr : Config::Pickaxe_spr)
src_bitmap = RPG::Cache.character(type, 0)
self.bitmap.blt(0, 0, src_bitmap, Rect.new(0,0,src_bitmap.width,src_bitmap.height))
end
@cw = bitmap.width / 4
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
Hopefully this can help you out. ;)
wow, you = awsome +1 ;), that is alot simplified to the way i went about it, but im slowly getting there, in the meantime i have been trying to randomize the wc_count and mine_count, as you can see i had an unused number in the config array, so looking at the array, 0 is 60 and 1 is 100, so i want it to randomize the value between this value, i found a way to randomize a number through a guide but i cant seem to get it to work, i have tried it the following way:
@object = Config.rock_setup(id)
randomizer = rand(@object[0]...@object[1])
then i set the value of the count to randomizer, but i get an error saying cannot convert range into integer, but say i just place a single number into the brackets, it randomizes it between 0 and that number, any idea how i can get it to work how i want?
I'm pretty sure something like that doesn't exist. A quick Google search (or some good ol' problem solving) came up with this solution:
first + rand(last + 1 - first)
So, to rewrite it into your script:
@object = Config.rock_setup(id)
randomizer = @object[0] + rand(@object[1] + 1 - @object[0])
60 + rand(101-60) = 60 + rand(41) = {60 .. 100}
cool thanks man, this is the link i got my information from: http://www.codeodor.com/index.cfm/2007/3/25/Ruby-random-numbers/1042
im not sure which version rmxp runs maybe its not the right one for the method i was trying to use, thanks again :D just reviewing how you added the tool to the sprite, that bit is what got me stumped looking at that code i was like :O.o:
RPG Maker XP uses 1.8.1 thanks to looking at the ARC forums. I forgot too :P
Yeah, drawing the hatchet/pickaxe took me a while to figure out--I'm not entirely sure what I did either, but I can understand it now. Essentially it just takes the hatchet/pickaxe character sprite sheet and throws it on top of the character-mining sprite (lolduh), but you must call RPG::Cache.clear so that the images don't constantly keep overlapping.
Anyways, good luck. :haha: