【纯脚本+处女作】跨地图寻路导航~
终于独立写出了自己的脚本……可能有很多BUG,欢迎大家指出.
嘛,有的时候在游戏里走迷宫啊什么的,走错路很蛋疼。
啦啦,这个脚本的通途跟指南针啊,导游啊什么的差不多。
详细说明在脚本的注释里了,看看吧
范例下载3
以下是脚本# 跨地图寻路 by fux2# 感谢九夜神尊纠正错误和提供技术支持# rpg.blue## 喵,说明下用法,在事件脚本里输入:## findway(目标所在地图ID,目标X,目标Y),停止命令stopfindway## 即可出现导航箭头~~照着目标走一般就可以到目的地啦~# 此脚本只负责找到可以通向目标的地图,途中障碍神马的无法判读(是你懒吧!)# 还有只能判断常规的事件移动指令,是否需要自动、并行处理事件可以在79行修改# 需要自动行走的可以自行添加(PIA飞!)# 箭头图像"Graphics/Arrow/Arrow.png".197行可以修改# 喵,欢迎来 http://rpg.blue/?65553 逛逛~##============================================================================# 当前地图的目标和箭头显示开关$target = nil $arrowswitch = false$getallevent = false$havefindmapid = [] # 用于记录所有找到的传送事件#--------------------------------------------------------------------------# ● 寻找地图类#--------------------------------------------------------------------------class SearchMap#--------------------------------------------------------------------------# ● 初始化#--------------------------------------------------------------------------def initialize @currentmapid = 1 # 记录当前地图ID @faildcount = 0 # 寻路失败次数 @realway = [] # 正确的路地图以及事件ID @havefindmap = [] # realway寻找过的地图 @fakeway = [] # 错误的路地图以及事件ID @checkways = [] # 用于检查正确的路是否改变 @targetx = 0 # 目标的X坐标 @targety = 0 # 目标的Y坐标 @currrenttargetid = 0 # 记录当前地图的正确传送事件IDend#--------------------------------------------------------------------------# ● 获取当前地图ID#--------------------------------------------------------------------------def get_currentmapId @currentmapid = $game_map.map_id return @currentmapid end#--------------------------------------------------------------------------# ● 获取最大地图数目#--------------------------------------------------------------------------def get_maxmapid $data_mapinfos = load_data("Data/MapInfos.rxdata") return $data_mapinfos.sizeend#--------------------------------------------------------------------------# ● 修改目标地图ID#--------------------------------------------------------------------------def targetmapid=(mapid) @targetmapid = mapidend#--------------------------------------------------------------------------# ● 数组子项是否包含#--------------------------------------------------------------------------def included(arr,str) arr.each do |i| if i.include?(str) return true end end return falseend#--------------------------------------------------------------------------# ● 找出通行路径与获得传送事件ID#--------------------------------------------------------------------------def getway(firsttarget,targetx,targety) @targetx = targetx @targety = targety maxmapid = get_maxmapid nowmapid = get_currentmapId target = firsttarget done = false while done == false # 获取全部传送事件 if $getallevent == false for workcount in 1..maxmapid temp = load_data(sprintf("Data/Map%03d.rxdata", workcount)) for ev in temp.events.values for page in ev.pages for eventline in page.list # 过滤非传送事件、已寻找过事件、自动、并行处理事件. if eventline.code == 201 && $havefindmapid.include?(]) == false && page.trigger != 3 && page.trigger != 4 $havefindmapid.push ] end end end end end # 打开开关以只搜寻一次所有传送事件 $getallevent = true else # 检查所有传送事件是否符合正确的路径 for checkcount in 0..$havefindmapid.size - 1 finded = false tempcheck = $havefindmapid tempmapid = target if tempcheck == tempmapid && @havefindmap.include?(tempcheck) == false && @realway.include?(,tempcheck,tempcheck]) == false && @fakeway.include?(,tempcheck,tempcheck]) == false && finded == false @realway += @havefindmap.push tempcheck @currrenttargetid = tempcheck target = tempcheck finded = true @faildcount = 0 end end # 如果目标就在当前地图(表示找到了~) if target == nowmapid done = true $targetid = @currrenttargetid $trueway = @realway $truetarget = @havefindmap # 如果没有找到目标且真实路径在上一次没有改变 elsif @realway == @checkways if @faildcount >= 2 done = true if $tempVariable1 != nil # 初始化目标 $tempVariable1 = 0 $tempVariable2 = 0 $tempVariable3 = 0 $targetid = nil $arrowswitch = false $game_player.move_backward # 为了避免重复对话,后退一步,可以修改 $game_temp.message_text = "目标无法到达." end else # 如果没有找到路径则失败次数加1并且清空目前的正确道路 @faildcount += 1 @fakeway.push @realway[@realway.size - 1] @realway = [] @havefindmap = [] target = firsttarget end else # 没有找到目标且真实路径改变 @checkways = @realway end end endend#--------------------------------------------------------------------------# ● 当地图更改时更改导航指针#--------------------------------------------------------------------------def changeway check = false finded = false nowmapid = get_currentmapId # 当前地图是否在正确路径列表中 for i in 0..$truetarget.size - 1 if $trueway == nowmapid && finded == false $targetid = $trueway finded = true end end # 如果走出了正确道路则检查是否能返回 if finded == false for j in 0..$havefindmapid.size - 1 if $havefindmapid == nowmapid && included($trueway,$havefindmapid) && check == false $trueway.push $havefindmapid check = true end end # 如果无法返回则…… if check == false check = true Interpreter.new.stopfindway $game_temp.message_text = "乃偏移了导航并且这里无法返回原来的路." end endendend#--------------------------------------------------------------------------# ● 获取事件内容#--------------------------------------------------------------------------class Game_Event < Game_Character# 获取事件内容def parameters return @parametersend# 获取运行编号def code return @codeend# 获取触发方式def trigger return @triggerendend#--------------------------------------------------------------------------# ● 在分割定义里增加方法#--------------------------------------------------------------------------class Interpreter# 打开导航def findway(firsttarget,targetx,targety) # 如果和上次指定目标一样,则不重新扫描 unless firsttarget == $tempVariable1 or targetx == $tempVariable2 or targety == $tempVariable3 $tempVariable1 = firsttarget $tempVariable2 = targetx $tempVariable3 = targety SearchMap.new.getway($tempVariable1,$tempVariable2,$tempVariable3) end $arrowswitch = trueend # 关闭导航def stopfindway $arrowswitch = false returnendend#--------------------------------------------------------------------------# ● 在地图上描绘箭头的类#--------------------------------------------------------------------------class ArrowGuide < Window_Basedef initializesuper(0 , 0, 640, 480) self.opacity = 0 self.back_opacity = 0 self.contents_opacity = 255 self.contents = Bitmap.new(608, 448)end def SetArrow unless $targetid == nil || $arrowswitch == false || $tempVariable1 == nil # 获取地图ID以判断地图是否变化 nowmapid = $game_map.map_id if nowmapid != @id @id = nowmapid unless nowmapid == $tempVariable1 SearchMap.new.changeway end end # 开始描绘箭头 self.contents.clear bitmap = Bitmap.new("Graphics/Arrow/Arrow.png") src_rect = Rect.new(0, 0, 100, 100) # 是否在目标位置 unless nowmapid == $tempVariable1 || $game_map.events[$targetid] == nil x = $game_map.events[$targetid].screen_x y = $game_map.events[$targetid].screen_y else x = ($tempVariable2 * 128 - $game_map.display_x + 3) / 4 + 16 y = ($tempVariable3 * 128 - $game_map.display_y + 3) / 4 + 32 end # 判断目标位置 if y < 48 sy = 0 elsif y > 464 sy = 416 else sy = y - 48 end # 囧 if x < 32 sx = 0 elsif x > 608 sx = 576 else sx = x - 32 end self.contents.blt(sx, sy, bitmap, src_rect) else self.contents.clear endendend#--------------------------------------------------------------------------# ● 在地图上描绘箭头#--------------------------------------------------------------------------class Scene_Map# 不必理解alias fux2 maindef main @arrow = ArrowGuide.new fux2 @arrow.disposeend alias fux2update updatedef update @arrow.SetArrow fux2updateendend复制代码
本帖来自P1论坛作者新坦克君,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=162496若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
页:
[1]