Raccoon Game RPG รวมพลนักพัฒนา
[สคริปต์] Enemy detected ขอบเขคการมองของมอน Rpgvx_1024x768b

Join the forum, it's quick and easy

Raccoon Game RPG รวมพลนักพัฒนา
[สคริปต์] Enemy detected ขอบเขคการมองของมอน Rpgvx_1024x768b
Raccoon Game RPG รวมพลนักพัฒนา
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[สคริปต์] Enemy detected ขอบเขคการมองของมอน

Go down

[สคริปต์] Enemy detected ขอบเขคการมองของมอน Empty [สคริปต์] Enemy detected ขอบเขคการมองของมอน

ตั้งหัวข้อ by boyhit Thu Oct 13, 2011 9:51 am

Script นี้เป็นสคริปที่ดีอันนึงเลยครับ พอดีไปเจอมา ไม่ใช่ของผมเองนะ เป็นสคริปที่ทำให้ศัตรูวิ่งเข้ามาหาเรา เมื่ออยู่ในระยะสายตาของศัตรู(กำหนดได้)เจ๋ง
ดีครับ สำหรับคนที่ทำเกมส์ RPG
และชอบทำศัตรูในMapเพราะถ้าเรากำหนดให้มันเคลื่อนหาตัวเอกเนี่ยมันจะวิ่งมา
ตั้งแต่เราเริ่มเกมส์เลยเหอๆ
แต่สคริปตัวนี้ถ้าไม่เข้าไปในเขตุการรับรู้ของมันมันก็เดินเฉยๆ

Credit : Gubid

Code:
#--------------------------------------------------------------------------<br>
<li># Enemy Detection System<br>
</li><li># by Gubid - 8/12/07<br>
</li><li># v 1.2.2 Updated 10/2/07<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Description:<br>
</li><li>#This system allows events that are named something including "ENEMY" then<br>
</li><li>#that event will be told to approach Game_Player, until Game_Player has gotten<br>
</li><li>#a specified distance away. At that time event will return to its original<br>
</li><li>#position if desired. If you happen to get close enough to the returning event<br>
</li><li>#it will begin to follow you again.<br>
</li><li>#<br>
</li><li>#Thanks to Near Fantasia for supplying the slightly modified path finding script.<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#if there are any questions as to the use of this script or<br>
</li><li>#modifications/additions/etc, please post it to the thread on CreationAyslum.net<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li><br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Update_Detect - How to Stop Detection if desired<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#1. Within a event, add a SCRIPT (3rd page)<br>
</li><li>#2. type "update_detect(EVENT_ID, TRUE/FALSE)" -Note: it defaults to false<br>
</li><li><br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#RETURN TO POSITION<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Use this to determine if you would like the event to return to its original<br>
</li><li>#position or not.<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>RETURN_TO_POSITION = true<br>
</li><li><br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#CHASE_SPEED and ENABLE_SPEED_CHANGE<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Use this to set the speed in which enemies will approach after spotting you<br>
</li><li>#and whether or not their speed will change.<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>CHASE_SPEED = 5<br>
</li><li>ENABLE_SPEED_CHANGE = true<br>
</li><li><br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#VIEW_RANGE<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Use this to set the distance in which you must be in order to start the detection<br>
</li><li>#process, or escape to stop.<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>VIEW_RANGE = 5<br>
</li><li><br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#ESCAPE_RANGE<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Use this to set the distance in which you must escape to stop the detection process<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>ESCAPE_RANGE = 9<br>
</li><li><br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#Other Notes<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>#If the event has a custom move route, they will resume that route when finished<br>
</li><li>#chasing you, but if you dont set RETURN_TO_POSITION, then they will resume<br>
</li><li>#their custom route at the location they stopped chasing you.<br>
</li><li><br>
</li><li>class Game_Map<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li># * Frame Update<br>
</li><li>#--------------------------------------------------------------------------<br>
</li><li>alias en_detect_gm_update update<br>
</li><li>def update<br>
</li><li>en_detect_gm_update<br>
</li><li><br>
</li><li># Update map event<br>
</li><li>for event in @events.values<br>
</li><li>if !event.name.include?("enemy")<br>
</li><li>next<br>
</li><li>else<br>
</li><li>if event.character_name != ""<br>
</li><li>if event.stop_detect?<br>
</li><li>next<br>
</li><li>end<br>
</li><li>if check_distance(event.id) == true<br>
</li><li>if event.exclamation == false<br>
</li><li>event.old_type = event.move_type<br>
</li><li>event.move_type = 2<br>
</li><li>if ENABLE_SPEED_CHANGE<br>
</li><li>event.old_speed = event.move_speed<br>
</li><li>event.move_speed = CHASE_SPEED<br>
</li><li>end<br>
</li><li>event.exclamation = true<br>
</li><li>event.animation_id = 98 #98 happens to be the exclamation animation<br>
</li><li>event.f_route.clear<br>
</li><li>end<br>
</li><li>else<br>
</li><li>if event.exclamation == true<br>
</li><li>event.exclamation = false<br>
</li><li>if RETURN_TO_POSITION == true<br>
</li><li>if event.x != @map.events[event.id].x or event.y != @map.events[event.id].y<br>
</li><li>route = get_route(event, @map.events[event.id].x, @map.events[event.id].y)<br>
</li><li>event.run_route(route)<br>
</li><li>end<br>
</li><li>else<br>
</li><li>event.restore_route<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>def check_distance(id = nil)<br>
</li><li>unless id == nil<br>
</li><li>event = $game_map.events[id]<br>
</li><li>range = ($game_player.x - event.x).abs + ($game_player.y - event.y).abs<br>
</li><li><br>
</li><li>if range <= VIEW_RANGE and range > 0<br>
</li><li>return true<br>
</li><li>elsif range <= ESCAPE_RANGE and range > 0 and event.exclamation<br>
</li><li>return true<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>def get_route(event, x=0, y=0)<br>
</li><li>target_x = x<br>
</li><li>target_y = y<br>
</li><li>max = (target_x - event.x).abs + (target_y - event.y).abs + 5<br>
</li><li>position = [[event.x, event.y]]<br>
</li><li>route = [[]]<br>
</li><li>more_step = [0]<br>
</li><li>for i in more_step<br>
</li><li>x = position[0]<br>
</li><li>y = position[1]<br>
</li><li>if !position.include?([x, y + 1]) and event.passable?(x, y, 2)<br>
</li><li>position.push([x, y + 1])<br>
</li><li>route.push(route + [2])<br>
</li><li>if route.size + 1 < max<br>
</li><li>more_step.push(route.index(route + [2]))<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>if !position.include?([x - 1, y]) and event.passable?(x, y, 4)<br>
</li><li>position.push([x - 1, y])<br>
</li><li>route.push(route + [4])<br>
</li><li>if route.size + 1 < max<br>
</li><li>more_step.push(route.index(route + [4]))<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>if !position.include?([x + 1, y]) and event.passable?(x, y, 6)<br>
</li><li>position.push([x + 1, y])<br>
</li><li>route.push(route + [6])<br>
</li><li>if route.size + 1 < max<br>
</li><li>more_step.push(route.index(route + [6]))<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>if !position.include?([x, y - 1]) and event.passable?(x, y, 8)<br>
</li><li>position.push([x, y - 1])<br>
</li><li>route.push(route + [8])<br>
</li><li>if route.size + 1 < max<br>
</li><li>more_step.push(route.index(route + [8]))<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li>if position.index([target_x, target_y]) == false<br>
</li><li>return [2]<br>
</li><li>else<br>
</li><li>return route[position.index([target_x, target_y])]<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li><br>
</li><li>class Game_Event<br>
</li><li>attr_accessor :move_type<br>
</li><li>attr_accessor :move_speed<br>
</li><li>attr_accessor :old_speed<br>
</li><li>attr_accessor :exclamation<br>
</li><li>attr_accessor :old_type<br>
</li><li>attr_accessor :stop_trigger<br>
</li><li>attr_reader :f_route<br>
</li><li><br>
</li><li>def initialize(map_id, event)<br>
</li><li>super()<br>
</li><li>@map_id = map_id<br>
</li><li>@event = event<br>
</li><li>@id = @event.id<br>
</li><li>@erased = false<br>
</li><li>@starting = false<br>
</li><li>@through = true<br>
</li><li>@name = @event.name<br>
</li><li>@exclamation = false<br>
</li><li>@f_route = []<br>
</li><li>@step = 0<br>
</li><li>@old_type = @move_type<br>
</li><li>@old_move_route = @move_route<br>
</li><li>@old_speed = @move_speed<br>
</li><li>@stop_trigger = false<br>
</li><li>moveto(@event.x, @event.y)<br>
</li><li>refresh<br>
</li><li>end<br>
</li><li><br>
</li><li>def stop_detect?<br>
</li><li>return @stop_trigger<br>
</li><li>end<br>
</li><li><br>
</li><li>def restore_route<br>
</li><li>@move_type = @old_type<br>
</li><li>@move_route_index = @original_move_route_index<br>
</li><li>@move_speed = @old_speed<br>
</li><li>refresh<br>
</li><li>return<br>
</li><li>end<br>
</li><li><br>
</li><li>def name<br>
</li><li>return @name<br>
</li><li>end<br>
</li><li><br>
</li><li>alias en_det_update update<br>
</li><li>def update<br>
</li><li>if @f_route.size > 0<br>
</li><li>run_path unless self.moving?<br>
</li><li>if @f_route.size == 0<br>
</li><li>restore_route<br>
</li><li>end<br>
</li><li>end<br>
</li><li>en_det_update<br>
</li><li>end<br>
</li><li><br>
</li><li>def run_route(route)<br>
</li><li>@f_route = route<br>
</li><li>@step = 0<br>
</li><li>end<br>
</li><li><br>
</li><li>def run_path<br>
</li><li>if @f_route.size > 0<br>
</li><li>if @f_route[@step] == nil<br>
</li><li>@f_route = []<br>
</li><li>end<br>
</li><li>action = @f_route[@step]<br>
</li><li>@step += 1<br>
</li><li>case action<br>
</li><li>when 2<br>
</li><li>self.move_down<br>
</li><li>when 4<br>
</li><li>self.move_left<br>
</li><li>when 6<br>
</li><li>self.move_right<br>
</li><li>when 8<br>
</li><li>self.move_up<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>class Interpreter<br>
</li><li>def update_detect(id, set = false)<br>
</li><li>$game_map.events[id].stop_trigger = set<br>
</li><li>end<br>
</li><li><br>
</li><li>def spotted?<br>
</li><li>is_true = 0<br>
</li><li>for event in $game_map.events.values<br>
</li><li>if event.exclamation<br>
</li><li>is_true += 1<br>
</li><li>end<br>
</li><li>end<br>
</li><li>if is_true > 0<br>
</li><li>return true<br>
</li><li>else<br>
</li><li>return false<br>
</li><li>end<br>
</li><li>end<br>
</li><li><br>
</li><li>def change_switch(id = 0, value = false, type = 0, switch = "A")<br>
</li><li>if id > 0<br>
</li><li>if type == 0 #for use of main switches<br>
</li><li>#id is switch_id and value should set to true or false<br>
</li><li>$game_switches[id] = value<br>
</li><li>elsif type == 1 #For use of self switches<br>
</li><li>#id is event.id and switch is the desired selfswitch. It must be text!<br>
</li><li>#value is true or false<br>
</li><li>key = [$game_map.map_id, id, switch]<br>
</li><li># Updates self switch<br>
</li><li>$game_self_switches[key] = value<br>
</li><li>end<br>
</li><li># Refresh map<br>
</li><li>$game_map.need_refresh = true<br>
</li><li>return true<br>
</li><li>end<br>
</li><li>end<br>
</li><li>end</li>

วิธีใช้ก็ง่ายๆ แค่กำหนด event มอนสเตอร์ในแมพ แล้วตั้งชื่อ Event นั้นว่า "enemy" แค่นั้นเอง ง่ายๆ

แต่ข้อเสียคือ การปรับค่าต่างๆ จะใช้กับศัตรูทั้งหมดนะครับ ไม่สามารปรับแต่งศัตรูแต่ละตัวได้น่ะครับ ใครมีฝีมือ ลองไป edit ดูนะ
Credit : Gubid

ปล.
ลบ </li><li> <br> ออกด้วย ไม่งั้น error
</li><li>*****************<br>
boyhit
boyhit
Admin
Admin

ชื่อเล่น : เเอล
ความฝัน : ศิลปิน
จำนวนข้อความ : 1130
เครดิต : 3356
วันที่สมัคร : 09/10/2011
คะเเนนน้ำใจ : 11
เพศ : Male อายุ : 24
เหรียญรางวัล : [สคริปต์] Enemy detected ขอบเขคการมองของมอน Medalhead2

https://raccoongame-rpg.thai-forum.net

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน

- Similar topics

 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ