Bag item menu

Ver o tópico anterior Ver o tópico seguinte Ir em baixo

Bag item menu

Mensagem  roberto em Sab Mar 13, 2010 7:21 pm

retirado da pagina do reino rpg :
Spoiler:
http://www.reinorpg.com/forum/index.php?topic=179.00
Créditos: Matte

Este script define quantos itens o personagem pode carregar. Ainda da a possibilidade de descartar itens.
Quando o limite de itens é ultrapassado, o jogador tem que excluir algum item obrigatoriamente para continuar.
Para usá-lo, crie uma nova classe acima do main e cole dentro, o script abaixo:
Spoiler:
#==============================================================================
# Game_Party
# Traduzido por Resource manager
#==============================================================================

class Game_Party
def gain_item(item_id, n)

if item_id == 40 # Numero id da 1° bag
$game_party.bag_size = 50 # maximo de itens que cabe na 1° bag
elsif item_id == 41 # Numero id da 2° bag
$game_party.bag_size = 100 # maximo de itens que cabe na 2° bag
elsif item_id == 42 # Numero id da 3° bag
$game_party.bag_size = 150 # maximo de itens que cabe na 3° bag

# Para adicionar mais bags, apenas copie e cole abaixo mais codigos iguais a este:
# elsif item_id == 43
# $game_party.bag_size = 200



else
if n < 0
@add_number = n
else
item_bag(n)
end
if item_id > 0
if n + @items_now > $game_party.bag_size and $data_items[item_id].element_set.include?(20)
$scene = Scene_Item.new(true)
$scene.remaining = n - @add_number
@items[item_id] = [[item_number(item_id) + n, 0].max, 999].min
@items_now += @add_number
else
@items[item_id] = [[item_number(item_id) + @add_number, 0].max, 999].min
@items_now += @add_number
$game_variables[99] = @add_number
end
end
end
end
#--------------------------------------------------------------------------
def gain_weapon(weapon_id, n, equip = false)
if equip
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
else
if n < 0
@add_number = n
else
item_bag(n)
end
if weapon_id > 0
@weapons[weapon_id] = [[weapon_number(weapon_id) + @add_number, 0].max, 99].min
@items_now += @add_number
$game_variables[99] = @add_number
end
end
end
#--------------------------------------------------------------------------
def gain_armor(armor_id, n, equip = false)
if equip
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
else
if n < 0
@add_number = n
else
item_bag(n)
end
if armor_id > 0
@armors[armor_id] = [[armor_number(armor_id) + @add_number, 0].max, 999].min
@items_now += @add_number
$game_variables[99] = @add_number
end
end
end
#--------------------------------------------------------------------------
def lose_item(item_id, n)
if item_id > 0
gain_item(item_id, -n)
end
end
#--------------------------------------------------------------------------
def lose_weapon(weapon_id, n)
if weapon_id > 0
gain_weapon(weapon_id, -n)
end
end
#--------------------------------------------------------------------------
def lose_armor(armor_id, n)
if armor_id > 0
gain_armor(armor_id, -n)
end
end
#--------------------------------------------------------------------------
def item_bag(n)
@add_number = 0
@number = n

items_max = $game_party.bag_size
for i in 1..@number
if @items_now + i > items_max
break
else
@add_number += 1
end
end
end
end


#==============================================================================
# Window_ItemAction
#==============================================================================

class Window_ItemAction < Window_Selectable
def initialize
super(160, 128, 150, 130)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.z = 400
@index = 0
@item_max = 3
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(2, 0, 100, 32, "Usar") #Texto p/ usar um item
self.contents.draw_text(2, 32, 100, 32, "Descartar") #Texto p/ descartar um item
self.contents.draw_text(2, 64, 100, 32, "Cancelar") #Texto p/ cancelar a opção
end
#--------------------------------------------------------------------------
# ? ?????????
#--------------------------------------------------------------------------
def update_cursor_rect
self.cursor_rect.set(0, @index*32, 120, 32)
end
end


#==============================================================================
# Window_ItemDrop
#==============================================================================

class Window_ItemDrop < Window_Selectable
def initialize(max_number = 99)
super(200, 128, 150, 68)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface
self.contents.font.size = $fontsize
self.z = 500
@index = 1
@max_number = max_number
@number = 1
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.draw_text(0, 0, 100, 32, "Descarte:")
self.contents.draw_text(self.contents.text_size("Descarte:").width + 12, 0, 32, 32, @number.to_s)
end
#--------------------------------------------------------------------------
def num
return @number
end
def update
if Input.repeat?(Input::UP)
if @number+1 <= @max_number
$game_system.se_play($data_system.decision_se)
@number += 1
refresh
else
$game_system.se_play($data_system.decision_se)
@number = 1
refresh
end
end
if Input.repeat?(Input::DOWN)
if @number-1 >= 1
$game_system.se_play($data_system.decision_se)
@number -= 1
refresh
else
$game_system.se_play($data_system.decision_se)
@number = @max_number
refresh
end
end
if Input.repeat?(Input::RIGHT)
if @number == @max_number
$game_system.se_play($data_system.buzzer_se)
return
end
if @number+10 <= @max_number
$game_system.se_play($data_system.decision_se)
@number += 10
refresh
else
$game_system.se_play($data_system.decision_se)
@number = @max_number
refresh
end
end
if Input.repeat?(Input::LEFT)
if @number == 1
$game_system.se_play($data_system.buzzer_se)
return
end
if @number-10 > 1
$game_system.se_play($data_system.decision_se)
@number -= 10
refresh
else
$game_system.se_play($data_system.decision_se)
@number = 1
refresh
end
end
end
end


#==============================================================================
# Window_ShopNumber
#==============================================================================

class Window_ShopNumber < Window_Base
#--------------------------------------------------------------------------
def initialize
super(0, 128, 368, 352)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface # "Shop" (Quantity) window font
self.contents.font.size = $fontsize
@item = nil
@max = 1
@price = 0
@number = $game_party.items_now < $game_party.bag_size ? 1 : 0
end
#--------------------------------------------------------------------------
def set(item, max, price)
@item = item
@max_number = max
@max = $game_party.items_now
@price = price
@number = $game_party.items_now < $game_party.bag_size ? 1 : 0
refresh
end
#--------------------------------------------------------------------------
def number
return @number
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_item_name(@item, 4, 96)
self.contents.font.color = normal_color
self.contents.draw_text(272, 96, 32, 32, "×")
self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
self.cursor_rect.set(304, 96, 32, 32)
domination = $data_system.words.gold
cx = contents.text_size(domination).width
total_price = @price * @number
self.contents.font.color = normal_color
self.contents.draw_text(4, 160, 328-cx-2, 32, total_price.to_s, 2)
self.contents.font.color = system_color
self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
end
#--------------------------------------------------------------------------
def update
super
if self.active
if Input.repeat?(Input::RIGHT) and @number + @max < $game_party.bag_size and @number < @max_number
$game_system.se_play($data_system.cursor_se)
@number += 1
refresh
end
if Input.repeat?(Input::LEFT) and @number > 1
$game_system.se_play($data_system.cursor_se)
@number -= 1
refresh
end
if Input.repeat?(Input::UP) and @number+10 + @max < $game_party.bag_size and @number < @max_number
$game_system.se_play($data_system.cursor_se)
@number = [@number + 10, @max].min
refresh
end
if Input.repeat?(Input::DOWN) and @number > 1
$game_system.se_play($data_system.cursor_se)
@number = [@number - 10, 1].max
refresh
end
end
end
end


#==============================================================================
# Scene_Item
#==============================================================================

class Scene_Item
attr_accessor :remaining
#--------------------------------------------------------------------------
def initialize(key_item = false)
@key_item = key_item
@remaining = 0
end
#--------------------------------------------------------------------------
def main
@help_window = Window_Help.new
@item_window = Window_Item.new
@item_window.help_window = @help_window
@target_window = Window_Target.new
@target_window.visible = false
@target_window.active = false
@action_window = Window_ItemAction.new
@action_window.visible = false
@action_window.active = false
@drop_items = Window_ItemDrop.new
@drop_items.visible = false
@drop_items.active = false
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@item_window.dispose
@target_window.dispose
@action_window.dispose
@drop_items.dispose
end
def refresh
@help_window.refresh
@item_window.refresh
@target_window.refresh
@action_window.refresh
@drop_items.refresh
end
#--------------------------------------------------------------------------
def update
@help_window.update
@word_item = @remaining <= 1 ? " item" : " items"
if @item_window.active
@item_window.update
if @key_item then @help_window.set_text("Vocíª precisa descartar " + @remaining.to_s + @word_item) end
update_item
return
end
if @action_window.active
@action_window.update
if @key_item then @help_window.set_text("Vocíª precisa descartar " + @remaining.to_s + @word_item) end
update_action
return
end
if @drop_items.active
@drop_items.update
if @key_item then @help_window.set_text("Vocíª precisa descartar " + @remaining.to_s + @word_item) end
update_drop
return
end
if @target_window.active
@target_window.update
if @key_item then @help_window.set_text("Vocíª precisa descartar " + @remaining.to_s + @word_item) end
update_target
return
end
end
#--------------------------------------------------------------------------
def update_item
if Input.trigger?(Input::B) and @remaining <= 0
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
return
end
if Input.trigger?(Input::C)
@item = @item_window.item
$game_system.se_play($data_system.decision_se)
@item_window.active = false
@action_window.active = true
@action_window.visible = true
return
end
end
def update_action
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@action_window.active = false
@action_window.visible = false
@item_window.active = true
return
end
if Input.trigger?(Input::C)
if @action_window.index == 0
unless $game_party.item_can_use?(@item.id)
$game_system.se_play($data_system.buzzer_se)
return
end
unless @item.is_a?(RPG::Item)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
if @item.scope >= 3
@action_window.active = false
@action_window.visible = false
@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
else
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
$scene = Scene_Map.new
return
end
end
elsif @action_window.index == 1
if @item.is_a?(RPG::Item) and @item.element_set.include?(20)
$game_system.se_play($data_system.buzzer_se)
return
else
$game_system.se_play($data_system.decision_se)
@action_window.active = false
if @item.is_a?(RPG::Item)
@drop_items = Window_ItemDrop.new($game_party.item_number(@item.id))
elsif @item.is_a?(RPG::Armor)
@drop_items = Window_ItemDrop.new($game_party.armor_number(@item.id))
elsif @item.is_a?(RPG::Weapon)
@drop_items = Window_ItemDrop.new($game_party.weapon_number(@item.id))
end
@drop_items.active = true
@drop_items.visible = true
end
elsif @action_window.index == 2
$game_system.se_play($data_system.cancel_se)
@action_window.visible = false
@action_window.active = false
@item_window.active = true
end
end
end
def update_drop
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@drop_items.active = false
@drop_items.visible = false
@action_window.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
if @item.is_a?(RPG::Item)
$game_party.lose_item(@item.id, @drop_items.num)
elsif @item.is_a?(RPG::Armor)
$game_party.lose_armor(@item.id, @drop_items.num)
elsif @item.is_a?(RPG::Weapon)
$game_party.lose_weapon(@item.id, @drop_items.num)
end
if @remaining > 0
if @remaining - @drop_items.num <= 0
$scene = Scene_Map.new
else
@remaining -= @drop_items.num
end
end
@item_window.refresh
@drop_items.active = false
@drop_items.visible = false
@action_window.visible = false
@item_window.active = true
end
end
#--------------------------------------------------------------------------
def update_target
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
unless $game_party.item_can_use?(@item.id)
@item_window.refresh
end
@item_window.active = true
@target_window.visible = false
@target_window.active = false
return
end
if Input.trigger?(Input::C)
if $game_party.item_number(@item.id) == 0
$game_system.se_play($data_system.buzzer_se)
return
end
if @target_window.index == -1
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
if @target_window.index >= 0
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
if used
$game_system.se_play(@item.menu_se)
if @item.consumable
$game_party.lose_item(@item.id, 1)
@item_window.draw_item(@item_window.index)
end
@target_window.refresh
if $game_party.all_dead?
$scene = Scene_Gameover.new
return
end
if @item.common_event_id > 0
$game_temp.common_event_id = @item.common_event_id
$scene = Scene_Map.new
return
end
end
unless used
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
end
Instruçíµes:

Vocíª pode fazer com que o personagem compre BAG maiores, assim cabendo mais itens.
Vá no banco de dados e na aba itens, crie novos itens que o jogador poderá comprar. Anote as ID destes itens.

Procure por estas linhas logo no inicio do script:

-----------------------------------------------------------------------------
if item_id == 40 # Numero id da 1° bag
$game_party.bag_size = 50 # maximo de itens que cabe na 1° bag
elsif item_id == 41 # Numero id da 2° bag
$game_party.bag_size = 100 # maximo de itens que cabe na 2° bag
elsif item_id == 42 # Numero id da 3° bag
$game_party.bag_size = 150 # maximo de itens que cabe na 3° bag
-----------------------------------------------------------------------------

Os níºmeros em vermelho: 40, 41, 42, representa respectivamente a id do item no banco de dados, mude-as para o níºmero da ID dos seus itens.

Abaixo de cada id, tem os níºmeros em azul: 50, 100, 150, que representa a quantidade de itens que cabe na BAG que vocíª criou.

Exemplo: O menu do jogador cabe apenas 30 itens, então ele vai no shop e compra uma BAG de 100 itens. Após a compra, seu menu de itens passará a caber 100 itens e não mais 30.
avatar
roberto
Admin

Mensagens : 75
Pontos : 204
Reputação : 3
Data de inscrição : 03/03/2010

Ver perfil do usuário http://morpgmaker.mo-rpg.com

Voltar ao Topo Ir em baixo

Ver o tópico anterior Ver o tópico seguinte Voltar ao Topo

- Tópicos similares

 
Permissão deste fórum:
Você não pode responder aos tópicos neste fórum