- Joined
- Jan 7, 2015
- Messages
- 34
- Reaction score
- 1
- First Language
- English
- Primarily Uses
I'm making a farming script because the few I can find don't fit my needs and aren't very elegant or flexible. I was working on this script a long time ago but I put it down because I was having a bunch of problems. I've asked for help on this site before but I'm always met with a bunch of irrelevant information. I need an expert because if I can't figure it out it's either a very simple mistake or a huge hole that takes a professional to fix. I'm working with RPG Maker VX Ace. The code I'm working with is supposed to work as follows: You activate an event with the name 'farmland', it prompts you to select a key item, you select an item and it checks to see if that item has a note that looks like <seed 1> where the number can represent an array of seeds corresponding to the number, if the item you selected has the <seed> tag return the number after it and use that as the seed parameter, check some of the seed's parameters against the player such as level and required items, I have a timer running in the background that keeps track of days, hours, seasons, ect. after a set amount of time it updates all events 'event_timer' and 'anim_stages' functions. Once the timer (hours_until_full) equals the seed :timer param mark the crop as grown and allow the player to harvest the appropriate items from the event with another event activation.
Right now I'm having a problem where the script doesn't wait until the player selects the key item. It just continues on with the code and throws a bunch of errors.
Also there appears to be a problem where the item isn't being read as a seed even though it has the note <seed 1>
the code I have so far is as follows:
Right now I'm having a problem where the script doesn't wait until the player selects the key item. It just continues on with the code and throws a bunch of errors.
Also there appears to be a problem where the item isn't being read as a seed even though it has the note <seed 1>
the code I have so far is as follows:
Code:
module FARM_PARAMS
VARIABLE = 21
end
FARMING_OBTAINED_STRING = '"Obtained \\\i[#{item.icon_index}] #{item.name} x#{amount}."'
FARMING_GATHERFAIL_STRING = "Failed to gather resource."
FARMING_LOWLEVEL_STRING = '"Level #{node_data[:level]} required."'
FARMING_TOOLREQ_STRING = '"Tool \\\i[#{item.icon_index}] #{item.name} required."'
Plant = {
#turnip
1 => {:name => "Turnip",
:item => [:item,17,[1,4]],
:level => 1,
:timer => 1, #in-game hours until grown
:base_chance => 75,
:max_chance => 100,
:chance_mod => 5,
:graphic => ["$Turnip",0],
:sound => ["Jump1",75,1,3]},
:persist => "false",
}
class Game_Event
alias farm_update update
alias gather_start start
alias farm_init setup_page
def setup_page(*args)
farm_init(*args)
@empty_plot = true
@days_to_grow = 0
@hours_until_full = 0
@plant_id = 0
end
def event_timer(rate)
if farm_data != nil
@hours_until_full += rate if @hours_until_full < farm_data[:timer].to_i
return farm_data[:timer].to_i - @hours_until_full
else
return 0
end
end
def farmland
@event.name.include?("Farmland")
end
def farm_data
Plant[@plant_id]
end
def start
farmland ? farm_start : gather_start
end
def grown?
if event_timer(0) <= 0 && @empty_plot == false
return true
else
return false
end
end
def anim_stages
if farm_data != nil
if @days_to_grow < farm_data[:timer].to_i / 4
@days_to_grow = 0
if @dir < 8
@dir += 2
end
@direction = dir
end
end
end
def farm_start
if @empty_plot == true
$game_message.add("What would I like to plant?")
$game_message.item_choice_variable_id = FARM_PARAMS::VARIABLE
return false if !Check_Seed?
end
if grown?
$game_party.gathering = true
if gather_success
item_d = farm_data[:item]
item = $data_items[item_d[1]] if item_d[0] == :item
item = $data_weapons[item_d[1]] if item_d[0] == :weapon
item = $data_armors[item_d[1]] if item_d[0] == :armor
msgbox("Invalid item category") unless item
amount = rand(item_d[2][1] - item_d[2][0]) + item_d[2][0]
$game_party.gain_item(item,amount)
$game_message.add(eval(FARMING_OBTAINED_STRING))
end
if farm_data[:sound]
farm_data[:sound][2].times do |i|
Audio.se_play("Audio/SE/" + farm_data[:sound][0],farm_data[:sound][1])
node_data[:sound][3].times do |i|
Graphics.update
SceneManager.scene.update
end
end
end
$game_party.gathering = false
end
end
def Check_Seed?
item = $data_items[$game_variables[FARM_PARAMS::VARIABLE]]
if item != nil
tag, id = item.note =~ /^<(seed) (\n)>/ ? [true, $1] : [false, nil]
if tag
@plant_id = id
if @plant_id != 0
return no_tool if !carrying_tool?
return no_level if farm_data[:level] > $game_party.highest_level
#persist = farm_data[:persist].to_s == 'true' ? true : false
graphic = farm_data[:graphic]
@character_name = graphic[0]
@character_index = graphic[1]
@days_to_grow = 0
@dir = 8
@direction = dir
@empty_plot == false
$game_message.add(farm_data[:name].to_string + " planted.")
end
return true
else
$game_message.add("This item isn't a seed")
@plant_id = 0
end
else
$game_message.add("No seed selected.")
return false
end
end
def carrying_tool?
if plant_id != nil
item_d = farm_data[:tool]
return true if item_d.nil?
item = $data_items[item_d[1]] if item_d[0] == :item
item = $data_weapons[item_d[1]] if item_d[0] == :weapon
item = $data_armors[item_d[1]] if item_d[0] == :armor
return $game_party.has_item?(item)
end
end
def unerase
@erased = false
refresh
end
def erased?; @erased == true; end
def event_id; @id; end
def no_level
$game_message.add(eval(FARMING_LOWLEVEL_STRING))
end
def no_tool
if plant_id != nil
item_d = farm_data[:tool]
item = $data_items[item_d[1]] if item_d[0] == :item
item = $data_weapons[item_d[1]] if item_d[0] == :weapon
item = $data_armors[item_d[1]] if item_d[0] == :armor
$game_message.add(eval(FARMING_TOOLREQ_STRING))
end
end
def gather_success
if plant_id != nil
empty_plot = true
chance = farm_data[:base_chance]
chance += farm_data[:chance_mod] * ($game_party.highest_level - farm_data[:level])
chance = [chance,farm_data[:max_chance]].min
if rand(100) < chance
return true
else
$game_message.add(FARMING_GATHERFAIL_STRING)
return false
end
end
end
end
class Game_Map
alias farm_set setup_events
alias farm_up update_events
def setup_events
farm_set
@events.each_value do |event|
next unless event.farmland
event.erase if event.event_timer(0) > 0
end
end
def update_events
farm_up
@events.each_value do |event|
next unless event.farmland && event.erased?
event.unerase if event.event_timer(0) == 0
end
end
end
class RPG::BaseItem
def ==(object)
return false if object.nil?
self.name == object.name && self.id == object.id && self.note == object.note
end
end
