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

[制作教程] Creating a Flashlight/Torch

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    4 天前
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    4609

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 2026-7-8 11:50:22 | 显示全部楼层 |阅读模式
    Hi all. We recently implemented this mechanic in our game, Jericho Falls, and thought to share how we did it. Now, we are by no means experts, so there are probably better ways to implement this, but it works.

    In this tutorial, we’ll show you how to create a torch/flashlight that uses batteries. This can also be adapted to anything else that should consume an item on use, like a lantern or whatever.

    This is done via Common Events etc – the only plugins we used (in our case) is HUD Maker Ultra Pro by SRDude for the UI and to keep track of the battery life in the torch and CGMZ Light Effects by Casper Gaming for, well, the light. You can use whatever else you wish, as the concept will probably remain the same.

    Spoiler: Creating the base Torch Common Event
    So, first things first, go to Common Events in your Database and create a common event that the torch item will call (we’ll get to the torch item in a moment). This first common event will activate when the player activated their torch. We want it to switch on or off with player input, and, we also want it to check if there is enough battery life to run the torch, otherwise, it won’t switch on.

    To walk you through the sequence of events in the screenshot:

    There is a conditional branch checking for a switch we called “Torch On”. This switch gets set to “on” if the torch is currently on and “off” if the torch is currently off. Below that is another conditional branch checking if another switch which we called “Torch Dead” is off. This “Torch Dead” switch determines if there is battery power left in the torch or not. If there is no battery power left in the torch, this switch turns on, and if there is still battery power left in the torch, this switch turns off.

    So, if the switch “Torch On” is off (the torch is not currently on) and if the switch “Torch Dead” is off, the “Torch On” switch is toggled to “on” (because you are switching the torch on) and we call the CGMZ Light Effects plugin command to set the light to the player. You can use other plugins for this, or do it without plugins, but we won’t discuss that here. In our common event, we also added a sound effect to play when this happens, to make a sound when the torch goes on, a click, y’know? But it’s optional.

    Anyway, this “Torch Dead” conditional branch has an else branch, as in if the “Torch Dead” switch is on (if there is no more battery power in the torch), we show a message saying that the torch’s battery is dead…and the torch, obviously, is not switched on. You can do whatever you like here.

    In the main “Torch On” conditional branch, there is also an else branch which checks if the torch is currently on. So, if the “Torch On” switch is “on” (the torch is currently on), the “Torch On” switch is set to “off” and the player light is removed. We also have an optional sound effect here.

    So, that’s it for the main torch effect which will be called whenever the player activates the torch item.
    Spoiler: Creating the Torch item
    Next, you need to create the torch item.

    Go to the Items tab in your Database and create your torch item. Customise the description etc of it as you wish. We set ours to be a key item and to not be consumed on use (obviously). In the effects tab, add the “Torch” common event you just made.

    You now have a torch that turns on and off when the player selects or uses the torch item from their inventory. We personally used Keyboard Gamepad Solution by Sang Hendrix to bind this to a hotkey so that the player doesn’t need to go into their inventory every time…but this is obviously not needed and you can customise this however you want to.



    Spoiler: Letting the Torch consume Batteries - Part 1
    Next, we want the torch to use a “battery” item and for the torch’s battery to run down when the torch is on. If you just wanted a torch system with no battery use, then in the previous common event, you can remove the whole “Torch Dead” conditional branch.

    Anyway, next, you’ll need to create two Common Events in your database. One that makes sure that the battery life variable does not go below 0 or above 100 and the other that makes the battery run down when the torch is in use.

    For the Common Event that makes sure that the battery life variable does not go below 0 or above 100, it’s going to be set to parallel and attached to a switch that you should place somewhere in your game, probably on the starting map area. We named this switch “Torch Life”. We also called this common event “Torch Life”. So, to confirm, the common event is set to parallel and is linked to the “Torch Life” switch as a requirement.

    Make two conditional branches. In the first one, create a variable (which will store the torch battery life amount). We called it “Torch Battery”. In this conditional branch, if “Torch Battery” is less than or equal to 0, set the “Torch Battery” variable to 0. In the second conditional branch, check if “Torch Battery” is greater than or equal to 100, and set the “Torch Battery” variable to 100. And that’s it.


    Spoiler: Letting the Torch consume Batteries - Part 2
    Next, make another Common Event for the torch’s battery to run out when the torch is on. Suppose there are many ways to do this, but we used frames to calculate this. We called this common event “Torch Run Down”. It is also a parallel common event and linked to the same switch as the “Torch life” Common Event, namely the “Torch Life” switch.

    In this “Torch Run Down” common event, make a conditional branch to see if the switch “Torch On” is “on”. If this switch is on, control the variable “Torch Battery” with sub operation of 1. Below that, add a wait x frames. We used 120 frames. So, this means that if the torch is on, every 120 frames the torch battery will go down by 1. You can set the frames to whatever you want, or even by how much it should run down.

    Next, create another conditional branch to see if the variable “Torch Battery” is “0”. If this variable is 0 (in other words, if the torch’s battery is empty), clear the light effect you added to your torch (in our case, via CGMZ Light Effects), then control switch “Torch On” to “off” and switch “Torch Dead” to “on”.

    This means that if the battery life is 0/empty, the torch will immediately switch off, and due to the “Torch Dead” switch being checked in the base Torch common event, the player won’t be able to turn it back on, because the battery is dead.

    Almost done.


    Spoiler: Creating the Battery Common Event
    Next, you obviously need a battery item to make the torch work again. So, create a Common Event that will be called when a battery item is used. We called this “Torch Battery”.

    In this common event, do a conditional branch (with an else branch) to check if the “Torch Battery” variable is less than 100 – in other words, if the battery is not full. Then control variable “Torch Battery” and set it to 100. We added a show text command saying that the player replaced the torch’s battery, but you can do whatever you want here. The most important part is to change that variable to 100. Anyway, we also added a change item for the battery item to -1. So, this means that if the player activates/uses the “battery” item in their inventory, and their torch is not full, then the battery item will be consumed, and the torch’s battery life will be full again.

    Next, do another conditional branch inside the above conditional branch to check if the “Torch Dead” switch was “on”. In other words, this will check if the torch was completely dead when the player replaced the battery. In this conditional branch, set the “Torch Dead” switch to “off”.

    Now, for the else branch. In the else branch, we just added a show text saying that the torch’s batteries are still full. What this means is that if the torch’s battery is still at 100/full, then the battery item will not be used, because it is not needed. You can replace the show text with whatever or leave it empty.


    Spoiler: Creating the Battery item
    Now, go to your Items tab in the Database and create a “battery” item. Customise it as you want to. We set ours to be non-consumable, because we are removing 1 battery upon use via the “Torch Battery” common event. In the Effects tab of the item, make it call the “Torch Battery” common event.


    Spoiler: Starting the Torch System
    And lastly, remember to create a blank event somewhere (probably on your starting map) that sets the “Torch Life” switch to “on”. We also suggest setting the “Torch On” and “Torch Dead” switches to “off” and setting the “Torch Battery” variable to 100, so that you can start with a full battery. then, erase event.

    There you go – you now have a fully working torch/flashlight system that consumes batteries. Hope it helps someone.



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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-16 17:28 , Processed in 0.141405 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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