Mysticphoenix   04-21-2014, 10:28 AM
#1
Authors: ForeverZer0
Website : http://forum.chaos-project.com/index.php?topic=6893.0

ซ้ำขออภัย

สคริปนี้จะช่วยให้คุณสั่งหน้าeventให้ทำงานด้วย "อะไรก็ได้"

อะไรก็ได้นี่คือ อะไรก็ได้จริงๆ

ตั้งแต่ปุ่มกด ไปจนถึงเวลาจริงของเครื่องคอม

ต้องใช้ความรู้ภาษา RGSS เล็กน้อย (เพื่อนำไปเขียนเงื่อนไขสั่งหน้า event ให้ทำงาน)


วิธีใช้
1. วางสคริปเหนือ main ตามปกติ

2. ไปที่หน้า event ใส่กล่อง comment ไว้เป็นคำสั่งแรกของหน้านั้น

3. ในกล่อง comment ใส่ข้อความในรูปแบบดังนี้

----------------------------
Custom Trigger
คำสั่ง..................
----------------------------

ตัวอย่าง
----------------------------
Custom Trigger
Input.trigger?(Input::C)
----------------------------
จะทำให้ event หน้านั้นทำงานเมื่อกดปุ่ม C

อีกตัวอย่าง
----------------------------
Custom Trigger
Input.press?(Input::L) && Input.press?(Input::R) &&Input.trigger?(Input::C)
----------------------------
จะทำให้ event หน้านั้นทำงานเมื่อกด C ในขณะที่แช่ปุ่ม L R

อีกตัวอย่าง
----------------------------
Custom Trigger
$game_party.steps == 23423
----------------------------
จะทำให้ event หน้านั้นทำงานเมื่อก้าวเดินมากกว่า 23,423 ก้าว

อีกตัวอย่าง
----------------------------
Custom Trigger
($game_variables[6]* ($game_variables[7]/100)) < 20
----------------------------
จะทำให้ event หน้านั้นทำงานเมื่อนำตัวแปรที่ 6 มาคูณกับตัวแปรที่ 7 หาร 100 แล้วผลลัพธ์น้อยกว่า 20


ข้อควรระวัง ถ้าใส่ Comment วิเศษของเราแล้ว trigger ดั้งเดิมของ event หน้านั้นจะเป็นโมฆะทันที

สามารถใช้กล่อง comment ต่อกันหลายกล่องได้

Script
Code:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Custom Event Triggers
# Author: ForeverZer0
# Version: 1.1
# Date: 10.13.2010
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#                              VERSION HISTORY
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# v.1.0  7.14.2010
#   - Original release
# v.1.1  10.13.2010
#   - Shortened and made more efficient. Added comments.
#   - Eliminated bug and removed an unnecessary Regular Expression.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#
# Explanation:
#
#   Allows you to easily create custom triggers for events. Uses simple comment
#   code in their event page to create a new trigger. If trigger evaluates as
#   'true', their code will execute. Work differently than conditions, since the
#   page conditions must still be met and they are what actually what begin
#   execution of the event commands for that page.
#
# Instructions:
#
#   - Very simple. Make a comment at the TOP of the page you want the custom
#     trigger to execute that simply reads "Custom Trigger". Now in the same
#     comment on the next line, or in another comment directly below the first,
#     simply write the a scripted true/false statement. If this line ever results
#     in a true statement, and the page conditions are met, the page will execute
#     its commands.  
#   - You can use as many comment boxes you need to script the trigger, but they
#     must be consecutive and immediately after the "Custom Trigger" comment. Do
#     not use an arbitrary comment right after these comments, else the game will
#     attempt to include them in the trigger.
#   - This will also disable all other triggers for this page.
#
#     Here's an example:
#
#     Comment: Custom Trigger
#            : Input.press?(Input::L) && Input.press?(Input::R) &&
#            : Input.trigger?(Input::C)
#
#   This will execute the event if the C button is pressed while the L and R
#   buttons are being held down (if page conditions are met).
#
#     Another example:
#
#     Comment: Custom Trigger
#            : $game_party.steps == 23423
#
#   This executes if the party step count is equal to 23423.
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:

#===============================================================================
# ** Game_Event
#===============================================================================

class Game_Event
  
  attr_accessor :trigger
  
  alias zer0_custom_trigger_refresh refresh
  def refresh
    # Normal refresh method.
    zer0_custom_trigger_refresh
    # Search top of current page for the string "Custom Trigger".
    if @page != nil && @page.list[0].code == 108 &&
      @page.list[0].parameters[0] == 'Custom Trigger'
      trigger, list_index = '', 1
      # If found, loop until the next command is not a comment, adding each line
      # of the comments into a single string.
      while [108, 408].include?(@page.list[list_index].code)
        trigger += @page.list[list_index].parameters[0] + ' '
        list_index += 1
      end
      # Set event trigger to -1, which no method exists for by default.
      @custom_trigger, @trigger = trigger, -1
    end
  end
  
  alias zer0_custom_trigger_upd update
  def update
    zer0_custom_trigger_upd
    # If trigger is -1, and the created string evaluates as true, start event.
    if @trigger == -1 && !@erased && eval(@custom_trigger)
      start
    end
  end
end
This post was last modified: 04-21-2014, 10:31 AM by Mysticphoenix.

[Image: webboard%20signature1_zpskhtut2jg.png]
การทำอาหารที่อร่อยที่สุด และเดือดร้อนชาวบ้านมากที่สุด กำลังจะเริ่มขึ้น
  
Users browsing this thread: 1 Guest(s)
Powered By MyBB, © 2002-2024 MyBB Group.
Made with by Curves UI.