Call a script when player levels.

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
Title is pretty self explanatory but,

I would like to call a script whenever a player levels up 

e.g. someone might call:

SceneManager.call(Scene_Save)  when player levels up.

How would they go about doing this?

I'm in VXA.

Thanks in advance,​
Tanner​
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,669
First Language
German
Primarily Uses
RMMV
You call a function from a script by adding that function (for example the line you wrote) at the place in the engine where you want that function to happen. There are several possible places where you could call that function and it would be called when an actor levels up - it depends which part of the level-up-process you want to happen before your scene, and which part you want to happen after your scene (level up isn't a single line in the engine, it does a lot like updating skills, updating parameters and more).


So your sentence "when player levels" is not exact enough to give you the line where you should insert the code, please describe in more detail what should be done when.
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
Sorry I was not direct enough, I would to run the script when the player actually gets the level.

For example,

A message states

"Player Reached Level 2!"

then opens a scene

SceneManager.call(Scene_Save) I'd like it to run that code after the player levels up.

And thats it.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,202
First Language
Binary
Primarily Uses
RMMZ
Code:
class Game_Actor  alias :levelupcallthing :level_up  def level_up    levelupcallthing    if @level == 2      SceneManager.call(Scene_Save)    end  endend
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
The BattleManager's gain_exp method is what triggers all party members to gain EXP (and thus level up). But it does ALL actors and then waits for messages to finish, which is what you'd want it to do, but by the sounds of it one actor at a time. Also, that method only runs in battle, so if you have your actors gaining EXP or levels outside of battle, they'd miss out there.


The Game_Actor's display_level_up method is where the level up display is actually created, but there's no logic to wait for the message there. Ideally you'd put the call at the end of that method, after waiting for the message. So you'd need to create a wait_for_message method and call that, followed by your new scene call. You'd have to see if that interferes with BattleManager's default handling (I don't think it will, but I haven't tested).


Or you could just save all your actor levels at the start of BattleManager.gain_exp, then at the end, if any have a higher level, call the new scene for each of them.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,669
First Language
German
Primarily Uses
RMMV
I would to run the script when the player actually gets the level.
Then the script would never run, because the player has no level and never levels - it's the actors that have levels.
Oh - I understand what you probably really want, but you need to think on the consequences and on the precise wording.


This is especially true for the answers you already got - because your mixup between player and actor gave you answers that probably will have sideeffects that you don't want.


For example if you have a party with four actors, and due to a big fight they all gain levels at the same time, then the savescreen will be called four times in sequence, and you have to close them all before you can continue - and the save that would contain all level data would be the last one because the level-up for the later actors would still be in the future at the moment the screen is called first.


I assume what you really want is to call that screen after the level-up for the entire party has been processed, and that isn't as easy as inserting the scriptcall into an actor's levelup function.


The only way it would be as easy would be if your project is limited to a single actor - but that is information we're still missing.
 

Capitán

kind of a big deal
Veteran
Joined
Jul 9, 2013
Messages
572
Reaction score
145
First Language
Engilsh
Primarily Uses
RMMV
Then the script would never run, because the player has no level and never levels - it's the actors that have levels.

Oh - I understand what you probably really want, but you need to think on the consequences and on the precise wording.

This is especially true for the answers you already got - because your mixup between player and actor gave you answers that probably will have sideeffects that you don't want.

For example if you have a party with four actors, and due to a big fight they all gain levels at the same time, then the savescreen will be called four times in sequence, and you have to close them all before you can continue - and the save that would contain all level data would be the last one because the level-up for the later actors would still be in the future at the moment the screen is called first.

I assume what you really want is to call that screen after the level-up for the entire party has been processed, and that isn't as easy as inserting the scriptcall into an actor's levelup function.

The only way it would be as easy would be if your project is limited to a single actor - but that is information we're still missing.
I see what you are saying but I'm not using it for that, I was using that snippet as an example.

I was planning on using for an attribute system in which, whenever a player levels up they gain attribute points.
 
Last edited by a moderator:

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,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top