Hey guys,
I've been using this Crafting Script that is a lot like Minecraft, but the only issue I have with it is that, there's no requirements for what you can and can't craft. It would be nice to have recipes you can learn or even a certain level, but instead everything is just available to you from the get-go.
What I'm trying to add is, If a variable, let's say Blacksmithing level is >2, then it'll let you create the item, additionally, it will add another variable (experience), to increase that blacksmithing level (this can be done out of the script, but aslong as it increases the variable).
I've tried having a condition for each item, like for Dagger, making an if statement for if variable is >2, then the recipe will exist. But I kept getting undefined method (most likely since $game_variables hasn't been defined yet by the game).
Any suggestions if this script could be altered? Pasting it below.
I've been using this Crafting Script that is a lot like Minecraft, but the only issue I have with it is that, there's no requirements for what you can and can't craft. It would be nice to have recipes you can learn or even a certain level, but instead everything is just available to you from the get-go.
What I'm trying to add is, If a variable, let's say Blacksmithing level is >2, then it'll let you create the item, additionally, it will add another variable (experience), to increase that blacksmithing level (this can be done out of the script, but aslong as it increases the variable).
I've tried having a condition for each item, like for Dagger, making an if statement for if variable is >2, then the recipe will exist. But I kept getting undefined method (most likely since $game_variables hasn't been defined yet by the game).
Any suggestions if this script could be altered? Pasting it below.
Ruby:
#==============================================================================#
# • CRAFTING SYSTEM • #
#==============================================================================#
# Autor: Sidhenidon #
# Versão: 1.1 #
#==============================================================================#
module Craft
Vocab = {}
Vocab['remove'] = '<Remove>' #texto que aparece na opção de remover.
Vocab['result'] = 'Result'
Results = [] #Não altere nem apague.
Comb = [] #Não altere nem apague.
ShowResult = true #Mostrar o que a combinação atual gera antes de confirmar?
Smoothness = 10 #Suavidade do movimento do grid ao formar um item
StackX = 29 #Quando mais de um item for criado, qual distância X entre cada ícone
StackY = 0 # Y
#==============================================================================#
# LISTA DE COMBINAÇõES #
#==============================================================================#
# Axe #
height = 3 #height do item. modifique à vontade.
width = 2 #width do item. modifique à vontade.
combination = ['i2','i2', #form a rectangle or square with the
nil,'i8', #height e width acima.
nil,'i8']
Results.push(['w1']) #itens que são recebidos. Separe por vírgulas.
Comb.push([width,height,combination]) #não altere nem apague.
# VARETA #
height = 2 #height do item. modifique à vontade.
width = 1 #width do item. modifique à vontade.
combination = ['i1', #forme um retângulo ou quadrado com a
'i1'] #height e width acima.
Results.push(['i8','i8'])
Comb.push([width,height,combination]) #não altere nem apague.
# Cut ALOE #
height = 1
width = 2
combination = ['i10','w2']
Results.push(['w2','i11','i12'])
Comb.push([width,height,combination])
# Dagger #
height = 1
width = 1
combination = ['i45']
Results.push(['w36'])
Comb.push([width,height,combination])
# Axe #
height = 1
width = 2
combination = [nil,'i45']
Results.push(['w36'])
Comb.push([width,height,combination])
# CORTAR ALOE INVERTIDO #
height = 1
width = 2
combination = ['w2','i10']
Results.push(['w2','i11','i12'])
Comb.push([width,height,combination])
# POÇÃO COM RAIZ DE ALOE #
height = 2
width = 1
combination = ['i11','i14']
Results.push(['i15'])
Comb.push([width,height,combination])
# POÇÃO ERRADA #
height = 2
width = 1
combination = ['i12','i14']
Results.push(['i16'])
Comb.push([width,height,combination])
# VARA #
height = 3
width = 3
combination = ['i8', nil,nil ,
'i5','i8',nil ,
'i5',nil ,'i8',
]
Results.push(['w3'])
Comb.push([width,height,combination])
# DECOMPOSIÇÃO DE ROUPA #
height = 1
width = 1
combination = ['a14']
Results.push(['i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5','i5'])
Comb.push([width,height,combination])
# POÇÃO ERRADA #
height = 2
width = 1
combination = ['i17','i14']
Results.push(['i16'])
Comb.push([width,height,combination])
# PÃO #
height = 2
width = 1
combination = ['i18','i14']
Results.push(['i19'])
Comb.push([width,height,combination])
# POÇÃO ERRADA #
height = 2
width = 1
combination = ['i19','i14']
Results.push(['i16'])
Comb.push([width,height,combination])
#==============================================================================#
# FIM DA LISTA DE COMBINAÇõES #
#==============================================================================#
end
class Scene_Crafting < Scene_Base
def initialize(gridsize=3)
@grid = gridsize
@in_use = {}
end
def start
super
@item_window = Window_CraftItem.new(0, 416, 544, 136)
@item_window.active = false
@item_window.opacity = 0
@craft_window = Window_Craft.new(@grid)
@craft_window.opacity = 0
@step = 0
@pop = nil
@pop_sprite = Sprite.new
@pop_sprite2 = Sprite.new
@preview = Sprite.new if Craft::ShowResult
update_showresult if Craft::ShowResult
create_menu_background
end
def refresh_in_use
@in_use = {}
@craft_window.craft.each{|item|
@in_use[item] = 0 if @in_use[item] == nil
@in_use[item] += 1}
end
def create_menu_background
@menuback_sprite = Sprite.new
@menuback_sprite.bitmap = $game_temp.background_bitmap
@menuback_sprite.bitmap.blt(0,0,Cache.system('Craft_BG'),Rect.new(0,0,544,416))
@menuback_sprite.z = @craft_window.z-1
update_menu_background
end
def terminate
super
dispose_menu_background
@item_window.dispose
@craft_window.dispose
@pop_sprite.dispose
@pop_sprite2.dispose
@preview.dispose if Craft::ShowResult
end
def create_pop_sprites
@pop_sprite.bitmap = Bitmap.new(@craft_window.width-32,@craft_window.height-32)
@pop_sprite.bitmap.blt(0,0,Graphics.snap_to_bitmap,Rect.new(@craft_window.x+16,@craft_window.y+16,@craft_window.width-32,@craft_window.height-32))
@pop_sprite.ox = (@pop_sprite.width)/2
@pop_sprite.oy = (@pop_sprite.height)/2
@pop_sprite.x,@pop_sprite.y = (@craft_window.x+16)+(@craft_window.width-32)/2,(@craft_window.y+16)+(@craft_window.height-32)/2
@pop_sprite.z = 9998
@pop_sprite2.bitmap = Bitmap.new(29+(@pop.size-1)*Craft::StackX,28+(@pop.size-1)*Craft::StackY)
idx = 0
for item in @pop
@pop_sprite2.bitmap.blt(0+idx*Craft::StackX,0+idx*Craft::StackY,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
@pop_sprite2.bitmap.blt(2+idx*Craft::StackX,2+idx*Craft::StackY,Cache.system('Iconset'),Rect.new(item.icon_index % 16 * 24, item.icon_index / 16 * 24, 24, 24))
idx += 1
end
@pop_sprite2.ox = @pop_sprite2.width/2
@pop_sprite2.oy = @pop_sprite2.height/2
@pop_sprite2.x = @pop_sprite.x
@pop_sprite2.y = @pop_sprite.y
@pop_sprite2.z = 9999
@pop_sprite2.opacity = 0
end
def update
super
update_menu_background
update_inventory_position
@craft_window.update
if @item_window.active
@item_window.update
update_item_selection
elsif @craft_window.active
update_craft_selection
elsif @pop != nil
case @step
when 0
shine ? @step = 1 : @step = 0
when 1
reduce ? @step = 2 : @step = 1
when 2
appear ? @step = 3 : @step = 2
when 3
Graphics.wait(60)
$scene = Scene_Map.new
end
end
end
def update_inventory_position
if @item_window.active
@item_window.y = [@item_window.y-[(280-@item_window.x).abs/Craft::Smoothness,1].max,280].max
else
@item_window.y = [@item_window.y+[(416-@item_window.y).abs/Craft::Smoothness,1].max,416].min
end
end
def shine
@pop_sprite.tone = Tone.new(@pop_sprite.tone.red+2,@pop_sprite.tone.green+2,@pop_sprite.tone.blue+2)
@preview.opacity -= 4 if Craft::ShowResult
@pop_sprite.x = [@pop_sprite.x+[(@pop_sprite.x-272).abs/Craft::Smoothness,1].max,272].min
@pop_sprite2.x = @pop_sprite.x
return true if @pop_sprite.tone.red == 255
return false
end
def reduce
sizex = @pop_sprite.zoom_x
sizey = @pop_sprite.zoom_y
if @pop_sprite.width*@pop_sprite.zoom_x > @pop_sprite2.width
@pop_sprite.zoom_x = (@pop_sprite.zoom_x-0.05)
end
if @pop_sprite.width*@pop_sprite.zoom_x < @pop_sprite2.width
@pop_sprite.zoom_x = (@pop_sprite.zoom_x+0.05)
end
if @pop_sprite.height*@pop_sprite.zoom_y > @pop_sprite2.height
@pop_sprite.zoom_y = (@pop_sprite.zoom_y-0.05)
end
if @pop_sprite.height*@pop_sprite.zoom_y < @pop_sprite2.height
@pop_sprite.zoom_y = (@pop_sprite.zoom_y+0.05)
end
return true if sizex == @pop_sprite.zoom_x and sizey == @pop_sprite.zoom_y
return false
end
def appear
@pop_sprite2.opacity += 3
@pop_sprite.opacity -= 3
return true if @pop_sprite2.opacity == 255
return false
end
def update_craft_selection
if Input.trigger?(Input::B)
if compare_crafting(@grid)
Sound.play_decision
create_pop_sprites
@item_window.active = false
@craft_window.active = false
@craft_window.visible = false
else
Sound.play_cancel
$scene = Scene_Map.new
end
elsif Input.trigger?(Input::C)
Sound.play_decision
@item_window.active = true
@craft_window.active = false
end
end
def update_item_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@craft_window.active = true
@item_window.active = false
elsif Input.trigger?(Input::C)
refresh_in_use
@in_use[@item_window.item] = 0 if @in_use[@item_window.item] == nil
if ($game_party.item_number(@item_window.item)-@in_use[@item_window.item] > 0) or @item_window.item == nil
Sound.play_decision
@craft_window.craft[@craft_window.index] = @item_window.item
@craft_window.refresh
update_showresult if Craft::ShowResult
else
Sound.play_cancel
end
@craft_window.active = true
@item_window.active = false
end
end
def update_showresult
preview = compare_crafting(@grid,true)
case preview
when false
draw_preview(nil)
when Integer
draw_preview(preview)
end
end
def draw_preview(idx)
@preview.dispose if [email protected]?
if idx == nil
@preview = Sprite.new
@preview.bitmap = Bitmap.new(29,28)
@preview.bitmap.blt(0,0,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
@preview.x = 257+@craft_window.width/2
@preview.y = (@craft_window.y+@craft_window.height/2)-(@preview.height/2)
@preview.z = 9999
return
end
itemlist = []
for item in Craft::Results[idx]
type = item.scan(/[iwa]/)[0]
case type
when 'i'
itemlist.push($data_items[item.scan(/[0-9]+/)[0].to_i])
when 'a'
itemlist.push($data_armors[item.scan(/[0-9]+/)[0].to_i])
when 'w'
itemlist.push($data_weapons[item.scan(/[0-9]+/)[0].to_i])
end
end
@preview = Sprite.new
@preview.bitmap = Bitmap.new(29+(itemlist.size-1)*Craft::StackX,28+(itemlist.size-1)*Craft::StackY)
index = 0
for item in itemlist
@preview.bitmap.blt(0+index*Craft::StackX,0+index*Craft::StackY,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
@preview.bitmap.blt(2+index*Craft::StackX,2+index*Craft::StackY,Cache.system('Iconset'),Rect.new(item.icon_index % 16 * 24, item.icon_index / 16 * 24, 24, 24))
index += 1
end
@preview.x = 257+@craft_window.width/2
@preview.y = (@craft_window.y+@craft_window.height/2)-(@preview.height/2)
@preview.z = 9999
end
def compare_crafting(gridsize,preview=false)
@result = Array.new
@craft_window.craft.each{|item|
case item
when RPG::Item
@result.push("i#{item.id}")
when RPG::Armor
@result.push("a#{item.id}")
when RPG::Weapon
@result.push("w#{item.id}")
else
@result.push(nil)
end
}
for combination in Craft::Comb
next if combination[0] > @grid or combination[1] > @grid
table = []
for x in 0..@grid-1
array = []
for y in 0..@grid-1
array.push(@result[x*@grid+y])
end
table.push(array)
end
check = []
for x in 0..combination[1]-1
array = []
for y in 0..combination[0]-1
array.push(combination[2][x*combination[0]+y])
end
check.push(array)
end
checkline = 0
checkitem = 0
for line in 0..table.size-1
for itam in 0..table[line].size-1
if table[line][itam] == (check[checkline].is_a?(Array) ? check[checkline][checkitem] : nil)
next if check[checkline] == nil or table[line] == nil
next if check.size > table.size-line
next if check[checkline].size > table[line].size-itam
successcomb = Array.new
y = line
x = itam
checkline = 0
checkitem = 0
loop do
if (table[y].is_a?(Array) ? table[y][x] : nil) == (check[checkline].is_a?(Array) ? check[checkline][checkitem] : nil)
if x >= @grid-1
if y >= @grid-1
successcomb.push([y,x])
for y1 in 0..@grid-1
for x1 in 0..@grid-1
if !successcomb.include?([y1,x1])
if table[y1][x1] != nil
return false
end
end
end
end
if preview
return Craft::Comb.index(combination)
else
return craftit(Craft::Comb.index(combination))
end
break
else
successcomb.push([y,x])# unless (y > check.size-1 or x > check[checkline].size-1)
y += 1 ; x = itam
checkline += 1 ; checkitem = 0
end
else
successcomb.push([y,x])# unless (y > check.size-1 or x > check[checkline].size-1)
x += 1 ; checkitem += 1
end
else
break
end
end
end
end
end
end
return false
end
def craftit(idx)
@pop = []
for item in Craft::Results[idx]
type = item.scan(/[iwa]/)[0]
case type
when 'i'
$game_party.gain_item($data_items[item.scan(/[0-9]+/)[0].to_i],1)
@pop.push($data_items[item.scan(/[0-9]+/)[0].to_i])
when 'a'
$game_party.gain_item($data_armors[item.scan(/[0-9]+/)[0].to_i],1)
@pop.push($data_armors[item.scan(/[0-9]+/)[0].to_i])
when 'w'
$game_party.gain_item($data_weapons[item.scan(/[0-9]+/)[0].to_i],1)
@pop.push($data_weapons[item.scan(/[0-9]+/)[0].to_i])
end
end
for item in @craft_window.craft
$game_party.lose_item(item,1)
end
return true
end
end
class Window_Craft < Window_Selectable
attr_accessor :craft
def initialize(gridsize)
super(272-(gridsize*29+32)/2-(Craft::ShowResult ? (gridsize*29+32)/2 : 0), 203-(gridsize*29*3/4), gridsize*29+32, gridsize*29+32)
@column_max = gridsize
self.index = 0
@craft = Array.new
for i in 1..(gridsize*gridsize)
@craft.push(nil)
end
refresh
end
def item
return @data[self.index]
end
def refresh
@data = []
for item in @craft
@data.push(item)
end
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
def item_rect(index)
rect = Rect.new(0, 0, 0, 0)
rect.width = 29
rect.height = 28
rect.x = index % @column_max * (rect.width)
rect.y = index / @column_max * 28
return rect
end
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
self.contents.blt(rect.x,rect.y,Cache.system('Craft_slot'),Rect.new(0,0,29,28))
if item != nil
rect.width -= 4
draw_icon(item.icon_index, rect.x+2, rect.y+2, true)
end
end
end
class Window_CraftItem < Window_Selectable
def initialize(x, y, width, height)
super(x, y, width, height)
@column_max = 2
self.index = 0
refresh
end
def item
return @data[self.index]
end
def include?(item)
return false if item == nil
if $game_temp.in_battle
return false unless item.is_a?(RPG::Item)
end
return true
end
def enable?(item)
return true
end
def refresh
self.contents.fill_rect(0,0,self.width,self.height, Color.new(0,0,0,130))
@data = []
@data.push(nil)
for item in $game_party.items
@data.push(item)
end
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
number = $game_party.item_number(item)
enabled = enable?(item)
rect.width -= 4
#self.contents.fill_rect(rect.x+2,rect.y+2,rect.width-4,rect.height-4, Color.new(0,0,0,180))
draw_item_name(item, rect.x, rect.y, enabled)
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
else
#self.contents.fill_rect(rect.x+2,rect.y+2,rect.width-4,rect.height-4, Color.new(0,0,0,180))
self.contents.draw_text(rect, Craft::Vocab['remove'], 1)
end
end
def update_help
@help_window.set_text(item == nil ? "" : item.description)
end
end