赞 | 41 |
VIP | 0 |
好人卡 | 0 |
积分 | 101 |
经验 | 0 |
最后登录 | 2024-11-22 |
在线时间 | 590 小时 |
Lv4.逐梦者
- 梦石
- 3
- 星屑
- 7145
- 在线时间
- 590 小时
- 注册时间
- 2019-9-15
- 帖子
- 113
|
本帖最后由 Cupidk爱呗茶 于 2021-8-13 23:50 编辑
花了一下午写的 虽说可能比不上论坛上其他大神的作品 而且代码方面会有点乱 不过我尽力了..
基本上算是实现了LZ所说的所有要求了 顺便..范例就收20星屑吧.. 希望不会无人问津 (
工程演示
范例
NG变量+多周目箱子.rar
(450.03 KB, 下载次数: 17, 售价: 20 星屑)
脚本 ↓
箱子系统和跨存档变量均为原创
# 简易跨存档变量 by cupidk rays 制作 # 脚本特性: 生成的数据即便不进行存档也依旧不会消失 (制作多周目游戏) # 变量获取方法 CUPIDK::NGVAR.get_var(id) # 数据获取方法 CUPIDK::NGVAR.get_data module CUPIDK end module CUPIDK::NGVAR # 被跨存档变量占用的变量位置 VAR_RANGE = 1..100 # 这里设置一些初始的数值 ↓ # 数字类变量初始化请写在这里 SETINIT_VAR = [0] NGTIMES_VARID = 1 # 存储周目数的跨存档变量ID NGCASE_SIZE = 3 # 这里设置每次周目额外获得的仓库容量上限 SETINIT_VAR[NGTIMES_VARID] = 1 # 周目数初始化 # 各种数据类请保存在这里(如数组,哈希表等) SETINIT_DATA = { "NG_items" => {} , # 跨存档物品 } def self.init_Ngdata(name) save_data(SETINIT_DATA, name) end def self.data_set(name) init_Ngdata(name) unless FileTest.exist?(name) @Game_DataNg = load_data(name) end def self.get_data @Game_DataNg end def self.init_Ngvar(name) save_data(SETINIT_VAR, name) end def self.var_set(name) init_Ngvar(name) unless FileTest.exist?(name) @Game_VarNg = load_data(name) end def self.var_refresh(var_id, value, name = "Data/NGvar.rxdata") @Game_VarNg[var_id] = value save_data(@Game_VarNg, name) end def self.get_var(var_id) @Game_VarNg[var_id] || 0 end end class Scene_Title include CUPIDK alias :old_start_21518 :main def main NGVAR.data_set("Data/NGdata.rxdata") NGVAR.var_set("Data/NGvar.rxdata") old_start_21518 end end class Game_Variables include CUPIDK alias_method "old_var_give_21518", "[]=" def []=(var_id, value) return NGVAR.var_refresh(var_id, value) if NGVAR::VAR_RANGE === var_id old_var_give_21518(var_id, value) end alias_method "old_var_21518", "[]" def [](var_id) return NGVAR.get_var(var_id) if NGVAR::VAR_RANGE === var_id old_var_21518(var_id) end end
# 简易跨存档变量 by cupidk rays 制作
# 脚本特性: 生成的数据即便不进行存档也依旧不会消失 (制作多周目游戏)
# 变量获取方法 CUPIDK::NGVAR.get_var(id)
# 数据获取方法 CUPIDK::NGVAR.get_data
module CUPIDK end
module CUPIDK::NGVAR
# 被跨存档变量占用的变量位置
VAR_RANGE = 1..100
# 这里设置一些初始的数值 ↓
# 数字类变量初始化请写在这里
SETINIT_VAR = [0]
NGTIMES_VARID = 1 # 存储周目数的跨存档变量ID
NGCASE_SIZE = 3 # 这里设置每次周目额外获得的仓库容量上限
SETINIT_VAR[NGTIMES_VARID] = 1 # 周目数初始化
# 各种数据类请保存在这里(如数组,哈希表等)
SETINIT_DATA = {
"NG_items" => {} , # 跨存档物品
}
def self.init_Ngdata(name)
save_data(SETINIT_DATA, name)
end
def self.data_set(name)
init_Ngdata(name) unless FileTest.exist?(name)
@Game_DataNg = load_data(name)
end
def self.get_data
@Game_DataNg
end
def self.init_Ngvar(name)
save_data(SETINIT_VAR, name)
end
def self.var_set(name)
init_Ngvar(name) unless FileTest.exist?(name)
@Game_VarNg = load_data(name)
end
def self.var_refresh(var_id, value, name = "Data/NGvar.rxdata")
@Game_VarNg[var_id] = value
save_data(@Game_VarNg, name)
end
def self.get_var(var_id)
@Game_VarNg[var_id] || 0
end
end
class Scene_Title
include CUPIDK
alias :old_start_21518 :main
def main
NGVAR.data_set("Data/NGdata.rxdata")
NGVAR.var_set("Data/NGvar.rxdata")
old_start_21518
end
end
class Game_Variables
include CUPIDK
alias_method "old_var_give_21518", "[]="
def []=(var_id, value)
return NGVAR.var_refresh(var_id, value) if NGVAR::VAR_RANGE === var_id
old_var_give_21518(var_id, value)
end
alias_method "old_var_21518", "[]"
def [](var_id)
return NGVAR.get_var(var_id) if NGVAR::VAR_RANGE === var_id
old_var_21518(var_id)
end
end
# 多周目物品箱 by cupidk rays # 需配合本工程内的跨存档变量 # 使用方法 调用脚本$scene = Scene_NGCase.new class Game_Party; attr_accessor :items ; end class Window_NgItem < Window_Item def refresh if self.contents != nil self.contents.dispose self.contents = nil end @data = [] (1...$data_items.size).each do |i| if Ngitem_number(i) > 0 @data.push($data_items[i]) end end @item_max = @data.size if @item_max > 0 self.contents = Bitmap.new(width - 32, row_max * 32) (0...@item_max).each do |i| draw_item(i) end end end def Ngitem_number(id) data = CUPIDK::NGVAR.get_data["NG_items"] n = data.include?(id) ? data[id] : 0 end def draw_item(index) item = @data[index] number = Ngitem_number(item.id) x = 4 + index % 2 * (288 + 32) y = index / 2 * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) self.contents.draw_text(x + 240, y, 16, 32, ":", 1) self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2) end end class Window_HaveItem < Window_Item def draw_item(index) item = @data[index] case item when RPG::Item number = $game_party.item_number(item.id) when RPG::Weapon number = $game_party.weapon_number(item.id) when RPG::Armor number = $game_party.armor_number(item.id) end x = 4 + index % 2 * (288 + 32) y = index / 2 * 32 rect = Rect.new(x, y, self.width / @column_max - 32, 32) self.contents.fill_rect(rect, Color.new(0, 0, 0, 0)) bitmap = RPG::Cache.icon(item.icon_name) opacity = self.contents.font.color == normal_color ? 255 : 128 self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity) self.contents.draw_text(x + 28, y, 212, 32, item.name, 0) self.contents.draw_text(x + 240, y, 16, 32, ":", 1) self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2) end end class Scene_NGCase include CUPIDK def main # 生成帮助窗口、物品窗口 @help_window = Window_Help.new @item_window = Window_HaveItem.new @item_window.y += 285 @item_window.height = 130 @item_window.help_window = @help_window @Ngitem_window = Window_NgItem.new @Ngitem_window.help_window = @help_window @Ngitem_window.height = 284 if $game_party.items.empty? || !$game_party.items.any? {|k,v| v >= 1 } @item_window.active = false else @Ngitem_window.active = false end # 执行过度 Graphics.transition # 主循环 loop do Graphics.update Input.update update if $scene != self break end end Graphics.freeze # 释放窗口 @help_window.dispose @item_window.dispose @Ngitem_window.dispose end # 画面更新 def update @help_window.update @item_window.update @Ngitem_window.update if @item_window.active update_item return end if @Ngitem_window.active update_Ngitem return end end def Ngitems NGVAR.get_data["NG_items"] end # 跨存档储存窗口 def update_Ngitem if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) $scene = Scene_Map.new return end if Input.trigger?(Input::C) @Ngitem = @Ngitem_window.item num = 1 if NGVAR.get_data["NG_items"].include?(@Ngitem.id) && NGVAR.get_data["NG_items"][@Ngitem.id] >= num NGVAR.get_data["NG_items"][@Ngitem.id] -= num if $game_party.items.include?(@Ngitem.id) $game_party.gain_item(@Ngitem.id, num) else $game_party.items[@Ngitem.id] = num end $game_system.se_play($data_system.decision_se) name = "Data/NGdata.rxdata" save_data(NGVAR.get_data, name) @item_window.refresh @Ngitem_window.refresh else $game_system.se_play($data_system.cancel_se) end end end # 角色物品窗口 def update_item if Input.trigger?(Input::B) $game_system.se_play($data_system.cancel_se) @Ngitem_window.active = true @item_window.active = false return end if Input.trigger?(Input::C) @item = @item_window.item id = NGVAR::NGTIMES_VARID max = $game_variables[id] * NGVAR::NGCASE_SIZE ngmax = NGVAR.get_data["NG_items"].select do |k, v| v > 0 end if (NGVAR.get_data["NG_items"][@item.id].nil? || NGVAR.get_data["NG_items"][@item.id] == 0) && max <= ngmax.size return $game_system.se_play($data_system.cancel_se) end # 演奏确定 SE num = 1 if $game_party.items.include?(@item.id) && $game_party.item_number(@item.id) >= num $game_party.gain_item(@item.id, -num) if NGVAR.get_data["NG_items"][@item.id] NGVAR.get_data["NG_items"][@item.id] += num else NGVAR.get_data["NG_items"][@item.id] = num end $game_system.se_play($data_system.decision_se) name = "Data/NGdata.rxdata" save_data(NGVAR.get_data, name) @item_window.refresh @Ngitem_window.refresh else $game_system.se_play($data_system.cancel_se) end end end end
# 多周目物品箱 by cupidk rays
# 需配合本工程内的跨存档变量
# 使用方法 调用脚本$scene = Scene_NGCase.new
class Game_Party; attr_accessor :items ; end
class Window_NgItem < Window_Item
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
(1...$data_items.size).each do |i|
if Ngitem_number(i) > 0
@data.push($data_items[i])
end
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
(0...@item_max).each do |i|
draw_item(i)
end
end
end
def Ngitem_number(id)
data = CUPIDK::NGVAR.get_data["NG_items"]
n = data.include?(id) ? data[id] : 0
end
def draw_item(index)
item = @data[index]
number = Ngitem_number(item.id)
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
end
class Window_HaveItem < Window_Item
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
end
class Scene_NGCase
include CUPIDK
def main
# 生成帮助窗口、物品窗口
@help_window = Window_Help.new
@item_window = Window_HaveItem.new
@item_window.y += 285
@item_window.height = 130
@item_window.help_window = @help_window
@Ngitem_window = Window_NgItem.new
@Ngitem_window.help_window = @help_window
@Ngitem_window.height = 284
if $game_party.items.empty? || !$game_party.items.any? {|k,v| v >= 1 }
@item_window.active = false
else
@Ngitem_window.active = false
end
# 执行过度
Graphics.transition
# 主循环
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
# 释放窗口
@help_window.dispose
@item_window.dispose
@Ngitem_window.dispose
end
# 画面更新
def update
@help_window.update
@item_window.update
@Ngitem_window.update
if @item_window.active
update_item
return
end
if @Ngitem_window.active
update_Ngitem
return
end
end
def Ngitems
NGVAR.get_data["NG_items"]
end
# 跨存档储存窗口
def update_Ngitem
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
@Ngitem = @Ngitem_window.item
num = 1
if NGVAR.get_data["NG_items"].include?(@Ngitem.id) && NGVAR.get_data["NG_items"][@Ngitem.id] >= num
NGVAR.get_data["NG_items"][@Ngitem.id] -= num
if $game_party.items.include?(@Ngitem.id)
$game_party.gain_item(@Ngitem.id, num)
else
$game_party.items[@Ngitem.id] = num
end
$game_system.se_play($data_system.decision_se)
name = "Data/NGdata.rxdata"
save_data(NGVAR.get_data, name)
@item_window.refresh
@Ngitem_window.refresh
else
$game_system.se_play($data_system.cancel_se)
end
end
end
# 角色物品窗口
def update_item
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@Ngitem_window.active = true
@item_window.active = false
return
end
if Input.trigger?(Input::C)
@item = @item_window.item
id = NGVAR::NGTIMES_VARID
max = $game_variables[id] * NGVAR::NGCASE_SIZE
ngmax = NGVAR.get_data["NG_items"].select do |k, v|
v > 0
end
if (NGVAR.get_data["NG_items"][@item.id].nil? || NGVAR.get_data["NG_items"][@item.id] == 0) &&
max <= ngmax.size
return $game_system.se_play($data_system.cancel_se)
end
# 演奏确定 SE
num = 1
if $game_party.items.include?(@item.id) && $game_party.item_number(@item.id) >= num
$game_party.gain_item(@item.id, -num)
if NGVAR.get_data["NG_items"][@item.id]
NGVAR.get_data["NG_items"][@item.id] += num
else
NGVAR.get_data["NG_items"][@item.id] = num
end
$game_system.se_play($data_system.decision_se)
name = "Data/NGdata.rxdata"
save_data(NGVAR.get_data, name)
@item_window.refresh
@Ngitem_window.refresh
else
$game_system.se_play($data_system.cancel_se)
end
end
end
end
|
评分
-
查看全部评分
|