Stacking States

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Neon Black, Jun 15, 2013.

    Tags:
  1. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    Stacking States v1.1a
    Created by Neon Black

    What is it?
    This script states that can be stacked on top of each other for increased effectiveness.  In other words, having more than 1 instance of the same state on an actor or enemy.  Due to how it works, the "params" and "sp-params" of states in a multiplicative fashion rather than additive which increases the state's effectiveness with each stack.

    How can I use it?
    Insert this script under materials and above main.  The script has no config option, just tags.  Place the tags in a state and it will work on it's own.

    • max stack[2] - Allows two instances of the state to be present at once.  The "2" can be replaced with any number to increase the number of stacks.
    • stack icon[2, 100] - Changes the icon of stack 2 to icon 100.  You can use this tag more than once with different stack numbers to have a different icon for each level.  You can also use any icon rather than 100.

    What does it work with?
    This script should work with most other scripts, but overwrites the methods relating to adding or removing scripts.  For this reason it should go ABOVE any scripts that affect how states are added or removed.

    How can I get the code?
    Version 1.1a (base script, 8.27.2013) is available from my pastebin account here.

    I would like to use this code.
    [​IMG]
    This work is licensed under a Creative Commons Attribution 3.0 Unported License and is available for commercial and non-commercial use.

    Author's Disclaimer:
    I made this script actually as sort of a way to replace buffs.  I wanted a way to increase stats by a little but allow the player to keep on increasing the stat.  Obviously making the stat stack was the answer.  Like I mentioned, the states stacking is multiplicative, so having for example 10 states with 110% HP, the end result would be 259.3% or so, rather than 200%.  Still, I think it gives a nice effect of increasing returns for using a skill multiple times in a row.  As always, enjoy!
     
    Last edited by a moderator: Aug 27, 2013
    #1
    Bonkers, Kenen, Archeia and 1 other person like this.
  2. Engr. Adiktuzmiko

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

    Messages:
    14,640
    Likes Received:
    2,966
    Location:
    Philippines
    First Language:
    Tagalog
    A really nice script and very useful... I think I'm gonna use this sometime...
     
    #2
  3. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,634
    Likes Received:
    14,383
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    It's like you read my mind! I was just thinking about this the other day D8
     
    #3
  4. Dr.Yami

    Dr.Yami 。◕‿◕。 Developer

    Messages:
    994
    Likes Received:
    737
    Location:
    Finland
    First Language:
    Vietnamese
    Primarily Uses:
    Other
    You remind me of YEM :3 Very nice work!
     
    #4
  5. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    Bahaha, and the best part is I'm sitting on like 5 other scripts I need to finish up and polish up for release, all battle related.  These were just first because of how tiny they are.  (Archeia-chan, please approve the last one? ;_; )
     
    #5
  6. Archeia

    Archeia Level 99 Demi-fiend Staff Member Developer

    Messages:
    14,634
    Likes Received:
    14,383
    Location:
    Game Dev Salt Mines
    First Language:
    Filipino
    Primarily Uses:
    VNM
    already done 8D
     
    #6
  7. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    It hadn't been when I posted that. :p
     
    #7
    Archeia likes this.
  8. Rhudra

    Rhudra Veteran Veteran

    Messages:
    30
    Likes Received:
    3
    First Language:
    French
    Hello!

    This script could become very handy!

    One question though... how does it react to the "remove state" feature, and also removing scripts like Yanfly's Lunatic Objects Package - Destruction (Effect No.5: Remove State which removes a state from the user when the skill or the object is used, even if it target someone else) ?

    Does it removes only one? Or all of them?

    To make it clearer i'm thinking to something like a vampire with a bloodsucking skill wich gives him 3 incréments of freshblood state. They give him access to special skills but each of them uses one increment of the state.

    Right now it works but with a limit of one it force to uses bloosuck after each special skill.
     
    Last edited by a moderator: Jul 12, 2013
    #8
  9. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    Script updated to v1.1.

    • Fixed an issue where states would wear off too soon when applied with multiple of the same state.
    The updated version of the script is available from the main post.
     
    #9
  10. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,976
    Likes Received:
    10,676
    First Language:
    English
    Primarily Uses:
    RMVXA
    This looks very interesting.  I have, though one question, which may be a bit dumb, but here goes.

    If I want more than one state to be applied to the same actor at the same time, can each state be stacked?
     
    #10
  11. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    If you have the skill or item apply the state multiple times, you can add several instances of the state to the stack with a single use of the skill.  I believe that's what you're asking.
     
    #11
  12. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,976
    Likes Received:
    10,676
    First Language:
    English
    Primarily Uses:
    RMVXA
    Not quite.

    Suppose I have 2 states, state A and state B.  I have not combined the attributes of A and B into one state, because there will be times when I only want one of them to apply.

    When I want both A and B to be applied at the same time, can I have either or both of them stacking at the same time?

    I hope that's clearer (though I don't guarantee it)
     
    #12
  13. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    Yes you can.  They work independently of each other and that's a default behavior of the core engine.  This just allows multiple instances of the same state to be applied at the same time.  For example, you could have state A applied 5 times and state B applied 8 times on a single character.  That's all this does is allow the same state to be applied even when it's already on the battler.
     
    #13
  14. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,976
    Likes Received:
    10,676
    First Language:
    English
    Primarily Uses:
    RMVXA
    Thanks for that clarification.  I'll definitely be using this script now.

    And thanks for all your work with scripts.  It helps scripting idiots like me enormously.
     
    #14
  15. Kenen

    Kenen Veteran Veteran

    Messages:
    256
    Likes Received:
    153
    First Language:
    English
    Primarily Uses:
    RMMV
    Sorry to bump this, but I cannot get the stacking (or icon switching) to work in a new / blank project. I'm not sure if I'm using the notetags incorrectly, or what. Any help would be appreciated!

    Final edit, hopefully. As stated above, this wasn't working at all for me plug-and-play in a clean project. States were not stacking, and icons were not switching. After a couple of edits, I got the icons to switch and the states to stack.

    However, when a state is removed, the entire stack is being removed. I tried to correct this by editing erase_state, and was able to remove individual stacks by setting up a case statement, but it caused bugs with non-stackable states.

    ##-----------------------------------------------------------------------------## Stacking States v1.1## Created by Neon Black#### For both commercial and non-commercial use as long as credit is given to## Neon Black and any additional authors. Licensed under Creative Commons## CC BY 3.0 - http://creativecommons.org/licenses/by/3.0/.##----------------------------------------------------------------------------## ####----------------------------------------------------------------------------#### Revision Info:## v1.1 - 8.17.2013## Fixed a bug where states would wear off too soon## v1.0 - 3.15.2013## Wrote and debugged main script##----------------------------------------------------------------------------## ##$imported ||= {} ##$imported["Stack_States"] = 1.1 ## ####----------------------------------------------------------------------------#### Instructions:## Place this script in the script editor below "Materials" and above "Main".## This script allows tagged states to be stacked multiple times on a single## battler. Each stacked state acts as a separate state, which makes the## effects multiplicative rather than additive increasing the effectiveness of## the state with each use (when using params and sp-params only). To use this## script, tag any states with the following tags:#### max stack[5] -or- max stacks[5]## - Allows the state to stack up to 5 times. The number can be replaced with## any max value you would like.#### stack icon[2, 100] -or- stack icons[2 100]## - Changes the icon ID of a state to 100 when it is stacked exactly 2 times.## One of these can be made for each level of the stack and it can use any## number for the ID.###### Whenever a skill or something else adds a state to an actor, the state is## added once. To have a skill add more than 1 instance of the state to the## stack, simply have more than one instance of the "Add State" effect on the## skill. This nature also applies to removing states. When the state is## removed, only one instance of it is removed from the stack, rather than## clearing the whole stack.##----------------------------------------------------------------------------## ## ####----------------------------------------------------------------------------#### The following lines are the actual core code of the script. While you are## certainly invited to look, modifying it may result in undesirable results.## Modify at your own risk!###----------------------------------------------------------------------------class Game_BattlerBase def erase_state(state_id) @states -= [state_id] return if state?(state_id) ## Line added to prevent a stack from bugging. @state_turns.delete(state_id) @state_steps.delete(state_id) end def max_state_stack?(state_id) ## Determines if the state is at max stacks. state_stack(state_id) >= $data_states[state_id].max_stacks end def state_stack(state_id) ## Gets the number of times the state is stacked. (@states.count(state_id) || 0) end ## Ken's note: un-commented following block def state_icons ## "uniq" method added and "icon_index" changed. icons = states.uniq.collect {|state| state.icon_index(state_stack(state.id)) } icons.delete(0) icons endendclass Game_Battler < Game_BattlerBase def add_state(state_id) if state_addable?(state_id) ## Line below changed to allow stacking states. add_new_state(state_id) unless max_state_stack?(state_id) reset_state_counts(state_id) @result.added_states.push(state_id).uniq! end end def remove_state(state_id) if state?(state_id) revive if state_id == death_state_id erase_state(state_id) refresh @result.removed_states.push(state_id).uniq! end end def states super ## Ken's note: Removed .uniq endendclass RPG::State < RPG::BaseItem def max_stacks ## Modified state class to add stack capabilities. create_stack_regs @max_stacks || 1 end alias :cp_stack_states :icon_index def icon_index(stacks = 1) ## Added an argument to get icons from stacks. create_stack_regs @stack_icons[stacks] || cp_stack_states end def create_stack_regs return if @finished_up_stack_icons; @finished_up_stack_icons = true @stack_icons = {} note.split(/[\r\n]+/).each do |line| case line when /max stacks?\[(\d+)\]/i @max_stacks = $1.to_i when /stack icons?\[(\d+),? (\d+)\]/i @stack_icons[$1.to_i] = $2.to_i end end endend##-----------------------------------------------------------------------------## End of script.##-----------------------------------------------------------------------------
    Frankly, my scripting knowledge is super limited, so I'm not exactly sure what is what here, or why it wasn't working for me in the first place.

    Under erase_state, this will correctly ADD one stack:

    Code:
    @states += [state_id]
    However, using -= [state_id] to remove a stack instead clears the entire stack.
     
    Last edited by a moderator: Aug 24, 2013
    #15
  16. Greensburg

    Greensburg Veteran Veteran

    Messages:
    32
    Likes Received:
    6
    First Language:
    Spanish
    I'm having an issue with this script. In battle, I can recieve a state a maximum of 4 times (since I put "max stack[4]" in the notes tag for the corresponding state). However, only 1 state remains. What I mean is, I only get the effect of the first one, like if it was the only one activated. Additionally, the show icon commands don't work past the first instance (stack_icon[1,100] works while stack_icon [2, 100] doesn't).

    The state count is still in effect since I only get the recieved stat messages up to the 4th cast.

    Can you give me a hand?

    I'm using yanfly's battle ace engine among other scripts (but I think that one is the only possible conflict).
     
    #16
  17. Neon Black

    Neon Black The Classy Prostitute Member

    Messages:
    1,149
    Likes Received:
    368
    Location:
    Eastern US
    First Language:
    Sarcasm
    I screwed something up. I'll fix it up later tonight before I head to sleep.

    EDIT:  Updated to version 1.1a.  That should fix the issue.
     
    Last edited by a moderator: Aug 27, 2013
    #17
  18. Kenen

    Kenen Veteran Veteran

    Messages:
    256
    Likes Received:
    153
    First Language:
    English
    Primarily Uses:
    RMMV
    a.remove_state(x) still removes the entire stack rather than just one.
     
    #18
  19. Siul

    Siul Veteran Veteran

    Messages:
    70
    Likes Received:
    14
    First Language:
    Spanish
    Hello there.

    I know is almost a necropost but I found out that script way too late. The stack is working as intended but the icon show isn't working on me: instead of changing the icon, it puts the original icon X times on the scroll. I say "on the scroll" because I'm using MOG battle hud and addons, could it be the problem?

    Any help?

    Thanks in advance.
     
    #19
  20. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    Sorry for the necropost, however I'm curious if anyone has any idea if there's a way to check how many stacks of a state there are via a script call?
     
    #20

Share This Page