设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 79|回复: 0

[转载发布] KWeatherArea VX

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    7547

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    29101
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    37542

    灌水之王

    发表于 7 天前 | 显示全部楼层 |阅读模式
    KWeatherArea VX

    by Kyonides


    Introduction

    Did you ever want to set a custom weather effect depending on a given area on the current map?
    Now you can do it in RMVX!


    NOTES

    • This scriptlet uses script calls to make that happen.

    • Here an area is synonymous with a rectangle.
    • You can add and remove areas.
    • These custom areas are NOT related to VX's map areas.
    • Removing an active weather area reverts the effects to the last effect you've set via Set Weather Effects event command.
    • If you change the weather in battle, it will revert it to the current area's weather, if any.
    • Please read the embedded notes to learn how to use it properly.

    The Script

                    Ruby:       
    1. # * KWeatherArea VX * #
    2. #   Scripter : Kyonides
    3. #   v1.2.0 - 2025-03-25
    4. # This scriptlet allows you to set regional weather effects on the current map.
    5. # It works as usual. If you enter an area, the rain or snow will soon appear.
    6. # Obviously, it will quickly vanish once you leave that area.
    7. # If you ever remove an active weather area, it will revert the weather to
    8. # the last effect set via weather effects event command if any.
    9. # * Script Call * #
    10. # - Add a Regional Weather Area
    11. # - Step #1
    12. #   Create 2 local variables: Use integers only, i.e. 1, 16 or 25.
    13. #   W stands for Width or how wide this rectangle is supposed to be.
    14. #   H stands for Height or how tall this rectangle is supposed to be.
    15. # area = [X, Y, W, H]
    16. # gm = $game_map
    17. #   Example:
    18. # area = [7, 10, 4, 6]
    19. # gm = $game_map
    20. # - Step #2
    21. #   Use this call now:
    22. #   - AreaID is an integer, 1+.
    23. #   - Type is one of the RM's weather types: 1 being rain, 2 storm & 3 snow.
    24. # gm.add_weather_area(AreaID, Type, area)
    25. #   Example:
    26. # gm.add_weather_area(1, 1, area)
    27. # - Remove a Regional Weather Area (Temporarily?)
    28. #   - AreaID is an integer, 1+.
    29. # $game_map.remove_weather_area(AreaID)
    30. class WeatherArea
    31.   def initialize
    32.     @id = 0
    33.     @type = 0
    34.     @area = Rect.new(0, 0, 0, 0)
    35.   end
    36.   def set_rect(*coords)
    37.     coords = coords.flatten
    38.     @area.x = coords.shift
    39.     @area.y = coords.shift
    40.     @area.width = coords.shift
    41.     @area.height = coords.shift
    42.   end
    43.   def inside?(px, py)
    44.     w = @area.x + @area.width - 1
    45.     h = @area.y + @area.height - 1
    46.     px.between?(@area.x, w) and py.between?(@area.y, h)
    47.   end
    48.   attr_accessor :id, :type, :area
    49. end
    50. class Game_Screen
    51.   def change_weather(type, max)
    52.     @weather_type = type
    53.     @weather_max = (max + 1) * 4.0
    54.     @weather_duration = 0
    55.   end
    56.   def previous_weather
    57.     @weather_type = @weather_type_target
    58.     @weather_max = @weather_max_target
    59.     @weather_duration = 0
    60.   end
    61. end
    62. class Game_Map
    63.   alias :kyon_weather_area_gm_map_init :initialize
    64.   alias :kyon_weather_area_gm_map_stp :setup
    65.   alias :kyon_weather_area_gm_map_up :update
    66.   def initialize
    67.     kyon_weather_area_gm_map_init
    68.     init_weather
    69.   end
    70.   def init_weather
    71.     @weather_map_areas = {}
    72.     @weather_area_id = 0
    73.   end
    74.   def setup(map_id)
    75.     kyon_weather_area_gm_map_stp(map_id)
    76.     load_weather_areas
    77.   end
    78.   def load_weather_areas
    79.     @weather_areas = @weather_map_areas[@map_id] || {}
    80.   end
    81.   def add_weather_area(area_id, new_type, *coords)
    82.     area = WeatherArea.new
    83.     area.id = area_id
    84.     area.type = new_type
    85.     area.set_rect(*coords)
    86.     areas = @weather_map_areas[@map_id] ||= {}
    87.     areas[area_id] = area
    88.     @weather_areas = areas
    89.   end
    90.   def remove_weather_area(area_id)
    91.     @weather_areas.delete(area_id)
    92.     return if @weather_area_id != area_id
    93.     reset_weather
    94.   end
    95.   def reset_weather
    96.     @screen.previous_weather
    97.     @weather_area_id = 0
    98.   end
    99.   def update
    100.     kyon_weather_area_gm_map_up
    101.     update_weather_areas
    102.   end
    103.   def update_weather_areas
    104.     return if @weather_areas.empty?
    105.     px, py = $game_player.xy
    106.     return if @weather_x == px and @weather_y == py
    107.     @weather_x = px
    108.     @weather_y = py
    109.     new_area = @weather_areas.find {|key, val| val.inside?(px, py) }
    110.     unless new_area
    111.       reset_weather
    112.       return
    113.     end
    114.     return if @weather_area_id == new_area[0]
    115.     @weather_area_id, area = new_area
    116.     @screen.change_weather(area.type, 10)
    117.   end
    118.   def aftermath_weather_area
    119.     if @weather_area_id == 0
    120.       reset_weather
    121.     else
    122.       area = @weather_areas[@weather_area_id]
    123.       @screen.change_weather(area.type, 10)
    124.     end
    125.   end
    126. end
    127. class Game_Player
    128.   def xy
    129.     [@x, @y]
    130.   end
    131. end
    132. class Spriteset_Battle
    133.   alias :kyon_weather_area_sprtst_btl_crt_pix :create_pictures
    134.   alias :kyon_weather_area_sprtst_btl_up_pix :update_pictures
    135.   alias :kyon_weather_area_sprtst_btl_disp :dispose
    136.   def create_pictures
    137.     create_weather
    138.     kyon_weather_area_sprtst_btl_crt_pix
    139.   end
    140.   def create_weather
    141.     @weather = Spriteset_Weather.new(@viewport2)
    142.     update_weather
    143.   end
    144.   def update_weather
    145.     @weather.type = $game_map.screen.weather_type
    146.     @weather.max = $game_map.screen.weather_max
    147.     @weather.ox = $game_map.display_x / 8
    148.     @weather.oy = $game_map.display_y / 8
    149.     @weather.update
    150.   end
    151.   def update_pictures
    152.     kyon_weather_area_sprtst_btl_up_pix
    153.     update_weather
    154.   end
    155.   def dispose
    156.     @weather.dispose
    157.     kyon_weather_area_sprtst_btl_disp
    158.   end
    159. end
    160. class Scene_Battle
    161.   alias :kyon_weather_area_scn_btl_end :battle_end
    162.   def battle_end(result)
    163.     $game_map.aftermath_weather_area
    164.     kyon_weather_area_scn_btl_end(result)
    165.   end
    166. end
    复制代码




    Terms & Conditions

    Free for use in ANY game.
    Please include my nickname in your game credits.
    Also mention the forum where you found it.

    That's it!



    本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/kweatherarea-vx.176484/

    本帖子中包含更多资源

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

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-7-30 20:34 , Processed in 0.141377 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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