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

[制作教程] Make States Turn Counter drop down for every tot steps taken

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    慵懒
    3 天前
  • 签到天数: 207 天

    连续签到: 1 天

    [LV.7]常住居民III

    3646

    主题

    862

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 昨天 13:52 | 显示全部楼层 |阅读模式
    Let's say one of your characters has an ability that they can use only once per day. This ability applies a State that works as a bonus, so perhaps you want to balance the fact that you can use it sparingly by not making the State disappear at the end of the battle, and make it persist a little longer. The standard way to do this is by toggling the "Remove After Battle" and "Remove After Tot Steps" options, but i found the latter a bit limiting. This one cancels the State after you take a tot of steps, but what if you wanted it to lower the State's Turn Counter for every Tot steps you took instead? That's what this Tutorial is here for!

    FOR GRANDMA RANDOR01's RECEIPE YOU'LL NEED:

    - Yanfly's BuffsStateCore

    Ready? Then let's get started!



    PART 1: DATABASE AND YEP_BUFFSSTATESCORE

    Alright, the first part will proceed in the States Database. Here, make sure to toggle the "Remove After Battle" of the States you want to work with OFF, and toggle the "Remove After Tot Steps" option ON. In that, write how many steps you must take for the Turn Counter of that State to drop down.

    Spoiler






    After that, it's time to use Yanfly's plugin. This plugin makes you able to execute JavaScript code in a State's Notetag when that State is Applied, when it's removed, when your party wins, loses or flees from a battle and one of the members has this State and so on. For each of these conditions exists a tag, where we'll write our code:

                    Code:       
    <Custom Victory Effect>target._stateSteps[22] = (target._stateTurns[22] * $dataStates[22].stepsToRemove);</Custom Victory Effect><Custom Escape Effect>target._stateSteps[22] = (target._stateTurns[22] * $dataStates[22].stepsToRemove);</Custom Escape Effect>


    These two tags, respectively, will run their code when the player Party wins a fight or escapes from one. (If your game has battles where the player WILL lose, you might consider using the "<Custom Defeat Effect>"" tag too).
    What does this code do anyway? Basically, it will alter the number of Steps necessary for the State to wear off by taking the State's remaining turns before it expires and multiplies it by the value assigned in the "Remove After Tot Steps" option, which in our case is 20.
    So, for example, if our State has 5 turns left, the player will have to take 100 steps before it wears off.

    This was the first half. Pretty simple, right? Now we have to make it so that the Turn counter will drop down as you walk too!

    PART 2: JAVASCRIPT AND COMMON EVENTS

    Here comes the beefiest part. What we're going to do here is to write a Common Event that will check which States you party members have, and make those States Turn Counter drop down as you walk in the map.
    First of all, set the Common Event of your choice to run on Parallel, and remember to turn ON the Switch that controls it!
    Let's go and take a look at the code we're going to use step by step:

                    Code:       
    //These are the States you want to persist after battle and of which you want the turn counter to drop down as you walk$gameSystem.statesRemainAfterBattle = $gameSystem.statusesRemainAfterBattle || [18, 22];//These are your 4 party members. You can make it count more party members if you want by adding a ",[]" inside it. This variable will work as list for each party member, containing the States in "$gameSystem.statesRemainAfterBattle" they're currently affected from.$gameSystem.memberAfflictedRemain = [[],[],[],[]];


    This is where we declare our main Variables: "statesRemainAfterBattle" and "memberAfflictedRemain". The first variable is an array containing the State that you want to be affected by the "remove by step" thingy we're working on. In the code's example, the States 18 and 22 will be affected.
    The second variable is a 2d Array, that will contain from which of the States in the "statesRemainAfterBattle" variable your Party Members are affected from.

    Here's the code that will check that:

                    Code:       
    for(var i = 0; i < $gameSystem.memberAfflictedRemain.length; i++){   for(var j = 0; j < $gameSystem.statesRemainAfterBattle.length; j++)   {      //If the party member you're checking exists, if he's afflicted by one of the States in "$gameSystem.statesRemainAfterBattle" and if the Turn counter for that State hasn't already reached 0, that State will be added in the Party Member's list      if($gameParty.members() != null && $gameParty.members().isStateAffected($gameSystem.statesRemainAfterBattle[j]))      {         if($gameParty.members()._stateTurns[$gameSystem.statesRemainAfterBattle[j]] > 0)         {            $gameSystem.memberAfflictedRemain.push($gameSystem.statesRemainAfterBattle[j]);         }         else         {            //If the turn counter for this State has reached 0, the State is removed from the Party member            $gameParty.members().removeState($gameSystem.statesRemainAfterBattle[j]);         }      }   }}


    This part of the code runs down checking your Party Members, and for each of them will look at the States they're affected from. If one of those States' ID equals to one of the values in "$gameSystem.statesRemainAfterBattle", then the code will add that ID in the "$gameSystem.memberAfflictedRemain" variable for that party member's instance. The code will also check if the Party's space it's checking isn't empty (like perhaps at the start of the game, when you don't have all your Party Members yet) before adding the State in that Party Member's instance, and if the Turn Counter for that Party Member’s State has already reached 0 it will automatically remove it.

    Now, for the final part. Here's where the code manages the Steps taken by the player and converts them into Turns remaining for that State:

                    Code:       
    for(var j = 0; j < $gameSystem.memberAfflictedRemain.length; j++){   for(var i = 0; i < $gameSystem.memberAfflictedRemain[j].length; i++)   {      //Here it checks the States in the Party Member's list. For each of them, the game sets the remaining turns using the remaining steps to be taken to make it expire.      //In this case, for each 20 steps you take, the State's Turn Counter will drop down by 1      $gameParty.members()[j]._stateTurns[$gameSystem.memberAfflictedRemain[j]] = Math.ceil($gameParty.members()[j]._stateSteps[$gameSystem.memberAfflictedRemain[j] / $dataStates[$gameSystem.memberAfflictedRemain[j]].stepsToRemove);   }}


    This part also runs down checking your Party Members, but in this case it checks the States stored in each of the members instances, and how many steps you must still take before the State expires. The code will proceed to divide that value by that State's n. steps you've chosen, and assign this new value to "_stateTurns", which contains the Turn Counter for that Party Member’s State.

    Here's, for quick reference, the complete code to put in the Common Event:

    Spoiler                Code:       
    ◆Controls Switches:#0010 MembersStatus? = OFF◆Script:$gameSystem.statesRemainAfterBattle = $gameSystem.statesRemainAfterBattle || [16, 18, 22];◆Script:$gameSystem.memberAfflictedRemain = [[],[],[],[]];:Script:for(var i = 0; i < 4; i++){:Script:   for(var j = 0; j < $gameSystem.statesRemainAfterBattle.length; j++){:Script:      if($gameParty.members() != null && $gameParty.members().isStateAffected($gameSystem.statesRemainAfterBattle[j])){:Script:         if($gameParty.members()._stateTurns[$gameSystem.statesRemainAfterBattle[j]] > 0){:Script:            $gameSystem.memberAfflictedRemain.push($gameSystem.statesRemainAfterBattle[j]);:Script:            $gameSwitches.setValue(10, true);:Script:         }else{ $gameParty.members().removeState($gameSystem.statesRemainAfterBattle[j]); }:Script:      }:Script:      else{:Script:         $gameParty.members().removeState($gameSystem.statesRemainAfterBattle[j]);:Script:      }}}◆If:MembersStatus? is ON  ◆Script:var membAfflicted = $gameSystem.memberAfflictedRemain;  :Script:  :Script:for(var j = 0; j < membAfflicted.length; j++)  :Script:{  :Script:   for(var i = 0; i < membAfflicted[j].length; i++)  :Script:   {  :Script:      $gameParty.members()[j]._stateTurns[membAfflicted[j]] = Math.ceil($gameParty.members()[j]._stateSteps[membAfflicted[j]] / $dataStates[membAfflicted[j]].stepsToRemove);  :Script:   }  :Script:}  ◆:Else  ◆:End






    This code will keep running as you walk in the Overworld, constantly checking and updating the Turn Counter of the States of your choice if one or more of your Party Members are affected by it.
    Hope that this can be of help!

    EDIT: Quick Fix at the last section of the code: changed from "Math.round" to "Math.ceil".
    EDIT: Added the complete Script at the end for quick reference. Also added a small conditional: the script won't alter the Members States Turn Counter if no one has at least one of the States you put in "$gameSystem.statesRemainAfterBattle". (Thanks to MushroomCake28 for this one!)


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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-10 02:19 , Processed in 0.139140 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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