Common Event Variables

commonEventVariables1

This script automatically updates a set of “common event variables” throughout the game. The purpose is to make it easier for developers to design events that rely on information such as who used a skill.

The main purpose of this script is to provide a way to specify common event arguments. These arguments are stored in game variables, which makes it easy to use for the event editor and some script calls when necessary.

The variables will be updated automatically whenever a skill or item is used, on the map or in a battle.

Download

Script: download here

Installation

Place this script below Materials and above Main

Usage

Object Access

The following objects are automatically set when a common event is used

$game_temp.common_event_user   - stores the user
$game_temp.common_event_target - stores the target
$game_temp.common_event_item   - stores the item used.
$game_temp.common_event_skill  - stores the skill used

You can access them in your common event script calls as needed. All values are nil if no data is available.

Variable Designation

In the configuration, set the ID of the game variables to store the common event variables. The game automatically tracks the following data upon item or skill use:

  • the user (actor or enemy ID)
  • the target (actor or enemy ID)
  • the skill (skill ID)
  • the item (item ID)

Note that the skill and item are stored in separate variables.
You can reference these variables in your events or script calls.

For common event effects, only the first common event will have this
information available. The data is lost after the first common event
finishes running. I have not figured out when is a good time to clear out
temporary data.

You may also like...

24 Responses

  1. Muzya says:

    HI Hime! I’m using this script, but i can’t get it to check the class id of the user of an item that runs a common variable.
    i tried with

    $game_temp.common_event_user.class_id == 1
    $game_temp.common_event_user.class.id == 1

    But they didn’t worked. Does this script checks for the actor’s class id?

    • SymbolsWriter says:

      Hi! I’m not Hime, and I don’t have the time to properly test it atm, but you can try smth like this:

      $game_actors[$game_variables[X]].class_id

      Where $game_variables[X] is the variable that you set as the “User_Variable” in the script’s settings.

  2. SymbolsWriter says:

    Hi!

    Can I ask, is it necessary to to clear out temporary data, or can the line doing it
    ($game_temp.clear_common_event_variables unless $game_temp.common_event_reserved?) be safely commented out?
    It appears to be conflicting with some other script I’m using, seemingly clearing out the data too soon, before it can even be used, but apparently it works fine if I remove this line (or with the line intact, but in a clean project).

    • Anonymous says:

      Hey Symbol. I ask to you cuz looks that you know about this and cuz hime looks to not be responding to this page anymore.
      Maybe you can help me with this. I can’t make that the branch do something when the actor use an skill.

      What I want to do is that: when an actor use an skill, a picture of their face shows.
      Now, I make in the skills that I want this to happend, that the common event “User Skills” call.

      Now in the common event “User Skills”, I made a Branch where when the variable 10 is = to 1, the picture of actor 1 appear.
      But nothing happend.
      (it’s supposed that the ID of variable 10 have the Actor ID)

      • SymbolsWriter says:

        Hello! Unfortunately, I don’t think I can help you with just the information that you provided.
        It would probably be best to ask on the RPG Maker forums, and include a screenshot of your common event. Feel free to message me with a link to your thread (I have the same nickname on the forum as here – SymbolsWriter), and I’ll see if I can help you if no one else does it first.

  3. AngryAragami says:

    Hime, I have a question. How can I use this to pull specific stats? The gist of what I want to do is use the variables of who the user and target are in order to allow the common event to find out what they have in a stat. For example, using this so the common event can find the atk of the user and def of the target.

    • Hime says:

      In your common event, you can use conditional branches with the script condition

      $game_temp.common_event_user.atk
      $game_temp.common_event_target.def
      

      To get the user's ATK and target's DEF respectively.

      So for example, if you wanted your common event to do something only if the target's defense is less than half the user's attack, you could say in your condition

      $game_temp.common_event_target.def < $game_temp.common_event_user.atk / 2
      
  4. piksalh says:

    No matter how I try, I cant find a proper way to make it work in my project. I want to show specific text when player casts skill on specific enemy. Let’s say if enemy with ID 001 is target, show text after using skill “Enemy 1”, if Enemy with ID 002 is target, show “Enemy 2”, etc. I tested on empty project – still no luck.

    I added common event in Attack skill, then in first common event I added conditional branch with script $game_temp.common_event_target == 1 and show text “Enemy 1”. I never get that text in the battle when using skill on Enemy ID 001.

    • Hime says:

      $game_temp.common_event_target is an object, not a number. If you want to know the position of the enemy is the first position, you can use

      $game_temp.common_event_target.enemy_id == 1

      Note that this the target MUST be an enemy in this case. If it is an actor it will crash.

  5. nat says:

    🙁 i need something like this to return the enemy id not the spot that enemy takes in the battle…

  6. formica says:

    Thanks for your great works but I think the download link is broken. How can I get that?

  7. Awesome says:

    Hmm, there seems to be a bug here…the script never sets the target of the skill/item, and it stays zero. Trying to use $game_temp.common_event_target brings up this error:

    “Script ‘Game_Interpreter’ line 450: NoMethodError occurred.

    undefined method `common_event_target=’ for #”

    • Awesome says:

      (the comment cut out something: basically, it was Game_Temp: (and then a hexadecimal offset))

    • Hime says:

      Have you tried this in a new project? Did you set up your variables correctly?

      • Awesome says:

        I just tried this in a clean project by inserting a common event in the Attack skill, and then using it. In that common event was a conditional branch that said $game_temp.common_event_target = 1, and if it did, display a message. When testing it, he same NoMethodError from before showed up.

        And I did set up my variables correctly.

      • Awesome says:

        Well, that fixed that error.
        It’s still returning zero, though, no matter what, variable or through $game_temp.common_event_target.

      • Awesome says:

        Stupid me, I didn’t realize that it starts from zero and not one. Sorry for wasting your time. This is a great script. 🙂

        Thank you!

Leave a Reply to Awesome Cancel reply

Your email address will not be published. Required fields are marked *