查看: 2804|回复: 29

[已经解决] 请教偷窃脚本切换地图后不还原成NPC携带物品初始状态方法

[复制链接]
梦石
0
星屑
9160
在线时间
466 小时
注册时间
2015-5-8
回帖
704
发表于 2021-10-24 21:27:58 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 taeckle 于 2021-10-25 05:14 编辑

本人在网上找到了一个简单的偷窃脚本,新开一个默认工程后在main上面插入就能使用,

请问大家要怎么搞才能让每次读档重新载入地图后(执行$game_map.setup($game_map.map_id)指令后)让NPC携带的物品不还原成新开工程时的初始状态啊?(比如现在的情况是先偷地图上第1号NPC携带的第2号物品, 然后再从当前地图出去再进来, 刚才偷第1号NPC的第2号物品就会又出现在第1号NPC携带物品列表里了)

先附上这个偷窃脚本代码, 下面还有在地图上设置的地图事件:

  1. #-------------------------------------------------------------------------
  2. # ★★★★★★
  3. #-------------------------------------------------------------------------
  4. module Stolen
  5.   STEAL_SKILL_ID = 1   # 偷盗特技id
  6. end
  7. #-------------------------------------------------------------------------
  8. # ★★★★★★
  9. #-------------------------------------------------------------------------
  10. class Scene_Map
  11.   attr_accessor :spriteset
  12. end

  13. #-------------------------------------------------------------------------
  14. # ★★★★★★
  15. #-------------------------------------------------------------------------
  16. class Window_Npc_Item < Window_Selectable
  17.   #--------------------------------------------------------------------------
  18.   # ● 初始化对像
  19.   #--------------------------------------------------------------------------
  20.   def initialize(item)
  21.     super(224, 80, 188+100, 320)
  22.     @column_max = 1
  23.     @item = item
  24.     @item_max = @item.size
  25.     self.height = @item.size*32+32
  26.     self.y = (480-self.height)/2
  27.     self.opacity = 160
  28.     refresh
  29.     self.index = 0
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   def item
  33.     return @item[self.index]
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   def refresh
  37.     if self.contents != nil
  38.       self.contents.dispose
  39.       self.contents = nil
  40.     end
  41.     if @item_max > 0
  42.       self.contents = Bitmap.new(width - 32, row_max * 32)
  43.       for i in 0...@item_max
  44.         draw_item(i)
  45.       end
  46.     end
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   def draw_item(index)
  50.     item = @item[index]   
  51.     x = 4
  52.     y = index * 32
  53.     bitmap = RPG::Cache.icon(item.icon_name)
  54.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  55.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  56.   end

  57. end
  58. #-------------------------------------------------------------------------
  59. # ★★★★★★
  60. #-------------------------------------------------------------------------
  61. class Game_Party
  62.   attr_reader   :stealexp
  63.   attr_accessor :stealnpc
  64.   alias initialize_old initialize
  65.   def initialize
  66.     initialize_old
  67.     @stealexp = 0
  68.     @stealnpc = {}
  69.   end
  70.   def add_sexp(n)
  71.     @stealexp = [[@stealexp + n, 0].max, 100].min
  72.   end
  73. end
  74. #-------------------------------------------------------------------------
  75. # ★★★★★★
  76. #-------------------------------------------------------------------------
  77. class Interpreter
  78.   def judge
  79.     @npc_item = []
  80.     @npc_item.clear
  81.     if @list[0].code == 108
  82.       if @list[0].parameters[0].split(/:/)[0] == "可偷盗对象"
  83.         unless @list[0].parameters[0].split(/:/)[1] == nil
  84.           @npc_item = eval(@list[0].parameters[0].split(/:/)[1])
  85.         end
  86.       #@list[0].parameters[0] = "不可偷盗"
  87.       end
  88.     end
  89.   end
  90.   #偷盗
  91.   def steal
  92.    unless judge_skill
  93.       @message_waiting = true
  94.       $game_temp.message_proc = Proc.new { @message_waiting = false }
  95.       $game_temp.message_text = "无人会偷盗技能!"
  96.       return true
  97.    end
  98.    if @npc_item.size == 0
  99.       @message_waiting = true
  100.       $game_temp.message_proc = Proc.new { @message_waiting = false }
  101.       $game_temp.message_text = "对方已无任何道具."
  102.       return true
  103.    end
  104.       $win = Window_Npc_Item.new(@npc_item)
  105.    loop do
  106.         $game_map.update
  107.         $scene.spriteset.update
  108.         Graphics.update
  109.         Input.update
  110.         $win.update
  111.     if Input.trigger?(Input::B)
  112.         $win.dispose
  113.         $game_system.se_play($data_system.cancel_se)
  114.         return true
  115.     end  
  116.     if Input.trigger?(Input::C)
  117.           $win.dispose
  118.           $game_map.events[@event_id].animation_id = $data_skills[Stolen::STEAL_SKILL_ID].animation2_id
  119.      for i in 1..$data_animations[$data_skills[Stolen::STEAL_SKILL_ID].animation2_id].frame_max*4
  120.           Graphics.update
  121.           $game_map.update
  122.           $game_player.update
  123.           $scene.spriteset.update
  124.      end
  125.      if successful?(@list[2].parameters[0].split(/,/)[1].split(/:/)[1].to_i)
  126.           $game_party.add_sexp(2)  #偷盗经验值上升
  127.           item = $win.item
  128.       case item
  129.        when RPG::Item
  130.           $game_party.gain_item(item.id, 1)
  131.           @list[4].parameters[0].slice!(item.id.to_s+",")              
  132.        when RPG::Weapon
  133.           $game_party.gain_weapon(item.id, 1)
  134.           @list[6].parameters[0].slice!(item.id.to_s+",")
  135.        when RPG::Armor
  136.           $game_party.gain_armor(item.id, 1)
  137.           @list[5].parameters[0].slice!(item.id.to_s+",")
  138.       else   
  139.       end
  140.           @wait_count = 1                       
  141.           return true
  142.      else
  143.           #$game_party.add_sexp(1)       #偷盗经验值上升         
  144.           @message_waiting = true
  145.           $game_temp.message_proc = Proc.new { @message_waiting = false }
  146.           $game_temp.message_text = "盗取失败,被发现了!"            
  147.           Audio.se_play("Audio/SE/"+"Glass1",80,100)
  148.           @wait_count = 1         
  149.       if $data_troops[@list[3].parameters[0].split(/:/)[1].to_i] != nil
  150.           $game_temp.battle_abort = true
  151.           $game_temp.battle_calling = true
  152.           $game_temp.battle_troop_id = @list[3].parameters[0].split(/:/)[1].to_i
  153.           $game_temp.battle_can_escape = false
  154.           $game_temp.battle_can_lose = false
  155.           current_indent = @list[@index].indent
  156.           $game_temp.battle_proc = Proc.new { |n| @branch[current_indent] = n }
  157.       end
  158.      end
  159.     break
  160.     end  # end of C键
  161.    end #end of loop do
  162.   end #end of def
  163.    #是否有“盗窃”技能判断
  164.   def judge_skill
  165.     actor = $game_party.actors
  166.     for i in 0...actor.size
  167.      if actor[i].skills.include?(Stolen::STEAL_SKILL_ID)
  168.         return true
  169.      end
  170.     end
  171.     return false
  172.   end
  173.    #取得物品
  174.   def get_item
  175.     temp_item = []     
  176.     # 是 物品 判断
  177.     if @list[4].parameters[0].split(/:/)[0] == "Item"
  178.       if @list[4].parameters[0].split(/:/)[1] != nil
  179.         b1 = @list[4].parameters[0].split(/:/)[1].split(/,/)
  180.         for i in 0...b1.size
  181.           temp_item.push($data_items[b1[i].to_i])
  182.         end      
  183.       end
  184.     end
  185.     # 是 武器 判断
  186.     if @list[6].parameters[0].split(/:/)[0] == "Weapon"
  187.       if @list[6].parameters[0].split(/:/)[1] != nil
  188.         b2 = @list[6].parameters[0].split(/:/)[1].split(/,/)
  189.         for i in 0...b2.size
  190.           temp_item.push($data_weapons[b2[i].to_i])
  191.         end
  192.       end
  193.     end
  194.     # 是 防具 判断
  195.     if @list[5].parameters[0].split(/:/)[0] == "Armor"
  196.       if @list[5].parameters[0].split(/:/)[1] != nil
  197.         b3 = @list[5].parameters[0].split(/:/)[1].split(/,/)
  198.         for i in 0...b3.size
  199.           temp_item.push($data_armors[b3[i].to_i])
  200.         end
  201.       end
  202.     end
  203.     # 返回物品数组
  204.     return temp_item
  205.    end
  206.    #偷盗成功判断
  207.    def successful?(n) # n - 对象npc的过失率
  208.     s_rate = 101
  209.     return rand(101) < s_rate
  210.   end
  211.   #------------------------------------------
  212. end
复制代码




附件里有完整的工程制作

地图事件上的设置

地图事件上的设置

taeckle简单的偷窃脚本_1.rar

191.09 KB, 下载次数: 16

第2张地图从左边进入

梦石
0
星屑
39236
在线时间
11155 小时
注册时间
2009-3-15
回帖
4768
发表于 2021-10-24 22:36:25 | 显示全部楼层
你的事件触发是决定键..读档后后需要再执行这个事件才行?

点评

或且自动执行+独立开关..  发表于 2021-10-28 12:00
这事件你改成並行就读档也会生效了...  发表于 2021-10-28 11:53
是啊,现在的问题就是只要一读档或者切换地图可偷的东西就还原初始化了。。  发表于 2021-10-26 05:12
我是说你这个偷东西脚本读档后应该需要再执行一次那个事件才有东西可偷..  发表于 2021-10-25 14:17
大神你把附件里的工程下载下来就全清楚了  发表于 2021-10-25 01:27
回复

使用道具 举报

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2021-10-25 17:42:06 | 显示全部楼层
这个偷窃脚本的设计就是这样,相当于你有一定的概率可以避免战斗直接获取经验和物品。也非常适合S/L大法。
如果你想让被偷过的东西在显示的时候减少,那么你就需要对所有可以偷窃的事件的状态进行记录。每次偷窃时,查询一下之前的记录,去掉已经偷掉的部分就行。
但是转念一想,这和储物箱并没有本质区别:NPC的东西只能拿不能放回,并且每次只能拿1个

点评

大神可否举个例子呢,比如咱想调用第3号地图种第2号事件的可偷窃物品列表,需要先在class Game_Map中的def initialize里怎么搞呢?  发表于 2021-10-25 23:48
用哈希表,地图ID*1000+事件ID作为键值  发表于 2021-10-25 20:11
比如在class Game_Map中的def initialize里这么写"$game_map[$game_map.map_id].[事件index]=[[0],[0],[0]]"可以嘛?  发表于 2021-10-25 20:08
那个储物箱只需要用1个全局变量, 我这边有500个可偷窃NPC分布在20多张地图上, 请问下有啥简单的法子在游戏一开始时设置这500个全局变量啊?  发表于 2021-10-25 20:05

评分

参与人数 1赞 +1 收起 理由
taeckle + 1 多谢大神指点!

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2021-10-26 15:51:39 | 显示全部楼层
本帖最后由 guoxiaomi 于 2021-10-26 16:16 编辑

[pre lang="ruby"]# encoding: utf-8
module Taeckle
  # 2 is the id of global variable which saves all npcs' stolen data
  Stolen_Data_VID = 2

  class Stolen_Data
    def initialize
      @data = {}
    end

    def setup(index, force)
      if force || @data[index].nil?
        @data[index] = []
        yield @data[index]
      end
    end

    def update(index)
      data = @data[index]
      if data.empty?
        return :empty_storage
      end
      # -----------------------------------------
      # 定义处理 data 的方式
      # 偷窃成功时操作 $game_party 以增加道具
      # -----------------------------------------

      # -----------------------------------------
      return true
    end
  end
end

class Interpreter
  def steal_setup(vid = Taeckle::Stolen_Data_VID, &block)
    if $game_variables[vid] == 0
      $game_variables[vid] = Taeckle::Stolen_Data.new
    end
    index = $game_map.map_id * 1000 + @event_id
    $game_variables[vid].setup(index, false, &block)
  end

  def steal_update(vid = Taeckle::Stolen_Data_VID)
    index = $game_map.map_id * 1000 + @event_id
    $game_variables[vid].update(index)
  end
end

=begin
# 直接在事件脚本里调用 steal_setup 和 steal_update
# usage :
# 1. 向 data 里添加数据,数据类型任意
steal_setup { |data|
  data << [1, 2]
  data << [3, 4]
}
# 2. 必须在 steal_setup 后使用,执行动作
@steal_result = steal_update()
# 3. 在条件分歧里判断结果以执行不同的分支
@steal_result == :empty_storage
=end[/pre]

点评

#<>是想说类名和objectID?你慢慢研究吧  发表于 2021-10-27 20:27
报告大神,p完了,好像要学的东西很多...请问下那个"#<>"是啥意思啊?我看这个东西里好像都是物品介绍,还老是在一个数组里出现啊...  发表于 2021-10-27 20:21
你把这里面的内容一点点p出来……先从@list[0]开始  发表于 2021-10-27 19:51
p出来的居然是那个def get_item!大神那还想请问下这eval(@list[0].parameters[0].split(/:/)[1])是怎么代换成成那个def get_item的呢?  发表于 2021-10-27 19:42
你把eval里面的内容p出来,看看就知道了  发表于 2021-10-27 19:28

评分

参与人数 3星屑 +120 赞 +3 收起 理由
RyanBern + 120 + 1 认可答案
enghao_lim + 1 这个模块命名我笑了 XD
taeckle + 1 大神威武!

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

梦石
0
星屑
9160
在线时间
466 小时
注册时间
2015-5-8
回帖
704
 楼主| 发表于 2021-10-28 02:44:15 | 显示全部楼层
guoxiaomi 发表于 2021-10-26 15:51
# encoding: utf-8
module Taeckle
  # 2 is the id of global variable which saves all npcs' stolen dat ...

大神我还有个问题,你看我上面的脚本第133、136、139行里的那个"slice!(item.id.to_s+",")",表示的意思是在对象@list[4].parameters[0]中删除item.id,那如果我想在对象@list[4].parameters[0]中增加item.id又该用哪个指令呢?

点评

+=,这个脚本写的并不好,但你非要死磕也不是不行……  发表于 2021-10-28 03:38
回复

使用道具 举报

梦石
0
星屑
9160
在线时间
466 小时
注册时间
2015-5-8
回帖
704
 楼主| 发表于 2021-10-31 16:01:27 | 显示全部楼层
本帖最后由 taeckle 于 2021-10-31 16:17 编辑
guoxiaomi 发表于 2021-10-26 15:51
# encoding: utf-8
module Taeckle
  # 2 is the id of global variable which saves all npcs' stolen dat ...


报告大神,我死磕了几天后这个问题终于被咱解决了,给你也分享下咱死磕的成果:
先总结下解决这个问题的整体思路,鉴于我的工程里还没有重名的NPC,我还是决定用事件名称来标记NPC以及其所携带的物品,在此之前得先用到那个显示事件名称脚本(插入到main上面就能用了,下面会有的), 然后得在$game_system里增加个存放NPC携带物品的全局变量, 最后完善偷窃脚本.

第1步: 把这个显示事件名称脚本插入到main上面:

  1. # 使用方法:插入到main前即可,之后就会显示每个事件的名字。
  2. # 不想显示名字的NPC直接把名字设置为一个空格就行了。
  3. #
  4. # 附加功能:名字颜色区分:比如一个NPC的名字是 小龙,2 就会用2号颜色(红色)显示
  5. #
  6. # 修改NPC名的方法:$game_map.events[事件ID编号].name =
  7. # 比如某个宝箱,原名宝箱,打开后名为“打开的宝箱”,则
  8. # $game_map.events[@event_id].name = "打开的宝箱" 或者
  9. # $game_map.events[2].name = "打开的宝箱" (假设宝箱是2号事件)
  10. #
  11. # 修改颜色定义:70-88行,131-149行,自己随便改。
  12. #
  13. # 给主角带上名字:192行,改 "" 为 "主角" 或者 $game_party.actors[0].name 即可
  14. #
  15. # 是否显示姓名的开关:157行,开头的井号去掉。则以后39号开关打开的时候才会显示姓名
  16. #
  17. #==============================================================================
  18. # ■ Game_Event
  19. #------------------------------------------------------------------------------
  20. #  处理事件的类。条件判断、事件页的切换、并行处理、执行事件功能
  21. # 在 Game_Map 类的内部使用。
  22. #==============================================================================
  23. class Game_Event < Game_Character
  24. #——————————————————————————————————————
  25. # 用来返回名称
  26. #——————————————————————————————————————
  27. def name
  28.   return @event.name
  29. end  
  30. def name=(newname)
  31.   @event.name = newname
  32. end
  33. end

  34. #==============================================================================
  35. # ■ Sprite_Character
  36. #------------------------------------------------------------------------------
  37. #  角色显示用脚本。监视 Game_Character 类的实例、
  38. # 自动变化脚本状态。
  39. #==============================================================================

  40. class Sprite_Character < RPG::Sprite
  41.   def dispose
  42.   super
  43.   @namesprite.dispose unless @namesprite.nil?
  44.   @titlesprite.dispose unless @titlesprite.nil?
  45.   @class_sprite.dispose unless @class_sprite.nil?
  46.   end
  47. #--------------------------------------------------------------------------
  48. # ● 定义实例变量
  49. #--------------------------------------------------------------------------
  50. attr_accessor :character                # 角色
  51.   #--------------------------------------------------------------------------
  52. # ● 初始化对像
  53. #     viewport  : 查看端口
  54. #     character : 角色 (Game_Character)
  55. #--------------------------------------------------------------------------
  56. def initialize(viewport, character = nil)
  57.   if character == nil
  58.   name = ""
  59.   else
  60.   name = character.name #if character != nil
  61.   end
  62.   super(viewport)
  63.   @npc_name = ["AA","BB","CC","DD"]
  64.   @character = character
  65.   @namesprite = Sprite.new
  66.   @namesprite.bitmap = Bitmap.new(160, 48)
  67.   @namesprite.bitmap.font.name = ["黑体", "楷体", "宋体"]
  68.   @namesprite.bitmap.font.size = 15
  69.   @namesprite.bitmap.font.color.set( 30, 255,   0)
  70.    ################################################
  71.    @titlesprite = Sprite.new
  72.    @titlesprite.bitmap = Bitmap.new(160, 48)#160,48
  73.    @titlesprite.bitmap.font.name = ["黑体", "楷体", "宋体"] #"楷体"
  74.    @titlesprite.bitmap.font.size = 25
  75.    @titlesprite.bitmap.font.color.set(255, 200, 0)
  76.    @class_sprite = Sprite.new
  77.    @class_sprite.bitmap = Bitmap.new(160, 48)#160,48
  78.    @class_sprite.bitmap.font.name = ["黑体", "楷体", "宋体"] #"楷体"
  79.    @class_sprite.bitmap.font.size = 25
  80.    @class_sprite.bitmap.font.color.set(  0, 255, 255)
  81.    ################################################
  82.   @evname = name
  83.   @evname_split = name.split(/,/)[0]
  84.   @evoy = 0
  85.   if name[0, 2]=="EV"
  86.     @evname_split = " "
  87.   end
  88.   #@tile_id = @character.tile_id
  89.   #if @tile_id >= 384 && @character.name.split(/,/)[1] == nil
  90.    # @evname_split = " "
  91.   #end
  92.   if name.split(/,/)[1] != nil
  93.     case name.split(/,/)[1]
  94.     when "0"
  95.       @namesprite.bitmap.font.color.set(255, 255, 255)
  96.     when "1"
  97.       @namesprite.bitmap.font.color.set(120, 120, 120)
  98.     when "2"
  99.       @namesprite.bitmap.font.color.set(255,   0,   0)
  100.     when "3"
  101.       @namesprite.bitmap.font.color.set(30, 255,   0)
  102.     when "4"
  103.       @namesprite.bitmap.font.color.set(0, 112, 221)
  104.     when "5"
  105.       @namesprite.bitmap.font.color.set(163,  53, 238)
  106.     when "6"
  107.       @namesprite.bitmap.font.color.set(247, 102,   0)
  108.     when "7"
  109.       @namesprite.bitmap.font.color.set(255, 210,   0)
  110.     else
  111.       @evoy = name.split(/,/)[1].to_i
  112.       #@namesprite.bitmap.font.color.set(255, 255, 255)
  113.     end
  114.   end
  115.   if @evname_split != "" and @evname_split != nil
  116.      if @character.character_name == "" && @character.tile_id == 0
  117.       @evname_split = ""
  118.      end
  119.      if character.is_a?(Game_Player)
  120.         if character.id == 0
  121.          case $game_variables[16]
  122.          when -999999..-60
  123.           @namesprite.bitmap.font.color.set(255,   0,   0)
  124.          when -59..79
  125.           @namesprite.bitmap.font.color.set(255, 255, 255)
  126.          when 80..999999
  127.           @namesprite.bitmap.font.color.set(255, 255,   0)
  128.          else
  129.          end
  130.        else
  131.         @namesprite.bitmap.font.color.set(30, 255, 0)
  132.       end
  133.       for i in 0..@npc_name.size
  134.        if @evname_split == @npc_name[i]
  135.         @namesprite.bitmap.font.color.set(30, 255, 0)
  136.        end
  137.       end
  138.      end
  139.      
  140.      @namesprite.bitmap.draw_text(0, 24, 160, 36, @evname_split, 1)
  141.   end
  142. ################################################
  143.    
  144.    if character.is_a?(Game_Player) && character.id == 0
  145.      if $game_party.actors[character.id].armor1_id != 0
  146.       @evtitle = $data_armors[$game_party.actors[character.id].armor1_id].name.to_s
  147.      else
  148.       @evtitle = ""#$game_party.actors[character.id].class_name
  149.     end
  150.      @class_name = $game_party.actors[character.id].class_name
  151.      for i in 0..@npc_name.size
  152.        if @evname_split == @npc_name[i]
  153.         @class_name = ""
  154.         @evtitle = ""
  155.        end
  156.      end
  157.      @class_name = "" if $game_party.actors[character.id].class_id == 1 or $game_party.actors[character.id].class_id == 26
  158.      @titlesprite.bitmap.draw_text(0, 0, 160, 36, @evtitle, 1)#160 36
  159.      @class_sprite.bitmap.draw_text(0, 0, 160, 36, @class_name, 1)
  160.    end
  161.    ################################################
  162.   update
  163. end
  164. #--------------------------------------------------------------------------
  165. # ● 更新画面
  166. #--------------------------------------------------------------------------
  167. def update
  168.   super
  169.   return if  @character == nil
  170.   # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  171.   if @tile_id != @character.tile_id or
  172.      @character_name != @character.character_name or
  173.      @character_hue != @character.character_hue
  174.     # 记忆元件 ID 与文件名、色相
  175.     @tile_id = @character.tile_id
  176.     @character_name = @character.character_name
  177.     @character_hue = @character.character_hue
  178.     # 元件 ID 为有效值的情况下
  179.     if @tile_id >= 384
  180.       self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  181.         @tile_id, @character.character_hue)
  182.       self.src_rect.set(0, 0, 32, 32)
  183.       self.ox = 16
  184.       self.oy = 32
  185.     # 元件 ID 为无效值的情况下
  186.     else
  187.       self.bitmap = RPG::Cache.character(@character.character_name,
  188.         @character.character_hue)
  189.       @cw = bitmap.width / 4
  190.       @ch = bitmap.height / 4
  191.       self.ox = @cw / 2
  192.       self.oy = @ch
  193.     end
  194.   end
  195.   if @evname != @character.name
  196.     @namesprite.bitmap.clear
  197.     @evname = @character.name
  198.     @evname_split = @character.name.split(/,/)[0]
  199.     if @character.name.split(/,/)[1] != nil
  200.       case @character.name.split(/,/)[1]
  201.       when "0"
  202.         @namesprite.bitmap.font.color.set(255, 255, 255)
  203.       when "1"
  204.         @namesprite.bitmap.font.color.set(120, 120, 120)
  205.       when "2"
  206.         @namesprite.bitmap.font.color.set(255,   0,   0)
  207.       when "3"
  208.         @namesprite.bitmap.font.color.set( 30, 255,   0)
  209.       when "4"
  210.         @namesprite.bitmap.font.color.set(  0, 112, 221)
  211.       when "5"
  212.         @namesprite.bitmap.font.color.set(163,  53, 238)
  213.       when "6"
  214.         @namesprite.bitmap.font.color.set(255, 128,   0)
  215.       when "7"
  216.         @namesprite.bitmap.font.color.set(229, 204, 128)
  217.       else
  218.         @namesprite.bitmap.font.color.set(255, 255, 255)
  219.       end
  220.     end
  221.    
  222.     if @evname_split != "" and @evname_split != nil
  223.       if character.character_name == ""  && character.tile_id == 0
  224.       @evname_split = ""
  225.       end
  226.      if character.is_a?(Game_Player)
  227.         if character.id == 0
  228.          case $game_variables[16]
  229.          when -999999..-150
  230.           @namesprite.bitmap.font.color.set(255,   0,   0)
  231.          when -149..79
  232.           @namesprite.bitmap.font.color.set(255, 255, 255)
  233.          when 80..999999
  234.           @namesprite.bitmap.font.color.set(247, 102,   0)
  235.          else
  236.          end
  237.        else
  238.         @namesprite.bitmap.font.color.set(30, 255, 0)
  239.       end
  240.        for i in 0..@npc_name.size
  241.         if @evname_split == @npc_name[i]
  242.         @namesprite.bitmap.font.color.set(30, 255, 0)
  243.         end
  244.        end
  245.       end
  246.       @namesprite.bitmap.draw_text(0, 24, 160, 36, @evname_split, 1)
  247.     end
  248.     ################################################
  249.    
  250.    if character.is_a?(Game_Player)
  251.      if $game_party.actors[character.id].armor1_id != 0
  252.       @evtitle = $data_armors[$game_party.actors[character.id].armor1_id].name.to_s
  253.      else
  254.       @evtitle = ""#$game_party.actors[character.id].class_name
  255.     end
  256.      @class_name = $game_party.actors[character.id].class_name
  257.       for i in 0..@npc_name.size
  258.        if @evname_split == @npc_name[i]
  259.         @class_name = ""
  260.         @evtitle = ""
  261.        end
  262.       end
  263.      @class_name = "" if $game_party.actors[character.id].class_id == 1 or $game_party.actors[character.id].class_id == 26
  264.      @titlesprite.bitmap.draw_text(0, 0, 160, 36, @evtitle, 1)#160 36
  265.      @class_sprite.bitmap.draw_text(0, 0, 160, 36, @class_name, 1)
  266.    end
  267.    ################################################
  268.   end
  269.   @namesprite.x = self.x-80
  270.   @namesprite.y = self.y-self.oy-10-@evoy
  271.    ################################################
  272.    if @class_name == ""
  273.    @titlesprite.x = self.x-80
  274.    @titlesprite.y = self.y-123
  275.    
  276.    @class_sprite.x = self.x-80
  277.    @class_sprite.y = self.y-123
  278.    else     
  279.    @titlesprite.x = self.x-80
  280.    #@titlesprite.y = self.y-148 #原人物模型位置
  281.    @titlesprite.y = self.y-141
  282.    
  283.    @class_sprite.x = self.x-80
  284.    #@class_sprite.y = self.y-130 #原人物模型位置
  285.    @class_sprite.y = self.y-123
  286.    end
  287. # @namesprite.visible = $game_switches[12]
  288.   # 设置可视状态
  289.   self.visible = (not @character.transparent)
  290.   # 图形是角色的情况下
  291.   if @tile_id == 0
  292.     # 设置传送目标的矩形
  293.     sx = @character.pattern * @cw
  294.     sy = (@character.direction - 2) / 2 * @ch
  295.     self.src_rect.set(sx, sy, @cw, @ch)
  296.   end
  297.   # 设置脚本的坐标
  298.   self.x = @character.screen_x
  299.   self.y = @character.screen_y
  300.   self.z = @character.screen_z(@ch)
  301.   # 设置不透明度、合成方式、茂密
  302.   self.opacity = @character.opacity
  303.   self.blend_type = @character.blend_type
  304.   self.bush_depth = @character.bush_depth
  305.   # 动画
  306.   if @character.animation_id != 0
  307.     animation = $data_animations[@character.animation_id]
  308.     animation(animation, true)
  309.     @character.animation_id = 0
  310.   end
  311. end
  312. end
  313. #==============================================================================
  314. # ■ Game_Player
  315. #------------------------------------------------------------------------------
  316. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  317. # 本类的实例请参考 $game_player。
  318. #==============================================================================

  319. class Game_Player < Game_Character
  320. def name
  321.   return $game_party.actors[0].name
  322. end
  323. end
复制代码



第2步: 在$game_system里增加个存放NPC携带物品的全局变量:

[pre lang="ruby"]#==============================================================================
# ■ Game_System
#------------------------------------------------------------------------------
#  处理系统附属数据的类。也可执行诸如 BGM 管理之类的功能。本类的实例请参考
# $game_system 。
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :map_interpreter          # 地图事件用解释程序
  attr_reader   :battle_interpreter       # 战斗事件用解释程序
  attr_accessor :timer                    # 计时器
  attr_accessor :timer_working            # 计时器执行中的标志
  attr_accessor :save_disabled            # 禁止存档
  attr_accessor :menu_disabled            # 禁止菜单
  attr_accessor :encounter_disabled       # 禁止遇敌
  attr_accessor :message_position         # 文章选项 显示位置
  attr_accessor :message_frame            # 文章选项 窗口外关
  attr_accessor :save_count               # 存档次数
  attr_accessor :magic_number             # 魔法编号
  attr_accessor :npc_carry_items          # NPC携带的物品集合
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #--------------------------------------------------------------------------
  def initialize
    @map_interpreter = Interpreter.new(0, true)
    @battle_interpreter = Interpreter.new(0, false)
    @timer = 0
    @timer_working = false
    @save_disabled = false
    @menu_disabled = false
    @encounter_disabled = false
    @message_position = 2
    @message_frame = 0
    @save_count = 0
    @magic_number = 0
    @npc_carry_items  = Hash["偷窃对象1"=>[[1,11],[2,12],[3,13]],
    "偷窃对象2"=>[[5,15],[6,16],[7,17]],
    "guoxiaomi"=>[[2],[3],[5,5,5]],
    "待定"=>[[],[],[]]]
  end
  #--------------------------------------------------------------------------
  # ● 演奏 BGM
  #     bgm : 演奏的 BGM
  #--------------------------------------------------------------------------
  def bgm_play(bgm)
    @playing_bgm = bgm
    if bgm != nil and bgm.name != ""
      Audio.bgm_play("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch)
    else
      Audio.bgm_stop
    end
    Graphics.frame_reset
  end
  #--------------------------------------------------------------------------
  # ● 停止 BGM
  #--------------------------------------------------------------------------
  def bgm_stop
    Audio.bgm_stop
  end
  #--------------------------------------------------------------------------
  # ● BGM 的淡出
  #     time : 淡出时间 (秒)
  #--------------------------------------------------------------------------
  def bgm_fade(time)
    @playing_bgm = nil
    Audio.bgm_fade(time * 1000)
  end
  #--------------------------------------------------------------------------
  # ● 记忆 BGM
  #--------------------------------------------------------------------------
  def bgm_memorize
    @memorized_bgm = @playing_bgm
  end
  #--------------------------------------------------------------------------
  # ● 还原 BGM
  #--------------------------------------------------------------------------
  def bgm_restore
    bgm_play(@memorized_bgm)
  end
  #--------------------------------------------------------------------------
  # ● 演奏 BGS
  #     bgs : 演奏的 BGS
  #--------------------------------------------------------------------------
  def bgs_play(bgs)
    @playing_bgs = bgs
    if bgs != nil and bgs.name != ""
      Audio.bgs_play("Audio/BGS/" + bgs.name, bgs.volume, bgs.pitch)
    else
      Audio.bgs_stop
    end
    Graphics.frame_reset
  end
  #--------------------------------------------------------------------------
  # ● BGS 的淡出
  #     time : 淡出时间 (秒)
  #--------------------------------------------------------------------------
  def bgs_fade(time)
    @playing_bgs = nil
    Audio.bgs_fade(time * 1000)
  end
  #--------------------------------------------------------------------------
  # ● 记忆 BGS
  #--------------------------------------------------------------------------
  def bgs_memorize
    @memorized_bgs = @playing_bgs
  end
  #--------------------------------------------------------------------------
  # ● 还原 BGS
  #--------------------------------------------------------------------------
  def bgs_restore
    bgs_play(@memorized_bgs)
  end
  #--------------------------------------------------------------------------
  # ● ME 的演奏
  #     me : 演奏的 ME
  #--------------------------------------------------------------------------
  def me_play(me)
    if me != nil and me.name != ""
      Audio.me_play("Audio/ME/" + me.name, me.volume, me.pitch)
    else
      Audio.me_stop
    end
    Graphics.frame_reset
  end
  #--------------------------------------------------------------------------
  # ● SE 的演奏
  #     se : 演奏的 SE
  #--------------------------------------------------------------------------
  def se_play(se)
    if se != nil and se.name != ""
      Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
    end
  end
  #--------------------------------------------------------------------------
  # ● 停止 SE
  #--------------------------------------------------------------------------
  def se_stop
    Audio.se_stop
  end
  #--------------------------------------------------------------------------
  # ● 获取演奏中 BGM
  #--------------------------------------------------------------------------
  def playing_bgm
    return @playing_bgm
  end
  #--------------------------------------------------------------------------
  # ● 获取演奏中 BGS
  #--------------------------------------------------------------------------
  def playing_bgs
    return @playing_bgs
  end
  #--------------------------------------------------------------------------
  # ● 获取窗口外观的文件名
  #--------------------------------------------------------------------------
  def windowskin_name
    if @windowskin_name == nil
      return $data_system.windowskin_name
    else
      return @windowskin_name
    end
  end
  #--------------------------------------------------------------------------
  # ● 设置窗口外观的文件名
  #     windowskin_name : 新的窗口外观文件名
  #--------------------------------------------------------------------------
  def windowskin_name=(windowskin_name)
    @windowskin_name = windowskin_name
  end
  #--------------------------------------------------------------------------
  # ● 获取战斗 BGM
  #--------------------------------------------------------------------------
  def battle_bgm
    if @battle_bgm == nil
      return $data_system.battle_bgm
    else
      return @battle_bgm
    end
  end
  #--------------------------------------------------------------------------
  # ● 设置战斗 BGM
  #     battle_bgm : 新的战斗 BGM
  #--------------------------------------------------------------------------
  def battle_bgm=(battle_bgm)
    @battle_bgm = battle_bgm
  end
  #--------------------------------------------------------------------------
  # ● 获取战斗结束的 BGM
  #--------------------------------------------------------------------------
  def battle_end_me
    if @battle_end_me == nil
      return $data_system.battle_end_me
    else
      return @battle_end_me
    end
  end
  #--------------------------------------------------------------------------
  # ● 设置战斗结束的 BGM
  #     battle_end_me : 新的战斗结束 BGM
  #--------------------------------------------------------------------------
  def battle_end_me=(battle_end_me)
    @battle_end_me = battle_end_me
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    # 计时器减 1
    if @timer_working and @timer > 0
      @timer -= 1
    end
  end
end
[/pre]


第3步: 完善偷窃脚本:

[pre lang="ruby"]#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
module Stolen
  STEAL_SKILL_ID = 1   # 偷盗特技id
end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Scene_Map
  attr_accessor :spriteset
end

#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Window_Npc_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #--------------------------------------------------------------------------
  def initialize(item)
    super(224, 80, 188+100, 320)
    @column_max = 1
    @item = item
    @item_max = @item.size
    self.height = @item.size*32+32
    self.y = (480-self.height)/2
    self.opacity = 160
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def item
    return @item[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @item[index]   
    x = 4
    y = index * 32
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  end

end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Game_Party
  attr_reader   :stealexp
  attr_accessor :stealnpc
  alias initialize_old initialize
  def initialize
    initialize_old
    @stealexp = 0
    @stealnpc = {}
  end
  def add_sexp(n)
    @stealexp = [[@stealexp + n, 0].max, 100].min
  end
end
#-------------------------------------------------------------------------
# ★★★★★★
#-------------------------------------------------------------------------
class Interpreter
  def judge   
    @npc_item = []
    @npc_item.clear
    if @list[0].code == 108
      if @list[0].parameters[0].split(/:/)[0] == "可偷盗对象"
        unless @list[0].parameters[0].split(/:/)[1] == nil
          @npc_item = eval(@list[0].parameters[0].split(/:/)[1])
        end
      end
    end
  end
  #偷盗
  def steal
   unless judge_skill
      @message_waiting = true
      $game_temp.message_proc = Proc.new { @message_waiting = false }
      $game_temp.message_text = "无人会偷盗技能!"
      return true
   end
   if @npc_item.size == 0
      @message_waiting = true
      $game_temp.message_proc = Proc.new { @message_waiting = false }
      $game_temp.message_text = "对方已无任何道具."
      return true
   end
      win = Window_Npc_Item.new(@npc_item)
   loop do
        $game_map.update
        $scene.spriteset.update
        Graphics.update
        Input.update
        win.update
    if Input.trigger?(Input::B)
        win.dispose
        $game_system.se_play($data_system.cancel_se)
        return true
    end  
    if Input.trigger?(Input::C)
        win.dispose
        $game_map.events[@event_id].animation_id = $data_skills[Stolen::STEAL_SKILL_ID].animation2_id
     for i in 1..$data_animations[$data_skills[Stolen::STEAL_SKILL_ID].animation2_id].frame_max*4
        Graphics.update
        $game_map.update
        $game_player.update
        $scene.spriteset.update
     end
     if successful?(@list[2].parameters[0].split(/,/)[1].split(/:/)[1].to_i)
        $game_party.add_sexp(2)  #偷盗经验值上升
        item = win.item
       case item
        when RPG::Item   
          $game_party.gain_item(item.id, 1)
          g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0]
          g_npc.delete_at g_npc.index item.id #这里最好用指令arr.delete_at arr.index,用delete的话会把所有item.id号物品全删了
        when RPG::Weapon
          $game_party.gain_weapon(item.id, 1)
          g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1]
          g_npc.delete_at g_npc.index item.id
        when RPG::Armor
          $game_party.gain_armor(item.id, 1)
          g_npc=$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2]
          g_npc.delete_at g_npc.index item.id
       end
          @wait_count = 1                       
          return true
     else
          #$game_party.add_sexp(1)       #偷盗经验值上升         
          @message_waiting = true
          $game_temp.message_proc = Proc.new { @message_waiting = false }
          $game_temp.message_text = "盗取失败,被发现了!"            
          Audio.se_play("Audio/SE/"+"Glass1",80,100)
          @wait_count = 1         
      if $data_troops[@list[3].parameters[0].split(/:/)[1].to_i] != nil
          $game_temp.battle_abort = true
          $game_temp.battle_calling = true
          $game_temp.battle_troop_id = @list[3].parameters[0].split(/:/)[1].to_i
          $game_temp.battle_can_escape = false
          $game_temp.battle_can_lose = false
          current_indent = @list[@index].indent
          $game_temp.battle_proc = Proc.new { |n| @branch[current_indent] = n }
      end
     end
    break
    end  # end of C键
   end #end of loop do
  end #end of def
   #是否有“盗窃”技能判断
   def judge_skill
    actor = $game_party.actors
    for i in 0...actor.size
     if actor.skills.include?(Stolen::STEAL_SKILL_ID)
        return true
     end
    end
    return false
   end
   #取得物品
   def get_item
    temp_item = []
    #生成物品列表
     for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0].size
      temp_item.push($data_items[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][0].to_i])
    end  
    #生成武器列表
     for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1].size
      temp_item.push($data_weapons[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][1].to_i])
    end  
    #生成防具列表   
     for i in 0...$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2].size
      temp_item.push($data_armors[$game_system.npc_carry_items[$game_map.events[@event_id].name.split(/,/)[0].to_s][2].to_i])
    end  
    #返回物品数组  
    return temp_item
   end
   #偷盗成功判断
   def successful?(n) # n - 对象npc的过失率, 这里暂时设定为100%成功
    s_rate = 101
    return rand(101) < s_rate
   end
  #------------------------------------------  
end
[/pre]

taeckle简单的偷窃脚本_version_0.2.rar

194.66 KB, 下载次数: 8

回复

使用道具 举报

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2021-10-31 17:22:08 | 显示全部楼层
能用就行,但是你没必要把整个game_system都抄下来吧

点评

没时间……  发表于 2021-10-31 17:54
尤其是我在上面帖子附件里打包了整个脚本,大神您还客串了一把被偷窃对象  发表于 2021-10-31 17:51
大神要不你在我这个Version_0.2版本基础上改一改,然后我们申请个教程精品帖子咋样  发表于 2021-10-31 17:49

评分

参与人数 1赞 +1 收起 理由
taeckle + 1 精品文章

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部