03-05-2006, 01:00 PM
Mining Script
GoldenShadow
Mar 5, 2006
Introduction
First off, read the comments in the script! I didn't put them for nothing.
Even if you don't like to read, just do it! I will not help you if
the problem is already described in the comments
What do I need to run it?
These codes in Main:
You can change the name and size, but the variables must be present.
The script
Give me feedback, folks.
Peace.
GoldenShadow
Mar 5, 2006
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
Introduction
First off, read the comments in the script! I didn't put them for nothing.
Even if you don't like to read, just do it! I will not help you if
the problem is already described in the comments
What do I need to run it?
These codes in Main:
Code:
$fontface = "Arial"
$fontsize = 26
You can change the name and size, but the variables must be present.
The script
Code:
#==========================
# <> Mining Script Advanced Ver 1.0
# ==> You can delete all the comments except the copyright and creator info. Thanks.
# ==> Do not rip, repost or any other way of reproducing without proper credit. Thanks.
# ShadowClan Technologies © 2003-2006 - All rights reserved.
#---------------------------------------------------
# * How to use
# Make a new global variable named:
# $mining = Mining.new
# This is to be put in, say, Main or in a common event you only use once.
# Note that, if you do this in events, it'll reset all data each time
# and that's not what you like, now is it?
#
# * Making Materials
# First off, create a new item in the database.
# Go to an event or whatever it is that gives you Material information.
# For example, going to a blacksmith might get you the "Iron"-material by
# adding this codeline in the event:
# $mining.add_type("Iron", 1, "Scrapyard")
# The number 1 represents the mining area and the "Scrapyard" represents
# the place where to find the material.
# The syntax is:
# $mining.add_type("name", Map_ID, "map_name")
#
# * How to mine
# In an event, for example the scrapyard manager, you put:
# $scene = Scene_Mining.new
# This will load the mining scene. You can now see 2 new windows appear.
# The upper window shows whether you can mine on the place you're standing or not.
# The lower window shows the material in that area and the highscore for mining.
#
# * So, how can I put material to be found?
# Go to the Database and make a new map.
# Put in terrain tags on the places you'd like the material to be found.
# For example, on a rock, you'd probably put Terrain Tag 4/5 to find
# a total of 4/5 Rocks. For example, yah?
#
# * Can I mine multiple materials in one area?
# Theoreticly, yes. But it will mess up the lower window.
# Of course, I will upgrade this script for Multi-Material Support.
#
# * What is the 'highscore'
# It represents the biggest amount of material you've mined in that area.
# It's, litterly, a highscore.
#
# * Features Ver. 1.0
# - Pressing X (cancel) button goes to the Material Database.
# - Events are supported while in the Scene (You can talk to everyone etc)
# - Window showing amount, highscore and another window showing availability.
#
# I'll be upgrading this script so don't bug me for the Multi-Material support.
#---------------------------------------------------
# * Suggestions? ==> PM or post in the topic where this is posted.
# * Created by: GoldenShadow
# * Credits: None
#==========================
class Scene_Mining
def main
@spriteset = Spriteset_Map.new
@diamonds_window = Window_Diamonds.new
@message_window = Window_Message.new
@db_window = Window_Diamonds_DB.new
@db_window.active = @db_window.visible = false
@db_window.z = 9999
@db_window_info = Window_Diamonds_Info.new
@db_window_info.active = @db_window_info.visible = false
@db_window_info.z = 9900
@info_window = Window_Diamonds_Info2.new
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@spriteset.dispose
@diamonds_window.dispose
@message_window.dispose
@db_window.dispose
@db_window_info.dispose
@info_window.dispose
end
def update
@spriteset.update
@diamonds_window.update
@message_window.update
@db_window.update
@db_window_info.update
@info_window.update
@info_window.refresh
if @db_window.active
update_database
end
loop do
$game_map.update
$game_player.update
$game_system.update
$game_screen.update
$game_system.map_interpreter.update
unless $game_temp.player_transferring
break
end
transfer_player
if $game_temp.transition_processing
break
end
end
if $game_temp.message_window_showing
return
end
if Input.trigger?(Input::B) and @db_window.active == false
@db_window.refresh
@db_window.active = @db_window.visible = true
@db_window_info.active = @db_window_info.visible = true
return
elsif Input.trigger?(Input::A) and @db_window.active == false
calc_diamonds
if @diamonds > 0
$game_party.gain_item($mining.get_id($mining.type($game_map.map_id)), @diamonds)
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
$game_temp.message_text = "You acquired #{@diamonds} #{$mining.type($game_map.map_id)}"
@diamonds_window.refresh
return
else
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
$game_temp.message_text = "You acquired no #{$mining.type($game_map.map_id)}s"
@diamonds_window.refresh
return
end
end
end
def transfer_player
$game_temp.player_transferring = false
if $game_map.map_id != $game_temp.player_new_map_id
$game_map.setup($game_temp.player_new_map_id)
end
$game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
case $game_temp.player_new_direction
when 2 # down
$game_player.turn_down
when 4 # left
$game_player.turn_left
when 6 # right
$game_player.turn_right
when 8 # up
$game_player.turn_up
when 7 # upright
$game_player.turn_upright
end
$game_player.straighten
$game_map.update
@spriteset.dispose
@spriteset = Spriteset_Map.new
if $game_temp.transition_processing
$game_temp.transition_processing = false
Graphics.transition(20)
end
$game_map.autoplay
Graphics.frame_reset
Input.update
end
def update_database
if Input.trigger?(Input::C) or Input.trigger?(Input::B) or Input.trigger?(Input::Y)
$scene = Scene_Mining.new
end
end
def calc_diamonds
@diamonds = 0
if $mining.places[[$game_player.x, $game_player.y, $game_map.map_id]] == nil and $game_map.terrain_tag($game_player.x, $game_player.y) != 0
$mining.places[[$game_player.x, $game_player.y, $game_map.map_id]] = $game_map.terrain_tag($game_player.x, $game_player.y)
calc_diamonds
elsif $mining.places[[$game_player.x, $game_player.y, $game_map.map_id]] != nil and $game_map.terrain_tag($game_player.x, $game_player.y) != 0
tmp = $mining.places[[$game_player.x, $game_player.y, $game_map.map_id]]
@diamonds = rand(tmp)
$mining.places[[$game_player.x, $game_player.y, $game_map.map_id]] -= @diamonds
else
return
end
if @diamonds > $mining.highscore[$mining.type($game_map.map_id)]
$mining.highscore[$mining.type($game_map.map_id)] = @diamonds
end
end
end
class Window_Diamonds < Window_Base
def initialize
super(32, 480-128, 240, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.opacity = 160
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(4, 0, self.width-40, 32, "#{$mining.type($game_map.map_id)}: ×#{$game_party.item_number($mining.get_id($mining.type($game_map.map_id)))}")
self.contents.draw_text(4, 32, self.width-40, 32, "Highscore: ×#{$mining.highscore[$mining.type($game_map.map_id)]}")
end
end
class Mining
attr_accessor :highscore
attr_accessor :places
attr_accessor :type
attr_accessor :material_db
attr_accessor :area
def initialize
@type = {}
@places = {}
@highscore = {}
@area = {}
@material_db = []
@material_id = {}
end
def type(map_id)
return @type[map_id]
end
def add_type(type, map_id, map_name)
@type[map_id] = type
@material_db.push(type)
@area[type] = map_name
@highscore[type] = 0
for i in 1...$data_items.size
if $data_items[i].name == type
@material_id[type] = $data_items[i].id
end
end
end
def get_amount(type)
for i in 1...$data_items.size
if $data_items[i].name == type
return $game_party.item_number(i)
end
end
end
def get_area(type)
return @area[type]
end
def get_name(id)
return @material_db[id]
end
def get_id(type)
return @material_id[type]
end
end
class Window_Diamonds_DB < Window_Selectable
def initialize
super(0, 40, 640, 440)
self.opacity = 0
@column_max = 1
refresh
self.index = 0
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
@data = $mining.material_db
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
for i in 0...@item_max
draw_item(i)
end
else
self.index = -1
end
end
def draw_item(index)
item = @data[index]
number = $mining.get_amount(item)
area = $mining.get_area(item)
highscore = $mining.highscore[item]
self.contents.font.color = normal_color
x = 8
y = index * 32
w = self.width-40
if @data.size > 0
self.contents.draw_text(x, y, 140, 32, item.to_s, 0)
self.contents.draw_text(x + 134, y, 64, 32, number.to_s, 0)
self.contents.draw_text(x + 232, y, 64, 32, highscore.to_s, 0)
self.contents.draw_text(x + 354, y, 240, 32, area.to_s, 0)
else
self.contents.font.color = knockout_color
self.contents.draw_text(4, 64, self.width-40, 32, "Database empty", 1)
self.contents.font.color = normal_color
end
end
end
class Window_Diamonds_Info < Window_Base
def initialize
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
refresh
end
def refresh
self.contents.clear
self.contents.draw_text(6, 0, self.width-40, 32, "Material")
self.contents.draw_text(140, 0, self.width-40, 32, "Quantity")
self.contents.draw_text(240, 0, self.width-40, 32, "Highscore")
self.contents.draw_text(360, 0, self.width-40, 32, "Area")
rect = Rect.new(4, 32, 600, 1)
self.contents.fill_rect(rect, Color.new(255, 255, 255))
end
end
class Window_Diamonds_Info2 < Window_Base
def initialize
super(32, 32, 200, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.opacity = 160
refresh
end
def refresh
self.contents.clear
if $game_map.terrain_tag($game_player.x, $game_player.y) == 0
self.contents.draw_text(6, 0, self.width-40, 32, "Cannot mine here")
else
self.contents.draw_text(6, 0, self.width-40, 32, "Z-button to mine")
end
end
end
Give me feedback, folks.
Peace.