State Add/Remove Commands

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,329
Reaction score
11,930
First Language
English
Primarily Uses
RMMV
State Add/Remove Commands v1.01
Shaz
Introduction
This script lets you enter RGSS script commands to be run when a state is added or removed. Like calling a common event when a state is added, or setting one state to be replaced by another after a certain number of turns.

Versions
Code:
 1.01  26 May 14  Fix issue with + sign in regular expressions

Features
- Make something happen when a state is removed.
- Multiple commands may be run for a single state.

How to Use
Paste the script into a new slot below Materials.
In a state's note box, enter onadd: command or onremove: command, where command is any valid RGSS script command.
If a command requires more than will fit in the note box, allow it to wrap to the next line automatically - do NOT use the enter key to go to a new line.
Anything from onadd: or onremove: to the next manual line break will be executed.
You may have several onadd: or onremove: commands for a single state.

Script
Get it here

Examples
If you want to call common event 8 when a state is added, enter the following as the note:


 
Code:
onadd: $game_temp.reserve_common_event(8)
If you want state 16 to be added when state 15 is removed (replace one state with another), enter the following into the note of state 15:
Code:
onremove: add_state(16)
If you want to add a new state when state 20 is removed, and that new state will be 21 if the battler’s hp is 50% or higher, and 22 if lower, enter the following into the note of state 20 (allow it to wrap automatically)
Code:
onremove: if hp_rate < 0.5; add_state(20); else; add_state(21); end;
You could also enter this to achieve the same thing:
Code:
onremove: add_state(hp_rate < 0.5 ? 20 : 21)
Feel free to provide a scenario in the comments, and I will give you the command you should use. Game_Interpreter is a good place to look, and any of the properties or methods in Game_Battler or Game_BattlerBase can be used.

FAQ



Credit and Thanks
- Shaz

Author's Notes
Free to use in commercial games. Please give credit.
 
Last edited by a moderator:

Syltti

Devout Follower of Yuri
Veteran
Joined
Sep 2, 2013
Messages
178
Reaction score
55
First Language
English
Primarily Uses
RMMV
Thanks a lot, Shaz~ ^_^
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,642
Reaction score
2,972
First Language
Tagalog
Primarily Uses
this is nice Shaz
 

Syltti

Devout Follower of Yuri
Veteran
Joined
Sep 2, 2013
Messages
178
Reaction score
55
First Language
English
Primarily Uses
RMMV
Did exactly what I needed~
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,728
Reaction score
281
First Language
English
Primarily Uses
RMMV
Excellent work on this one, I can see the possibilities.
 

Vide infra

Warper
Member
Joined
Jul 19, 2013
Messages
3
Reaction score
0
First Language
Spanish
Primarily Uses
Yes,it works,sorry.It was my browser that was causing the problem.
 

geoffok

Villager
Member
Joined
Dec 7, 2013
Messages
9
Reaction score
2
First Language
English
Primarily Uses
I just wanted to say thank you for this. I have been searching for a solution to my problem for several days and finally found this. /highfive
 

Ice Cluster

Veteran
Veteran
Joined
Feb 4, 2013
Messages
68
Reaction score
6
First Language
German
Primarily Uses
RMMV
Hey, is there a way to have a state add another one, when it expires, but not when it gets cured by an item?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,329
Reaction score
11,930
First Language
English
Primarily Uses
RMMV
Try setting up your item so that it removes this state, AND removes the new state that would have been added. IF you add them both as features, making sure the order is correct (remove this state first, remove the new state second), it should work. It SHOULD remove this state, which will trigger adding the new state, and then will remove the new state.


If that doesn't work, I'd make the item call a common event that removes this state, and then removes the new state.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,072
First Language
English
Hey, is there a way to have a state add another one, when it expires, but not when it gets cured by an item?
You need to make the following assumption: a state that expires without curing, means that it has zero turns left. What gets tricky is when you have a cure effect that occurs WHEN the state expires, but that's a special case.

In that case, you can say something like

onremove: add_state(YOUR_NEW_STATE) if @state_turns[THIS_STATE_ID] == 0Or possibly 1, I don't remember exactly whether it is reduced to zero or not.Alternatively, you can use this, which attaches itself to the "state expire" logic: progressive states, which follows basically the same logic I have described.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,329
Reaction score
11,930
First Language
English
Primarily Uses
RMMV
lol - did you check the thread that question was posted in Hime? ;)
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,230
Reaction score
3,072
First Language
English
No. Which is why I edited in a solution using the current script afterwards.
 
Last edited by a moderator:

Ice Cluster

Veteran
Veteran
Joined
Feb 4, 2013
Messages
68
Reaction score
6
First Language
German
Primarily Uses
RMMV
Thanks for the quick answers. I'll try out your solutions.
 

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
When I try to have it, on a fresh project, so that on removal, a state recovers the battler's MP, it won't work.

I just tried

onremove: self.mp += 100in the notes box of a state and had it so it removes itself after 1 turn, just to test it out.

And yet the state fades and the call does nothing.

onremove: self.add_state(2)works just fine.

Would this have something to do with the fact that this script only deals with Battlerbase?

The original idea was to have it so that when MP is zero, you have to wait a certain number of turns for an MP Rejuvination state to wear off then the battler's MP would be restored. Kind of like in Kingdom Hearts 2, where you cast Curaga and it full heals your party yet puts your MP at unusable till a certain amount of time passes.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,329
Reaction score
11,930
First Language
English
Primarily Uses
RMMV
It's meant to work on Game_BattlerBase (mp wouldn't be available if it didn't).


I have figured out WHY it's not working. I don't understand it, or have a fix yet. I will appeal to the gurus of regular expressions.
 

Arsist

Veteran
Veteran
Joined
May 16, 2014
Messages
140
Reaction score
10
Primarily Uses
Alrighty, I await your solution *salutes*

And that's so strange because you would think your script would be able to handle it.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,329
Reaction score
11,930
First Language
English
Primarily Uses
RMMV
It's a funny regular expression thing. Regular expressions and I do not like each other very much.
 

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

Latest Threads

Latest Profile Posts

Well if you're going to create a JRPG, learn from the best. DRAGON QUEST XI S: Echoes of an Elusive Age - Definitive Edition purchased ^-^
Oh man I was so stressed to launch my android demo It looks like it turned out fine when testing with play testers dayum its such a good feel :kaoangry:
I think I've seen 4-5 covers for Toss a Coin to Your Witcher by now.
Year of the Rat. Plague in China. Hmmm...
is it just me or have posts gotten way more boring ever sense the forum updated

Forum statistics

Threads
93,621
Messages
914,048
Members
123,193
Latest member
RickBadguy11
Top