State Add/Remove Commands

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Shaz, Sep 30, 2013.

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    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: Dec 6, 2015
    #1
  2. Syltti

    Syltti Devout Follower of Yuri Veteran

    Messages:
    178
    Likes Received:
    55
    Location:
    Storyland
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks a lot, Shaz~ ^_^
     
    #2
    Shaz likes this.
  3. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,407
    Likes Received:
    2,821
    Location:
    Philippines
    First Language:
    Tagalog
    this is nice Shaz
     
    #3
    Shaz likes this.
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Ah, good. Hope it does what you need.
     
    #4
  5. Syltti

    Syltti Devout Follower of Yuri Veteran

    Messages:
    178
    Likes Received:
    55
    Location:
    Storyland
    First Language:
    English
    Primarily Uses:
    RMMV
    Did exactly what I needed~
     
    #5
    Shaz likes this.
  6. Vide infra

    Vide infra Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    Spanish
    The link is broken :/
     
    #6
  7. kerbonklin

    kerbonklin Hiatus King Veteran

    Messages:
    1,728
    Likes Received:
    280
    First Language:
    English
    Primarily Uses:
    RMMV
    Excellent work on this one, I can see the possibilities.
     
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Works for me.
     
    #8
  9. Vide infra

    Vide infra Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    Spanish
    Yes,it works,sorry.It was my browser that was causing the problem.
     
    #9
  10. geoffok

    geoffok Villager Member

    Messages:
    9
    Likes Received:
    2
    First Language:
    English
    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
     
    #10
  11. Ice Cluster

    Ice Cluster Veteran Veteran

    Messages:
    68
    Likes Received:
    6
    Location:
    Ulm, Germany
    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?
     
    #11
  12. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    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.
     
    #12
  13. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,055
    Location:
    Toronto
    First Language:
    English
    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: Jan 12, 2014
    #13
  14. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    lol - did you check the thread that question was posted in Hime? ;)
     
    #14
  15. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,055
    Location:
    Toronto
    First Language:
    English
    No. Which is why I edited in a solution using the current script afterwards.
     
    Last edited by a moderator: Jan 12, 2014
    #15
  16. Ice Cluster

    Ice Cluster Veteran Veteran

    Messages:
    68
    Likes Received:
    6
    Location:
    Ulm, Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    Thanks for the quick answers. I'll try out your solutions.
     
    #16
  17. Arsist

    Arsist Veteran Veteran

    Messages:
    140
    Likes Received:
    10
    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: May 25, 2014
    #17
  18. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    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.
     
    #18
  19. Arsist

    Arsist Veteran Veteran

    Messages:
    140
    Likes Received:
    10
    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: May 25, 2014
    #19
  20. Shaz

    Shaz Veteran Veteran

    Messages:
    37,184
    Likes Received:
    11,053
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    It's a funny regular expression thing. Regular expressions and I do not like each other very much.
     
    #20

Share This Page