[XP] Skill Self Inflicted State without Common Events

What I'm trying to get is when a character cast magic/skill The Caster get inflicted with a state let call it "Tired" this cannot be done with common event due to anyone able to equip any magic or skill in my game.
I opened up my project to see how I did that. It is pretty simple overall, you can add it through the damage formula box. Here is an example I found for myself:

dmg = a.atk * 5.8 - b.def * 2; a.addState(5); dmg;

You can probably move it around a bit, but the important part you are looking for is a.addState(5) - just be sure to replace the 5 with whatever number state you want to inflict on the user of the skill.
Thxs, I still havn't figure it out where to put it yet(might be due to the battle system I'm using) if it still giving me problem I'll ask again.
there is 1 problem with .addstate() in damage formulas. it only gets added if it doesnt miss
but if u use yanflys action sequences plugin u can use the note tags to have the state get added to the caster hit or miss
http://yanfly.moe/2015/10/10/yep-3-battle-engine-core/ is required
http://yanfly.moe/2015/10/11/yep-4-action-sequence-pack-1/
the note tag is
<follow action>
add state x: user
</follow action>
replace x with the state's number
Isnt plugin are for MV?
My mistake, I did not see that this was for XP - my solution would not work for XP. My apologies!
Even if it by mistakes thxs for trying
@ItemNazo This script should do what you're looking for. Instructions are in the script, but it's pretty simple.

Spoiler
Code:
#===============================================================================
# Self State
# Author: Mobius XVI
# Version: 1.0
# Date: 18 MAY 2018
#===============================================================================
#
# Introduction:
#
#   The purpose of this script is to allow you to apply states to a skill user
#       even when the target of the skill is someone else.
#
# Instructions:
#
#  - Place this script below all the default scripts but above main
#
#  - Create a Common Event (CE) with a script call. In the script call place
#        the following snippet:
#
#        Mobius::Self_State.apply_state(State_ID)
#
#  - Tag your skill with the CE that you just made, and you're done!
#
# Issues/Bugs/Possible Bugs:
#
#   - None
#
#  Credits/Thanks:
#    - Mobius XVI, author
#    - ItemNazo, for requesting it
#
#  License
#    The MIT License (MIT)
#
#    Copyright (c) 2018 darmes
#
#     Permission is hereby granted, free of charge, to any person obtaining a copy
#     of this software and associated documentation files (the "Software"), to deal
#     in the Software without restriction, including without limitation the rights
#     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#     copies of the Software, and to permit persons to whom the Software is
#     furnished to do so, subject to the following conditions:
#
#     The above copyright notice and this permission notice shall be included in all
#     copies or substantial portions of the Software.
#
#     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#     SOFTWARE.
#   
#    Further, if you do decide to use this script in a commercial product,
#    I'd ask that you let me know via a forum post or a PM. Thanks.
#
#===============================================================================
# ** Self State - EDIT BELOW THIS LINE AT OWN RISK
#===============================================================================
module Mobius
  module Self_State
    
    def self.apply_state(state_ID)
      # get active battler
      if $scene.is_a?(Scene_Battle)
        active_battler = $scene.active_battler
      else
        return
      end
      active_battler.add_state(state_ID)
    end
    
  end
end
#--------------------------------------------------------------------------
# Changes to class Scene_Battle
#--------------------------------------------------------------------------
class Scene_Battle
    attr_reader :active_battler
end
@MobiusXVI Thanks you so much this work 100% flawless.

Original thread: https://forums.rpgmakerweb.com/threads/xp-skill-self-inflicted-state-without-common-events.95357/