DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,835
Reaction score
982
First Language
Chinese
Primarily Uses
N/A
Purpose
Lets you run some codes set by your notetags on some important state timings

Introduction
Code:
*    1. This plugin lets you use notetags to set what happens when a state's
*       added/removed/expired/turn's updated/turn's reset on the battler
*       involved
*    2. You're expected to write JavaScript codes directly, as there are so
*       much possibilities that most of them are just impossible to be
*       covered by this plugin itself, so this plugin just lets you write
*       JavaScript codes that are executed on some important timings

Video

Games using this plugin
None so far

Code:
* @param addNotetagDataTypePriorities
* @type select[]
* @option Data of the actor
* @value actor
* @option Data of the current class
* @value class
* @option Data of learnt skills/action list(Shouldn't be used with Data of usable skills)
* @value skills
* @option Data of usable skills(Shouldn't be used with Data of learnt skills)
* @value usableSkills
* @option Data of possessed items(Shouldn't be used with Data of usable items)
* @value items
* @option Data of usable items(Shouldn't be used with Data of possessed items)
* @value usableItems
* @option Data of the latest skill/item being used(Can double-count with skills/items/usableSkills/usableItems)
* @value latestSkillItem
* @option Data of equipped weapons
* @value weapons
* @option Data of equipped armors
* @value armors
* @option Data of the enemy
* @value enemy
* @option Data of effective states
* @value states
* @option Data of the state to have triggers run
* @value thisState
* @desc Sets data type priorities of the add notetags
* You can use script calls/plugin commands to change this
* @default ["thisState"]
*
* @param removeNotetagDataTypePriorities
* @type select[]
* @option Data of the actor
* @value actor
* @option Data of the current class
* @value class
* @option Data of learnt skills/action list(Shouldn't be used with Data of usable skills)
* @value skills
* @option Data of usable skills(Shouldn't be used with Data of learnt skills)
* @value usableSkills
* @option Data of possessed items(Shouldn't be used with Data of usable items)
* @value items
* @option Data of usable items(Shouldn't be used with Data of possessed items)
* @value usableItems
* @option Data of the latest skill/item being used(Can double-count with skills/items/usableSkills/usableItems)
* @value latestSkillItem
* @option Data of equipped weapons
* @value weapons
* @option Data of equipped armors
* @value armors
* @option Data of the enemy
* @value enemy
* @option Data of effective states
* @value states
* @option Data of the state to have triggers run
* @value thisState
* @desc Sets data type priorities of the remove notetags
* You can use script calls/plugin commands to change this
* @default ["thisState"]
*
* @param resetNotetagDataTypePriorities
* @type select[]
* @option Data of the actor
* @value actor
* @option Data of the current class
* @value class
* @option Data of learnt skills/action list(Shouldn't be used with Data of usable skills)
* @value skills
* @option Data of usable skills(Shouldn't be used with Data of learnt skills)
* @value usableSkills
* @option Data of possessed items(Shouldn't be used with Data of usable items)
* @value items
* @option Data of usable items(Shouldn't be used with Data of possessed items)
* @value usableItems
* @option Data of the latest skill/item being used(Can double-count with skills/items/usableSkills/usableItems)
* @value latestSkillItem
* @option Data of equipped weapons
* @value weapons
* @option Data of equipped armors
* @value armors
* @option Data of the enemy
* @value enemy
* @option Data of effective states
* @value states
* @option Data of the state to have triggers run
* @value thisState
* @desc Sets data type priorities of the reset notetags
* You can use script calls/plugin commands to change this
* @default ["thisState"]
*
* @param expireNotetagDataTypePriorities
* @type select[]
* @option Data of the actor
* @value actor
* @option Data of the current class
* @value class
* @option Data of learnt skills/action list(Shouldn't be used with Data of usable skills)
* @value skills
* @option Data of usable skills(Shouldn't be used with Data of learnt skills)
* @value usableSkills
* @option Data of possessed items(Shouldn't be used with Data of usable items)
* @value items
* @option Data of usable items(Shouldn't be used with Data of possessed items)
* @value usableItems
* @option Data of the latest skill/item being used(Can double-count with skills/items/usableSkills/usableItems)
* @value latestSkillItem
* @option Data of equipped weapons
* @value weapons
* @option Data of equipped armors
* @value armors
* @option Data of the enemy
* @value enemy
* @option Data of effective states
* @value states
* @option Data of the state to have triggers run
* @value thisState
* @desc Sets data type priorities of the expire notetags
* You can use script calls/plugin commands to change this
* @default ["thisState"]
*
* @param turnNotetagDataTypePriorities
* @type select[]
* @option Data of the actor
* @value actor
* @option Data of the current class
* @value class
* @option Data of learnt skills/action list(Shouldn't be used with Data of usable skills)
* @value skills
* @option Data of usable skills(Shouldn't be used with Data of learnt skills)
* @value usableSkills
* @option Data of possessed items(Shouldn't be used with Data of usable items)
* @value items
* @option Data of usable items(Shouldn't be used with Data of possessed items)
* @value usableItems
* @option Data of the latest skill/item being used(Can double-count with skills/items/usableSkills/usableItems)
* @value latestSkillItem
* @option Data of equipped weapons
* @value weapons
* @option Data of equipped armors
* @value armors
* @option Data of the enemy
* @value enemy
* @option Data of effective states
* @value states
* @option Data of the state to have triggers run
* @value thisState
* @desc Sets data type priorities of the turn notetags
* You can use script calls/plugin commands to change this
* @default ["thisState"]

Code:
*    ## Notetag Info
*       1. Among all the same notetag types in the same data, all can be
*          effective
*       2. Each line can only have at most 1 notetag
*       3. The following is the structure of all notetags in this plugin:
*          - <doublex rmmz state triggers>
*          - <state triggers>
*          Where contents are in the form of type suffixes: entries
*          Either of the above can be used, but the 1st one reduce the chance
*          of causing other plugins to treat the notetags of this plugin as
*          theirs, while the 2nd one is more user-friendly
*          - type is one of the following:
*            1. add
*            2. remove
*            3. reset
*            4. expire
*            5. turn
*          - suffixes is the list of suffixes in the form of:
*            suffix1 suffix2 suffix3 ... suffixn
*            Where each suffix is either of the following:
*            val(The notetag value will be used as-is)
*            switch(The value of the game switch with id as the notetag value
*                   will be used)
*            event(The common event with id as the notetag value will be
*                  reserved)
*            (Advanced)script(The value of the game variable with id as the
*                            notetag value will be used as the contents of
*                            the functions to be called upon using the
*                            notetag)
*          - The this pointer of the script suffix is the action involved
*            (Game_Battler.prototype)
*          - entries is the list of entries in the form of:
*            entry1, entry2, entry3, ..., entryn
*            Where entryi must conform with the suffixi specifications
*----------------------------------------------------------------------------
*    # Actor/Class/Learnt Skills/Usable Skills/Posessed Items/Usable Items/
*      Inputted Skill Or Item/Weapon/Armor/Enemy/States/This State Notetags
*      1. add condSuffix eventSuffix: condEntry, eventEntry
*         - Triggers what specified in eventEntry when the state's just added
*           to the battler involved(not when the state already exists before)
*           if condEntry returns a truthy result
*         - condSuffix can be val, switch or script
*         - eventEntry can be event or script
*         - The result of condEntry can be anything as only whether it's
*           truthy matters
*         - If the result of condEntry is falsy, this notetag will be
*           discarded upon such use cases
*         - The result of eventEntry can be anything as it's supposed to run
*           commands instead of returning results
*         - E.g.:
*           <state triggers add switch event: 1, 2> will reserve the common
*           event with id 2 when the state's just added to the battler
*           involved(not when it already exists before) if the game switch
*           with id 1 is on
*      2. remove condSuffix eventSuffix: condEntry, eventEntry
*         - Triggers what specified in eventEntry when the state's just
*           removed from the battler involved(not when the state turn just
*           expired causing the removal) if condEntry returns a truthy result
*         - condSuffix can be val, switch or script
*         - eventEntry can be event or script
*         - The result of condEntry can be anything as only whether it's
*           truthy matters
*         - If the result of condEntry is falsy, this notetag will be
*           discarded upon such use cases
*         - The result of eventEntry can be anything as it's supposed to run
*           commands instead of returning results
*         - E.g.:
*           <state triggers remove val script: true, 3> will always run the
*           JavaScript codes stored as a string in variable with id 3 when
*           the state's just removed from the battler involved(not when the
*           state turn just expired causing the removal)
*      3. reset condSuffix eventSuffix: condEntry, eventEntry
*         - Triggers what specified in eventEntry when the state's turn's
*           just reset due to trying to add that state to the battler
*           involved if condEntry returns a truthy result
*         - condSuffix can be val, switch or script
*         - eventEntry can be event or script
*         - The result of condEntry can be anything as only whether it's
*           truthy matters
*         - If the result of condEntry is falsy, this notetag will be
*           discarded upon such use cases
*         - The result of eventEntry can be anything as it's supposed to run
*           commands instead of returning results
*         - E.g.:
*           <state triggers reset switch event: 1, 2> will reserve the common
*           event with id 2 when the state's turn's just reset due to trying
*           to add that state to the battler involved if the game switch with
*           id 1 is on
*      4. expire condSuffix eventSuffix: condEntry, eventEntry
*         - Triggers what specified in eventEntry when the state's turn's
*           just expired causing the state to be removed from the battler
*           involved if condEntry returns a truthy result
*         - condSuffix can be val, switch or script
*         - eventEntry can be event or script
*         - The result of condEntry can be anything as only whether it's
*           truthy matters
*         - If the result of condEntry is falsy, this notetag will be
*           discarded upon such use cases
*         - The result of eventEntry can be anything as it's supposed to run
*           commands instead of returning results
*         - E.g.:
*           <state triggers expire val script: true, 3> will always run the
*           JavaScript codes stored as a string in variable with id 3 when
*           the state's turn's just expired causing the state to be removed
*           from the battler involved
*      5. turn condSuffix eventSuffix: condEntry, eventEntry
*         - Triggers what specified in eventEntry when the state's turn's
*           just updated without being expired for the battler involved if
*           condEntry returns a truthy result
*         - condSuffix can be val, switch or script
*         - eventEntry can be event or script
*         - The result of condEntry can be anything as only whether it's
*           truthy matters
*         - If the result of condEntry is falsy, this notetag will be
*           discarded upon such use cases
*         - The result of eventEntry can be anything as it's supposed to run
*           commands instead of returning results
*         - E.g.:
*           <state triggers turn val event: true, 2> will always reserve the
*           common event with id 2 when the state's turn's just updated
*           without being expired for the battler involved

Code:
*    # Parameter manipulations
*      1. $gameSystem.setStateTriggersParam(param, val)
*         - Sets the fully parsed value of the parameter param as val
*         - param must be the name of a valid parameter of this plugin
*         - val must be a valid new fully parsed value of the parameter param
*         - Such parameter value changes will be saved
*         - E.g.:
*           $gameSystem.setStateTriggersParam("addNotetagDataTypePriorities", [
*               "thisState"
*           ]) sets the fully parsed value of the parameter
*           addNotetagDataTypePriorities as ["thisState"]
*      2. $gameSystem.stateTriggersParam(param)
*         - Returns the fully parsed value of the parameter param
*         - param must be the name of a valid parameter of this plugin
*         - E.g.:
*           $gameSystem.setStateTriggersParam("removeNotetagDataTypePriorities")
*           returns the fully parsed value of the parameter
*           removeNotetagDataTypePriorities, which should be
*           ["thisState"] if it uses its default parameter value

Code:
* @command setStateTriggersParam
* @desc Applies script call $gameSystem.setStateTriggersParam(param, val)
* @arg param
* @desc The name of a valid parameter of this plugin
* @arg val
* @desc A valid new fully parsed value of the parameter param

Plugins:
1. DoubleX RMMZ Enhanced Codebase
Abilities:
1. Some RMMV plugin development proficiency
(Basic knowledge on what RMMV plugin development does in general with several easy, simple and small plugins written without nontrivial bugs up to 1000 LoC scale but still being inexperienced)

Code:
*      1. Commercial use's always allowed and crediting me's always optional.
*      2. You shall keep this plugin's Plugin Info part's contents intact.
*      3. You shalln't claim that this plugin's written by anyone other than
*         DoubleX or my aliases. I always reserve the right to deny you from
*         using any of my plugins anymore if you've violated this.
*      4. If you repost this plugin directly(rather than just linking back),
*         you shall inform me of these direct repostings. I always reserve
*         the right to request you to edit those direct repostings.
*      5. CC BY 4.0, except those conflicting with any of the above, applies
*         to this plugin, unless you've my permissions not needing follow so.
*      6. I always reserve the right to deny you from using this plugin
*         anymore if you've violated any of the above.

Code:
*      Authors:
*      1. DoubleX
*      Plugin Development Collaborators:
*      - None So Far
*      Bug Reporters:
*      - None So Far
*      Compatibility Issue Raisers:
*      - None So Far
*      Feature Requesters:
*      - None So Far

Code:
 *      { codebase: "1.1.0", plugin: "v1.00b" }(2020 Dec 2 GMT 0400):
 *      1. You no longer have to edit the value of
 *         DoubleX_RMMZ.State_Triggers.PLUGIN_NAME when changing this plugin
 *         file name
*      { codebase: "1.0.0", plugin: "v1.00a" }(2020 Aug 29 GMT 1300):
*      1. 1st version of this plugin finished

Download Link
Demo Link
 
Last edited:

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,835
Reaction score
982
First Language
Chinese
Primarily Uses
N/A
Updates
Code:
 *      { codebase: "1.1.0", plugin: "v1.00b" }(2020 Dec 2 GMT 0400):
 *      1. You no longer have to edit the value of
 *         DoubleX_RMMZ.State_Triggers.PLUGIN_NAME when changing this plugin
 *         file name
 

Krystek_My

Veteran
Veteran
Joined
Dec 29, 2017
Messages
275
Reaction score
74
First Language
Polish
Primarily Uses
RMMZ
Hello, is this possibile to trigger skill when stare is added or expired?
Example would be enemy when killed Explorer dealing damage to autor (unless it got state that turnus effect off).
 
Last edited:

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
2,019
Reaction score
584
First Language
English
Primarily Uses
N/A
Can you use this to run a common event? If so, my brain is exploding with ideas in how to use this
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,835
Reaction score
982
First Language
Chinese
Primarily Uses
N/A
Can you use this to run a common event? If so, my brain is exploding with ideas in how to use this
Code:
*           <state triggers add switch event: 1, 2> will reserve the common
*           event with id 2 when the state's just added to the battler
*           involved(not when it already exists before) if the game switch
*           with id 1 is on
Normally, you don't just run a common event directly, but instead tell the game to reserve that common event so it'll be run when the game can run it.
But usually a common event will be run soon after(or even almost instantaneously) it's reserved, so I think the eventSuffix "event" is worth your try :)
(Of course, this doesn't just work with add, but with all the other type - remove, reset, expire, turn as well)

Hello, is this possibile to trigger skill when stare is added or expired?
Example would be enemy when killed Explorer dealing damage to autor (unless it got state that turnus effect off).
Code:
*      1. add condSuffix eventSuffix: condEntry, eventEntry
*         - Triggers what specified in eventEntry when the state's just added
*           to the battler involved(not when the state already exists before)
*           if condEntry returns a truthy result
*         - condSuffix can be val, switch or script
*         - eventEntry can be event or script
*         - The result of condEntry can be anything as only whether it's
*           truthy matters
*         - If the result of condEntry is falsy, this notetag will be
*           discarded upon such use cases
*         - The result of eventEntry can be anything as it's supposed to run
*           commands instead of returning results
*         - E.g.:
*           <state triggers add switch event: 1, 2> will reserve the common
*           event with id 2 when the state's just added to the battler
*           involved(not when it already exists before) if the game switch
*           with id 1 is on
While your use case of this plugin will demand you to write some Javascript directly, you can still try this notetag on the death state:
<state triggers add script script: 1, 2>
Where the contents of the game variable with id 1 is the following:
JavaScript:
return this.isEnemy() && this.enemy().id === x; // x is the id of the enemy "Explorer"
And that of the game variable with id 2 can be set by the following script call:
JavaScript:
$gameVariables.setValue(2, `
    const subject = BattleManager._subject;
    if (!subject) return;
    subject._result.clear();
    subject._result.used = subject._result.success = subject._result.hpAffected = true;
    subject.gainHp(-y);
    subject.onDamage(y);
    subject.startDamagePopup();
    if (subject._hp <= 0) {
        subject.addState(subject.deathStateId());
        BattleManager._logWindow.displayChangedStates(subject);
    }
    $gameTemp.requestBattleRefresh();
`); // y is the damage dealt to the actor killing that enemy

But if you've to disable this effect when that enemy has certain states, things will be even more complicated and convoluted, because by default, when that enemy dies, all states will be erased from that enemy, meaning that the state trigger will be impossible to check whether those certain states were added to that enemy.
To fix this, you'll have to use a plugin that lets you add permanent states, such as DoubleX_RMMZ_Permanent_States, then change the contents of game variable with id 1 to the following:
JavaScript:
return this._states.intersection([a, b, c]).isEmpty() && this.isEnemy() && this.enemy().id === x; // a, b and c are the ids of permanent states preventing the effects from happening
(You can add as many state ids after the array [a, b, c] as you want, or you can make the array to have just 1 or 2 state ids)
 
Last edited:

Krystek_My

Veteran
Veteran
Joined
Dec 29, 2017
Messages
275
Reaction score
74
First Language
Polish
Primarily Uses
RMMZ
Thanks, that was very helpful. I'll try this out.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
2,019
Reaction score
584
First Language
English
Primarily Uses
N/A
@DoubleX thanks! this is a really powerful script then, with near limitless possibilities!
 

Latest Threads

Latest Posts

Latest Profile Posts

I just don't know why, but it's funny.
5.gif
Ugh. The one time I forget to save every hour or so is also the day my computer crashes. That's life!
Even though I spent 100's of dollars on my game already. I think I might just have to give it away for free. Since I haven't heard back from people if I could use some of their graphics. Even from a global mod here. Maybe I can make a donation thing.
you know, some days you get resentful that game dev is even considered a "fun job" and other days it's like, welp, time to roll up my sleeves and code these molotov cocktails
If you suck at playing trumpets, that is probably why.

Forum statistics

Threads
115,968
Messages
1,094,506
Members
151,242
Latest member
Monopo
Top