Applying a state with reduced duration

I am sorry to make another help thread today, but I am really trying to figure things by myself with no avail. 🙁

I have a state, let's say it is Haste, that boosts AGI and last 10 turns. I also have a skill that gives the user Haste, but only for 1 turn.

I could make two Haste statuses, one lasting 10 turns and another one lasting 1 turn, but this creates two problems: first of all, the two statuses could stack (or just showing at the same time, that is visually bad). Second, when comes to enemies that have dispel abilities it would increases the amount of checks I need to do to make sure every status will be correctly removed, and I don't want to fill the database with double/triple/etc. versions of statuses.

I have Yanfly's Buff & State Manager but doesn't help me:
- If I make Haste a 1 turn duration baseline and use Yanfly's script to boost it by 9 turns using other skills, the result would be an exploit because a player could repeatedly use the "boost" skill to get unlimited turns of Haste (I am honestly surprised Yanfly's script allows this).
- If I make Haste a 10 turn baseline and use Yanfly's script to reduce it to 1 turn only by the skill that would give the "nerfed" version of Haste, this would backfire when the character would have the "real" 10 turns Haste because using the "nerfed" Haste skill would completely wipe the "real" Haste duration.

I could make a workaround by making a check to see if the user has Haste status or not, and if he doesn't have it the skill would call another skill (skill link) that applies Haste with Yanfly's script to decimate 9 rounds from it, but it is honestly a mess, I am sure there is a simple method to achieve what I want.

So the question is: maybe using a Common Event call on the skill's effects, can I make a script call that reduces turns of a status an actor has?

Thanks again.
there is a simple solution to the "double effect": Make it two different haste states, but on all skills that apply "haste 10" have them remove haste 1, and on all skills that apply haste 1 have them remove haste 10 as an additional effect.

The disadvantage of this is that by casting haste 1 you can effectively remove haste 10 before the time is up, effectively shortening the haste.
But that might even be wanted by the player, and it can easily be given an ingame explanation as well.

Using common events will cause some problems here because by default the common events are all executed at the end of the turn, so you've to look for a plugin if those disadvantages are not acceptable.
Using common events will cause some problems here because by default the common events are all executed at the end of the turn, so you've to look for a plugin if those disadvantages are not acceptable.

The purpose of the skill is that you Dodge (= defend) for that turn and you will have Haste for the next turn, so it wouldn't be a problem.
Hm, I haven't worked with Yanfly's yet, but if I were to use Himework's Conditional States and State Charges...

-State Haste lasts for 1 turn/action.

-State 1 checks if Haste doesn't exists and adds Haste, otherwise it adds a "spill" state (a state that does nothing and disappears, aka no effect).

-State 10 checks if Haste doesn't exist and add 10 charges of Haste, otherwise the spill state.

-Bad news is that the State Charges script changes state removal so that it removes a Charge, so you would have to remove Haste 10 times unless you a) use erase_state(Haste) or b) add a Conditional State designed to remove all that Haste.
If anyone is interested, I managed to actually come up with a script with the help of a friend that studied a little Ruby. I don't know if it will work in the long run, but my tests so far were fine. We called it "Arbitrary Turns".

Code:
#--------------------------------------------------------------------------
# * Add State With Arbitrary Turns
#--------------------------------------------------------------------------
class Game_Battler
  def add_state_param(state_id, param)
    if state_addable?(state_id)
      add_new_state(state_id) unless state?(state_id)
      state = $data_states[state_id]
      @state_turns[state_id] = param
      @result.added_states.push(state_id).uniq!
    end
  end
end

You can copy & paste this into a blank script space under Materials.

It is basically a rework of the add_state function. Instead of calling reset_state_counts(state_id) (that puts the new added state at the maximum turn duration), it takes the state_id and sets its turn equal to param.

Usage: add_state_param(state_id, turns).

For example, let's assume you have a Haste state with ID 110 that is set to have 10 turns duration in the database. If you use a.add_state(110) as a formula on a skill it will put Haste to the skill's users with its full turn duration. Instead, if you use a.add_state_param(110, 2) it will put Haste on the skill's user with 2 turns remaining.

Assuming the scripts works without problems (I repeat, our testing was really brief, I posted it here so maybe we can get some feebacks and bugs reports), you can use it to modulate statuses' turns as you like without creating multiple statuses with different turns in the database. You can have one state that last X turns but make a skill that applies that state with reduced turns.

Note: adding the same state via add_state(state_id) makes the game follow the standard rules for reapplying statuses (by default: the state is refreshed to its full turn duration). add_state_param(state_id, turns) sets the state's turns remaining equal to "turns" regardless instead.

Clarification: if you have a state ID 90 that last for 10 turns and apply this state with a skill to an enemy using b.add_state(90) (default function, the same called when defining effects for skills), the enemy will have the state 90 inflicted with 10 turns remaining on it. If you then apply the same state on the same target but with b.add_state_param(90, 4), the result will be that the target will be afflicted with state 90 but with only 3 turns remaining.

For my project this doesn't bother me since I either use statuses with either full duration or 1-turn only duration and I just need a simple check to avoid applying a "nerfed" state over a "good" one (i.e. a.add_state_param(10, 2) if !a.state?(10), "afflict state 10 to the skill's user if the user is not afflicted by state 10"). But it would be easy to just add an if-then-else check to further improve this script. I'll will look at it tomorrow.

Original thread: https://forums.rpgmakerweb.com/threads/applying-a-state-with-reduced-duration.75785/