设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2305|回复: 5
打印 上一主题 下一主题

[已经过期] 求思路,我想做一个随机的各种NPC开门进来并执行公共事件

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
18 小时
注册时间
2014-6-4
帖子
20
跳转到指定楼层
1
发表于 2014-6-18 11:13:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
想了好久,还是不得要领,可能是思路不对,求思路~~感谢

ps,另外小小的问一下,如何让走到指定位置?因为NPC位置是随机的,所以不能用指定路线。

十分感谢!~

点评

是做商店或者餐厅的游戏吗?NPC是顾客吧...  发表于 2014-6-18 11:47

Lv1.梦旅人

梦石
0
星屑
151
在线时间
208 小时
注册时间
2012-7-10
帖子
170
2
发表于 2014-6-18 11:28:44 | 只看该作者
入口有几个么……不用脚本的话比较麻烦,你可以设置一个变量,随机赋值再判断条件确定NPC位置,根据不同位置设置不同路线,不过每种NPC都要设置一次有点麻烦,额……LZ还是看其他人有没有什么比较好的脚本吧
事件只会越用越熟,在用脚本前想想能否能用事件简便处理
回复 支持 反对

使用道具 举报

Lv5.捕梦者 (管理员)

老黄鸡

梦石
0
星屑
41103
在线时间
7568 小时
注册时间
2009-7-6
帖子
13498

开拓者贵宾

3
发表于 2014-6-18 13:11:29 | 只看该作者
这有个现成的脚本,我给你改了改可以让事件寻路
但是把返回的路径转成移动指令还得另外有人帮你写
很简单的事情。(现在有点事
  1. #==================================================================#
  2. # AStar Core v1.01 by 禾西 on 2012.01.02
  3. #------------------------------------------------------------------#
  4. # (此算法基于 4 方向)
  5. # public methods
  6. # * new(Game_Map map)
  7. #     生成關聯地圖的 A* 實例
  8. # * set_origin(int ox, int oy)
  9. #     設置起始點(超過地圖范圍會引起 Runtime Error )
  10. # * set_target(int tx, int ty)
  11. #     設置終止點(超過地圖范圍會引起 Runtime Error )
  12. # * Array do_search(bool print_rst = false)
  13. #     進行尋路,返回包含移動信息的數組
  14. #
  15. # private methods
  16. # * int _f(x, y)
  17. #     f 值算法
  18. # * print_data
  19. #     數據打印算法(此方法僅在 do_search(true) 時被使用)
  20. #==================================================================#
  21. #
  22. #   修改:Fux2
  23. #   可以使$game_player之外的事件寻路
  24. #
  25. #調用方法
  26. #    ac = $game_map.events[self.event_id]
  27. #    astr = AStar.new($game_map,ac)
  28. #    astr.set_target(0, 0)
  29. #    path = astr.do_search
  30. #
  31. #    把第一行换成ac = nil就是玩家寻路
  32. #
  33. #==================================================================#
  34. class AStar
  35.   Point = Struct.new(:x, :y)
  36.   public
  37.   # ============================================================== #
  38.   # 初始化數據
  39.   # ============================================================== #
  40.   def initialize(map,act=nil)
  41.     [url=home.php?mod=space&uid=250514]@ACT[/url] = act ? act : $game_player
  42.     @map_width  = map.width
  43.     @map_height = map.height
  44.     @g_data = Table.new(@map_width, @map_height)
  45.     @f_data = Table.new(@map_width, @map_height)
  46.     @p_data = Table.new(@map_width, @map_height)
  47.     @ox,@oy = @act.x,@act.y
  48.     @tx = 0;@ty = 0
  49.     @openList = []
  50.     @g = 0
  51.     @search_done = false
  52.   end
  53. #~   # ============================================================== #
  54. #~   # 設置 起始點
  55. #~   # ============================================================== #
  56. #~   def set_origin(ox, oy)
  57. #~     @ox = ox;@oy = oy
  58. #~     if is_Overmap(ox, oy)
  59. #~       raise RuntimeError, "Origin location is overmap!"
  60. #~     end
  61. #~   end
  62.   # ============================================================== #
  63.   # 設置 目標點
  64.   # ============================================================== #
  65.   def set_target(tx, ty)
  66.     @tx = tx;@ty = ty
  67.     if is_Overmap(tx, ty)
  68.       raise RuntimeError, "Target location is overmap!"
  69.     end
  70.   end
  71.   # ============================================================== #
  72.   # 開始尋路
  73.   # ============================================================== #
  74.   # 主邏輯
  75.   def do_search(print_rst = false)
  76.     x = @ox;y = @oy
  77.     @g_data[x, y] = 2;@f_data[x, y] = 1
  78.     @openList << [x, y]
  79.     t0 = Time.now
  80.     t = 0
  81.     begin
  82.       t += 1
  83.       point = @openList.shift
  84.       return [] if point == nil
  85.       check_4dir(point[0], point[1]) # ->檢查 4 方向
  86.     end until @search_done
  87.     if @g_data[@tx,@ty] == 1
  88.       @tx = point[0];@ty = point[1];
  89.     end
  90.     t1 = Time.now
  91.     make_path # ->生成路徑
  92.     if print_rst
  93.       print "#{t1 - t0}, #{t}\n"
  94.       print_data # ->打印數據
  95.     end
  96.     return @path
  97.   end

  98.   private
  99.   # ============================================================== #
  100.   # 檢查 4 方向
  101.   def check_4dir(x, y)
  102.     @g = @g_data[x, y] + 1
  103.     mark_point(x, y - 1, 8) # ->檢查單點
  104.     mark_point(x, y + 1, 2) # ->檢查單點
  105.     mark_point(x - 1, y, 4) # ->檢查單點
  106.     mark_point(x + 1, y, 6) # ->檢查單點
  107.   end
  108.   # ============================================================== #
  109.   # 檢查單點
  110.   def mark_point(x, y, dir)
  111.     if is_Overmap(x, y) # ->檢查地圖是否超界
  112.       return
  113.     end
  114.     if @g_data[x, y] > 1
  115.       return
  116.     end
  117.     if check_passibility(x, y, dir) # ->檢查通行度
  118.       f = _f(x, y)
  119.       @g_data[x, y] = @g
  120.       @f_data[x, y] = f
  121.       point = @openList[0]
  122.       if point.nil?
  123.         @openList.push [x, y]
  124.       elsif (f <= @f_data[point[0], point[1]])
  125.         @openList.unshift [x, y]
  126.       else
  127.         @openList.push [x, y]
  128.       end
  129.     else
  130.       @g_data[x, y] = 1
  131.       @f_data[x, y] = _f(x, y)
  132.     end
  133.     if x == @tx && y == @ty
  134.       @search_done = true
  135.     end
  136.   end
  137.   # ============================================================== #
  138.   # 生成路徑
  139.   def make_path
  140.     x = @tx;y = @ty
  141.     @path = []
  142.     while !(x == @ox && y == @oy) #TODO:有過多障礙時死轉……
  143.       @g = @g_data[x, y]
  144.       @best_f = 0
  145.       dir = 0
  146.       dir = make_step(x, y - 1, 2)||dir # ->生成單步
  147.       dir = make_step(x, y + 1, 8)||dir # ->生成單步
  148.       dir = make_step(x - 1, y, 6)||dir # ->生成單步
  149.       dir = make_step(x + 1, y, 4)||dir # ->生成單步
  150.       @path.unshift(dir)
  151.       case dir
  152.       when 2 then y -= 1;
  153.       when 8 then y += 1;
  154.       when 6 then x -= 1;
  155.       when 4 then x += 1;
  156.       end
  157.       @p_data[x, y] = 1
  158.     end
  159.   end
  160.   # ============================================================== #
  161.   # 生成單步
  162.   def make_step(x, y, dir)
  163.     if @g_data[x, y].nil? || @p_data[x, y] == 1
  164.       return nil
  165.     end
  166.     if (@g - @g_data[x, y]) == 1 || @g == 1
  167.       f = @f_data[x, y]
  168.       if f > 0 && (@best_f == 0 || f < @best_f)
  169.         @best_f = f
  170.         return dir
  171.       end
  172.     end
  173.     return nil
  174.   end
  175.   # ============================================================== #
  176.   # 檢查地圖通行度
  177.   def check_passibility(x, y, dir)
  178.     case dir
  179.     when 2 then y -= 1;
  180.     when 8 then y += 1;
  181.     when 4 then x += 1;
  182.     when 6 then x -= 1;
  183.     end
  184.     return @act.passable?(x, y, dir)
  185.   end
  186.   # ============================================================== #
  187.   # 檢查地圖是否超界
  188.   def is_Overmap(x, y)
  189.     return (x|y|(@map_width - x - 1)|(@map_height - y - 1)) < 0
  190.   end
  191.   # ============================================================== #
  192.   # f 值算法
  193.   def _f(x, y)
  194.     return ((x - @tx).abs + (y - @ty).abs) + @g
  195.   end
  196.   # ============================================================== #
  197.   # 打印數據
  198.   def print_data
  199.     strf = ""
  200.     strg = ""
  201.     (0...@f_data.ysize).each do |y|
  202.       (0...@f_data.xsize).each do |x|
  203.         if @f_data[x, y] == 0
  204.           strf += "  "
  205.         else
  206.           strf += sprintf("%02d", @f_data[x, y])
  207.         end
  208.         strf += ","
  209.         if @g_data[x, y] < 2
  210.           strg += sprintf("%02d", @g_data[x, y])#"  "
  211.         else
  212.           strg += sprintf("%02d", @g_data[x, y])
  213.         end
  214.         strg += ","
  215.       end
  216.       strf += "\n"
  217.       strg += "\n"
  218.     end
  219.     print "f:\n"
  220.     print strf + "\n"
  221.     print "g:\n"
  222.     print strg + "\n"
  223.     strp = ""
  224.     (0...@p_data.ysize).each do |y|
  225.       (0...@p_data.xsize).each do |x|
  226.         if @p_data[x, y] == 0
  227.           strp += "  "
  228.         else
  229.           strp += sprintf("%02d", @p_data[x, y])
  230.         end
  231.         strp += ","
  232.       end
  233.       strp += "\n"
  234.     end

  235.     print "p:\n"
  236.     print strp
  237.     print @path
  238.   end
  239. end
复制代码
RGDirect - DirectX驱动的RGSS,点我了解.
RM全系列成套系统定制请联系QQ1213237796
不接受对其他插件维护的委托
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
18 小时
注册时间
2014-6-4
帖子
20
4
 楼主| 发表于 2014-6-18 14:24:24 | 只看该作者
本帖最后由 xie7 于 2014-6-18 15:57 编辑

是的,请问你有好的办法吗? @正太君

哇这个脚本是将所有的XY都改成坐标吗?不会用~~是讲35行的2个XY改成地址吗?@fux2 还请指导。

话说为什么VA都不给个智能的让NPC移动到指定地方呢~真是……  
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
48
在线时间
784 小时
注册时间
2013-1-4
帖子
1102
5
发表于 2014-6-18 14:59:58 | 只看该作者
lz是说目标地点一定 而中途路径随机吗?

点评

是的呢~~  发表于 2014-6-18 15:56
RM-GUI延期。。。最近被黑心老板压迫T_T
二次元少女的shitake,长着长脸,身高165,蓝色卷双马尾,FCUP,瞳色黑色,病气和御宅属性,是天才少女。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
48
在线时间
59 小时
注册时间
2010-8-19
帖子
68
6
发表于 2014-6-21 18:50:22 | 只看该作者
表示,曾经用纯事件做过一个NPC开门的路径,不过似乎不是楼主要的。里面的路径都是自己设定的呢。
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-25 13:22

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表