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

[转载发布] Aluvien's OnSpellCast

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

    连续签到: 2 天

    [LV.7]常住居民III

    4434

    主题

    864

    回帖

    2万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 前天 16:35 | 显示全部楼层 |阅读模式
    Aluvien OnSpellCast v1.0

    Introduction

    During combat, this plugin provides a universal code hook at the time of use of any skill or item. It reads and executes JS code snippets from a wide variety of notetags that are executed when that object uses a skill or is used.

    Features


    • Executes custom code on item use or skill use
    • Code is kept in notetags on the relevant item, including:
    • Actors (executed whenever a specific actor performs an action)
    • Classes (whenever a member of a class acts)
    • Items (whenever the specific item is used)
    • Skills (same as item)
    • Weapons (applied whenever the wielder performs an action)
    • Armors (same as weapons)
    • Enemies (same as Actors)
    • States (executed when an actor with that state performs an action)

    Screenshots

    This plugin does not directly create visual effects.

    Instructions

    This code can be attached to actors, classes, skills, weapons, armors, enemies, and states. I have included the variables a, b, and v, as in standard damage formulas. Put the code in the appropriate notebox between <OnSpellCast></OnSpellCast>

    Example:

    <OnSpellCast>a.gainHp(-v.value(1))a.performDamagea.startDamagePopup() </OnSpellCast>This will subtract an amount of health from the skill user equal to the value of game variable 1, make the user's sprite show the damage animation, and show the damage number. Should you use variables, note that you must create them before using them. In other words, if you use variable 100 while you haven't created more than the page with the first 20 in the GUI, nothing will happen (if you're lucky).

    The code in your notetags will be executed based on its location, in the following order:
     
    Battler (Actor/Enemy)
    Class
    Action (Skill/Item)
    Weapon
    Armor (slot 1 first, then slot 2, and so on)
    State

    This means that you can write spellcast effects that interact on a feed-forward basis. In other words, code for Skill can react to the result of code from Class, but not vice versa.

    Due to the way ._damagePopup works, it is not recommended to have multiple stacking effects create popup values, as only one can be displayed at a time (the most recently created one). If you for some reason must do this, you can chain a variable through all desired effects, so that each one adds a certain amount and then the final effect (likely a passive state) generates an amount of damage equal to the value of that variable.

    Code written here is executed in the context of Game_Action, so ‘this’ refers to Game_Action itself and this.item() refers to the current action. Because of this, you can use any property that falls under Game_Action, even if that property is added by a different plugin (and of course you can access all global properties at any time). For example, a state with this code:

    <OnSpellCast>a.atb += 10000</OnSpellCast>will act as a Haste state when used with Ellye’s ATB, granting an additional 10000 ATB every action until the state expires.

    Script



    /*:===========================================================Aluvien OnSpellCast===========================================================Version: 1.0Release Date: 12/18/2015Inspired by Tsukihime's State Damage Modifiers----------------------------------------------------------@title OnSpellCast@author Aluvien@plugindesc Allows you to write code that will be executed when aspell is cast.@help Allows you to write code that will be executed when a spell is cast. This code can be attached to actors, classes,skills, weapons, armors, enemies, and states. I have includedthe variables a, b, and v, as in standard damage formulas.Put the code in the appropriate notebox between<OnSpellCast></OnSpellCast>Example:<OnSpellCast>a.gainHp(-v.value(1))a.performDamagea.startDamagePopup()</OnSpellCast>This will subtract an amount of health from the skill user equalto the value of game variable 1, make the user's sprite showthe damage animation, and show the damage number. Should youuse variables, note that you must create them before usingthem. In other words, if you use variable 100 while youhaven't created more than the page with the first 20 inthe GUI, nothing will happen (if you're lucky).The code in your notetags will be executed based on its location,in the following order:Battler (Actor/Enemy)ClassSkillWeaponArmor (slot 1 first, then slot 2, and so on)StateThis means that you can write spellcast effects that interacton a feed-forward basis. In other words, code for Skill canreact to code from Class, but not vice versa.Due to the way ._damagePopup works, it is not recommended tohave multiple stacking effects create popup values, as onlyone can be displayed at a time (the most recently createdone). If you for some reason must do this, you can chaina variable through all desired effects, so that each oneadds to a variable and then the final effect (likely apassive state) generates an amount of damage equal tothe value of that variable. */var Imported = Imported || {} ;var RM = RM || {};Imported.onSpellCast = 1;RM.onSpellCast = RM.onSpellCast || {};(function ($) {    $.CastRegex = /<onspellcast>([\s\S]*)<\/onspellcast>/im;    $.spellCastModifier = function(spell) {        if (spell.castModifier === undefined ) {            $.loadNotetagSpellModifiers(spell);        }        return spell.castModifier;    };    $.loadNotetagSpellModifiers = function(spell) {        spell.castModifier = null;        var res = $.CastRegex.exec(spell.note);        if (res) {            var formula = res[1];            spell.castModifier = new Function("a", "b", "v", formula);        }    };    var RM_Game_Action_apply = Game_Action.prototype.apply;    Game_Action.prototype.apply = function(target) {        RM_Game_Action_apply.call(this, target);        if(this._subjectActorId > 0){            this.applyActorModifiers(target);        }else        {            this.applyEnemyModifiers(target);        }    };    Game_Action.prototype.applyOnSpellCastModifiers = function(target) {        var fn = $.spellCastModifier(this.item());        var value = this.applySpellModifier(fn, target);        return value;    };    Game_Action.prototype.applySpellModifier = function(fn, target) {        if (fn) {            var a = this.subject();            var b = target;            var v = $gameVariables;            fn.call(this, a, b, v)        }    };    Game_Action.prototype.applyBattlerCastModifiers = function(battler) {        var fn = $.spellCastModifier(battler);        var value = this.applySpellModifier(fn);        return value;    };    Game_Action.prototype.applyClassCastModifiers = function(actorclass, target) {        var fn = $.spellCastModifier(actorclass);        var value = this.applySpellModifier(fn, target);        return value;    };    Game_Action.prototype.applyEquipCastModifiers = function(weapon, target) {        var fn = $.spellCastModifier(weapon);        var value = this.applySpellModifier(fn, target);        return value;    };    Game_Action.prototype.applyArmorCastModifiers = function(battler, target) {        for(var i = 1; i < battler.equips.length; i++) {            if(battler.equips > 0){                var armor = $dataArmors[battler.equips];                var fn = $.spellCastModifier(armor);                var value = this.applySpellModifier(fn, target);            }        }        return value;    };    Game_Action.prototype.applyStateCastModifiers = function(battler, target) {        var states = this.subject().states();        for(var i = 0; i < states.length; i++){            var fn = $.spellCastModifier(states);            var value = this.applySpellModifier(fn, target);        }        return value;    };    Game_Action.prototype.applyActorModifiers = function(target) {        var battler = $dataActors[this._subjectActorId];        this.applyBattlerCastModifiers(battler, target);        this.applyClassCastModifiers($dataClasses[battler.classId], target);        this.applyOnSpellCastModifiers(target);        this.applyEquipCastModifiers($dataWeapons[battler.equips[0]], target);        this.applyArmorCastModifiers(battler, target);        this.applyStateCastModifiers(battler, target);    };    Game_Action.prototype.applyEnemyModifiers = function(target) {        var battler = $dataEnemies[this.subject()._enemyId];        this.applyBattlerCastModifiers(battler, target);        this.applyOnSpellCastModifiers(target);        this.applyStateCastModifiers(battler, target);    };})(RM.onSpellCast);

    Compatibility

    Works with:

    Ellye’s ATB

    Tsukihime’s State Damage Modifiers

    Yanfly’s Passive States

    Incompatible with:

    Unknown

    The only place I hook into the original code is Game_Action.prototype.apply. Even then, I’m only adding things rather than changing original code, so compatibility should be high so long as you put this plugin after anything else that rewrites that function wholesale.

    Terms of Use

    Free for use in non-commercial or commercial projects. I would like if you dropped me a line so I can look out for the game, but you don’t have to.

    Credits and Thanks

    Tsukihime, whose State Damage Modifiers inspired the basic structure for this plugin.



    本贴来自国际rpgmaker官方论坛作者:Aluvien处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/aluviens-onspellcast.53244/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-7-14 12:55 , Processed in 0.101017 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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