VXAce Method to store actor ID of the caster of a skill?

I'm really new to scripting and fairly new to VX Ace in general, though please don't let that influence you to ignore this question because I've been scouring online forums and have yet to find a solution to my problem.

Basically, I had an idea for the combat in my game where each skill would leave the caster in a position (apply a state to them) and that would give them certain advantages, like a reckless attack might do more damage but put the caster in a vulnerable position, lowering their defense.

Unfortunately though, there seems to be no good way to do this. There isn't an option to apply a state to the caster in the skill menu. In searching for a solution to this, I've found that most people will put the state in the damage formula, something like

a.add_state(1); a.atk*4 - b.def*2

The problem with this is that this only applies the state if the attack lands, not if it misses. I need it to apply either way.

My next idea was to use a common event triggered by the skill to apply the state, but this didn't work either. There isn't a way in the event commands to find the caster that triggered the event. So, I figured maybe I could write a script for this. Thus arose another issue; I can only reference the actor ID of a caster DURING THE DAMAGE CALCULATION. The value is wiped immediately after. I have no idea why they did this instead of just overwriting the value but I'm not that fluent in ruby so maybe I'm missing something here. As a note, I would go in and change this myself but the default scripts are kind of insane and really hard for me to understand and navigate.

I figured okay, maybe I can set a variable to the actor ID in the damage calculation, since that's the only time it can be accessed, and then from there, reference the variable in the common event and add the state to that actor. Unfortunately, no matter what I do, I can't seem to get the damage formula to actually change the value of the variable. I've tried

v[1] = a.actor_id; 100

and

$game_variables[1] = a.actor_id; 100

and neither work.

Again, I'm pretty new to ruby and not super familiar with all the RMVXA systems so there might be something really obvious I'm missing, but I'm stumped. Any advice or workarounds welcome.

TLDR
I want to set a game variable to the actor ID of the caster of a skill, but I can't figure out how.
v[1] = a.id
Kinda redundant now...
But heres a script I was messing around with. Applies state/s to user of specific skill regardless of hit or miss
Code:
class Game_Battler < Game_BattlerBase
  SKILL_STATE_MAP = {
    80 => 2,   # Skill ID 80 applies State ID 2
    81 => [2,3]   # Skill ID 81 applies State ID 2 and 3
  }
  alias_method :custom_item_apply, :item_apply

  def item_apply(user, item)
    custom_item_apply(user, item)
    if item.is_a?(RPG::Skill) && SKILL_STATE_MAP.has_key?(item.id)
      state_ids = [SKILL_STATE_MAP[item.id]].flatten
      state_ids.each do |state_id|
        user.add_state(state_id) unless user.state?(state_id)
      end
    end
  end
end
v[1] = a.id
appreciated. This does work, though (and this should have occurred to me) this doesn't work for the same reason just applying the state in the damage calculation doesn't work; it only applies if the attack connects.
Kinda redundant now...
But heres a script I was messing around with. Applies state/s to user of specific skill regardless of hit or miss
Code:
class Game_Battler < Game_BattlerBase
  SKILL_STATE_MAP = {
    80 => 2,   # Skill ID 80 applies State ID 2
    81 => [2,3]   # Skill ID 81 applies State ID 2 and 3
  }
  alias_method :custom_item_apply, :item_apply

  def item_apply(user, item)
    custom_item_apply(user, item)
    if item.is_a?(RPG::Skill) && SKILL_STATE_MAP.has_key?(item.id)
      state_ids = [SKILL_STATE_MAP[item.id]].flatten
      state_ids.each do |state_id|
        user.add_state(state_id) unless user.state?(state_id)
      end
    end
  end
end
Thank you, I'll try this out.

EDIT: Thanks so much. This works great.

Original thread: https://forums.rpgmakerweb.com/threads/method-to-store-actor-id-of-the-caster-of-a-skill.178711/