- Joined
- Nov 14, 2014
- Messages
- 33
- Reaction score
- 15
- First Language
- English
- Primarily Uses
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
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.
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.
Last edited by a moderator:
