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

[制作教程] How to make the most of custom formulae. Part #1

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

    连续签到: 2 天

    [LV.7]常住居民III

    4456

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 前天 16:26 | 显示全部楼层 |阅读模式
    This tutorial can also be found on my blog at: http://cobbtocs.co.uk/wp/?p=271 || Archive Link

    So earlier today in rpgmaker's irc chat the conversation moved to the scripts someone desired for their game which included:

    favorite foods - i can specify each actors favorite food and when the item is used on them, they heal extra hp or something

    Anyhow I pretty quickly realised a script was not needed to implement this feature. RPG Maker Ace once again proves just how versatile it is because this feature can be implemented in a single input box. In particular this one:





    That formula box alone has tremendous potential. I offered two solutions to the problem.



                    Code:        
    1. if b.id == 1; 500; else; 100; end;
    复制代码




                    Code:        
    1. b.id == 1 ? 500 : 100
    复制代码

    Let us first look at exactly what they are doing. They both check a conditional statement, namely:



                    Code:        
    1. b.id == 1
    复制代码

    For the formula box in general a refers to the attacker or user and b refers to the defender or recipient, who may or may not be the same.

    Any way what we are checking is that the recipient's id is equal to 1. Please note that this example is about an item which should be usable on party members only and therefore b is always going to be an actor (party member in English). So essentially we are checking that the person who the item is being used on is first in the database (Eric by default).

    Now let's look at the rest of those lines.



                    Code:        
    1. if b.id == 1; 500; else; 100; end;
    复制代码

    If you've done any programming before you will recognise this as a standard if statement. If you're confused about the presence of the semi-colons then let me quickly explain that they are like a way of inserting a new line. Were we not restricted to a single line then we could have written it like this:



                    Code:        
    1. if b.id == 1
    2. 500
    3. else
    4. 100
    5. end
    复制代码

    So what this means is when the character id equals 1, heal 500HP otherwise heal 100HP. The other version achieves the same result but might be a little less clear if you are not overly familiar with ruby.



                    Code:        
    1. b.id == 1 ? 500 : 100
    复制代码

    It still has the conditional, it is still checking if the item is being used on Eric but the rest of the code you could say has been condensed. This effectively boils down to:



                    Code:        
    1. condition ? true : false
    复制代码

    The last thing two things I want to say before moving on are firstly that for more complicated situations you are probably better going the if statement route and the last thing is that while the formula box is pretty powerful you need to be aware that it is capped at a certain length (let's be grateful that we use a & b and not attacker & defender) and if there is an error in your formula the skill will just miss repeatedly rather than crash the game.

    Right so that concludes the explanation section of this tutorial. I personally find having a lot of examples to work from quite helpful so this next section is going to be a problem and solution section and hopefully one of them will be close enough to what you hope to achieve that you can adapt it.

    Scenario: Half your party are demi-humans or robots and require different healing items than the rest of your party.

    There are some quite creative solutions to this problem but for the sake of this tutorial I want to keep is simple. So the solution I offer just checks the ids again.



                    Code:        
    1. (b.id==1 or b.id==3 or b.id==4) ? 500 : 0
    复制代码

    A couple of things I would like to draw your attention to. I have omitted the spaces on both sides of == because when we're space conscious they are wasted characters. The other feature is the ors they act like you'd expect but be careful when using and because it has a bit more to it.

    Scenario: One character's favourite food is peanut butter sandwiches but another character is allergic to peanuts.

    So the way I'm going to implement it is that Eric gets a bonus 100 health when he eat the sandwich but Natalie is afflicted by poison when she eats one.



                    Code:        
    1. if b.id==1;200;elsif b.id==2;b.add_state(2);0;else;100;end;
    复制代码

    So it was a bit more complicated this time so I went the route of the if statement, elsif is a way of checking another condition if the first one wasn't met. So let's just talk it through, if Eric gain 200HP, if Natalie add status number 2 (poison) otherwise restore 100HP.

    Scenario: You have a thunder skill which doors more damage when outside, which you control with a switch

    This is just a switch example.



                    Code:        
    1. $game_switches[x] ? 500 + a.mat * 4 - b.mdf * 2 :  200 + a.mat * 4 - b.mdf * 2
    复制代码

    I've also included in it an example of how to include the default formula so you can see how to incorporate it.

    Scenario: I have a skill whose power I want to control through a variable

    Easy enough. Here's how to do 10 times the value of the variable.



                    Code:        
    1. $game_variables[x] * 10
    复制代码

    Scenario: I have a gamber and I want him to use dice skills e.g. he rolls two six sided dice, the skill does 100 times the combined number of the faces. It does double if he rolls a double and 10000 if he rolls snake eyes.

    This one has a lot in it so we'll look at it closely. We'll use the if method and then use the rand(x) method which returns a number from 0 to x-1 meaning we will add 1 to it to simulate dice. We will also need to create some local variables, I will use c & d (DO NOT USE a &  
    .



                    Code:        
    1. c=1+rand(6);d=1+rand(6);if c==1 and d==1;10000;elsif c==d;c*400;else;(c+d)*100;end;
    复制代码

    It's not perfect, I would quite like to know what he rolled rather than just seeing the damage. Don't worry the solution to this new problem will be shown in the next tutorial.

    Scenario: We want a skill like White Wind (a final fantasy move which restores someone's current health).

    An easier one for once, we want the target's (  
      hp



                    Code:        
    1. b.hp
    复制代码

    Other parameters you can use:

    hp,mp,tp,mhp (Maximum Hit Points), mmp *Maximum Magic Points), atk,def,mat (Magic ATtack power),mdf,agi,luk

    Scenario: What about demi?

    Demi was a move which took a quarter of your current health.



                    Code:        
    1. b.hp / 4
    复制代码

    Scenario: I want a skill which uses someone else's stat e.g. my princess is bossing her guard around.

    This is easier than you think, as long as it's a particular character.



                    Code:        
    1. $game_actors[1].atk * 4 - b.def * 2
    复制代码

    Eric attack!

    Scenario: I want a skill to do x

    Leave a comment and I will try my best to direct you.


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

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-14 15:47 , Processed in 0.091081 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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