[RPG VXA] Self variables for events

Devildimos

I ruin memes for a living
Veteran
Joined
Jul 11, 2014
Messages
82
Reaction score
172
First Language
Eglish
Primarily Uses
RMVXA
Hello everyone!

I know there is a script out there that allows you to add Self variables to an event. However it is not exactly how I need it to work.
Or perhaps I don't know how.

Because all of my events spawn randomly in my maps. I would not be able to identify the event's ID.
The Self Variable script I found requires both map_id and Event_id.

So I am looking for a script that does 99% the same as a self switch but with numbers. :p
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
Here you go.

Code:
class Game_SelfVariables
  def initialize
    @data = {}
  end
  
  def [](key)
    @data[key]
  end
  
  def []=(key, value)
    @data[key] = value
    on_change
  end
  
  def on_change
    $game_map.need_refresh = true
  end
  
  # more convenient methods for getting/setting
  def get_value(map_id, event_id, variable_name)
    @data[[map_id, event_id, variable_name]]
  end
  
  def set_value(map_id, event_id, variable_name, value)
    @data[[map_id, event_id, variable_name]] = value
    on_change
  end
end

DataManager.module_eval do
  class << self
    alias_method(:tlb_create_game_objects, :create_game_objects)
    alias_method(:tlb_make_save_contents, :make_save_contents)
    alias_method(:tlb_extract_save_contents, :extract_save_contents)
  end
  
  def self.create_game_objects
    tlb_create_game_objects
    $game_self_variables = Game_SelfVariables.new
  end
  
  def self.make_save_contents
    contents = tlb_make_save_contents
    contents[:self_variables] = $game_self_variables
    contents
  end
  
  def self.extract_save_contents(contents)
    tlb_extract_save_contents(contents)
    $game_self_variables = contents[:self_variables]
  end
end
I've added a get_value and set_value method for you so you can just pass in the map ID, event ID and name of the variable to save you having to remember the key elements. So when you want to set a self variable you'd do

$game_self_variables.set_value(map ID, event ID, varname, value)

And then to get the value you'd do

$game_self_variables.get_value(map ID, event ID, varname)

varname can be anything you want, like "quest_progress" or something. You also don't have to just store numbers in it, value can be any valid object.
 

Devildimos

I ruin memes for a living
Veteran
Joined
Jul 11, 2014
Messages
82
Reaction score
172
First Language
Eglish
Primarily Uses
RMVXA
I was surprised because my notification did not notify me about this :o
So I am sorry for the late reply.

Thank you for making it.
But I do have a few questions as I am a bit confused. As I was testing I came along a few things.
1. Do I have to add the actual map ID or event ID for the call? Because my events spawn in randomly and get copied into the current map.
2. Is it possible to add + or - to the value than only set to a value? Example: $game_self_variables.set_value(map ID, event ID, cloud, +1)
3. the $game_self_variables.get_value(map ID, event ID, varname) where would I put this? Because it does not fit in the Variable script. :s
4. when I want to have a conditional branch for a self_variables how would I do this?
5. When I tried using this : $game_self_variables.set_value(2, 19, cloud, 1)
I get this error
Error.png
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
1. If you're using an event spawn script you'd need some way to figure out the ID of the created event as it does need the actual map and event ID.

2. Yes. I'll go over how to do that when I'm home.

3. It should fit into the "script" command at the end of page 4.

4. The get_value command should fit in the script box for conditional branch but if not I'll figure something out when I'm home for you.

5. You need to put the variable name in quotes.
 

Devildimos

I ruin memes for a living
Veteran
Joined
Jul 11, 2014
Messages
82
Reaction score
172
First Language
Eglish
Primarily Uses
RMVXA
thank you for your reply.
1. Alright. I guess the map ID will be easy to use a $game_variables[1] command in the ID field.
I would be able to store the event's ID in a var as well if I knew how. But as long the self_variable will be unique for the event than it will work.

2. Thank you :)

3. If it did than I would not mention it :p
It will be a problem if I want to add $game_variables[1] to it. :s
Varccc.png

4. I think it will fit in the conditional branch. Not sure if there is a limit.

5. Ah, right. For once we need to use the "s haha.

I think I should explain what I am trying to achieve. Before we continue this.
I am trying to get the pearl abs projectiles to follow turns rather than real time frames. The tool's "Tool Destroy Delay" as it is called works on frames. If I could place a switch on the "Tool Destroy Delay" to pause the count of the projectile. Than I could control when it would disappear. than I could skip all this. But I don't know where or how to put a switch on that.

So I though of taking an alternative way. Making my own projectiles using events.
Because the Pearl ABS script is in real time frames with it's projectile system and not in turns. For some skills and attacks I would need to create my own projectiles using events. Op on the tool's use an event is spawned from another map with Yanfly's Event spawn into the current map. Than it will follow the turn system I evented. But I can only get it to last on the map for 4 turns because there are only 4 self switches. A,B,C and D. After the 4th turn it will disappear. (transported to the comer of the map and than erased. Just in case :p)
So I though a self var will extant the turns it would last on the map.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
287
Reaction score
71
First Language
English
Primarily Uses
RMXP
Where the script says "def get_value" rename it as def get or def value.
As a side note, Rubyists tend to skip the get_ and set_ prefixes, RGSS scripters never got used to default Ruby naming conventions. XD

Another solution:

class Game_Interpreter
def self_vars(map_id, event_id, name)
$game_self_variables[[map_id, event_id, name]]
end

def set_self_vars(map_id, event_id, name, value)
$game_self_variables[[map_id, event_id, name]] = value
$game_map.need_refresh = true
end
end

Then you'd need to call it

self_vars(1, 1, 'name')
set_self_vars(1, 1, 'name', new_value)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top