Conditional States

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English



This script allows you to create "conditional states". A conditional state is simply a placeholder for other states, depending on the conditions at the time the state is applied.


For example, suppose you have a skill that adds a Weak Poison state to a target if it is not already poisoned, and adds a Strong Poison state if it has Weak Poison inflicted. You can use a formula to determine whether the weak poisonhas been added or not to determine which state should be added.


Get it at Hime Works!
 
Last edited by a moderator:
Joined
Nov 17, 2012
Messages
19
Reaction score
5
Primarily Uses
Thank you for a great script! I appreciate your work! I admire that you are working on many specific scripts for specific needs, Tsukihime. Utility scripts are the most under-appreciated things, honestly.

General question: May I kindly ask you to provide more examples for how to use your formula variables? How can I make a conditional state that checks to only apply a state to members of my party (not a specific member, but the whole hero party)? How can I make a conditional state that only applies to the enemy? How can I make a conditional state which only works if switch 001 is on? I'm trying to figure out the code, but, the conditional logic is confusing. Any help would be much appreciated.

Specific question: I'm trying to use a conditional state to determine if the battler that the state will be added to is a party member, and if so, apply x, if not, apply the else y. Your script seems like it will be tremendously powerful and useful for making this happen!

Here is my conditional formula:
 

   <conditional state>     if a = p       6     else       30     end   </conditional state>Can you spot anything with your experienced eyes that is wrong? In this condition, when I use Sleep with the proper placeholder state in its Effects, against my party or my enemy, state 6 (Sleep) is always determined to be applied, even on enemies. State 30 (enemy-customized version of Sleep state) is never used.

It's my understanding that your Conditional State's formula variable p is equivalent to $game_party. I figure that I am making a mistake here and there is a difference between a global variable and its contents, I am guessing. However, I don't understand how to make conditional checks or what place I should check. If I introduce a p.battle_members?, I still need something to check, right? Even if I try to make more conditional methods for each member of my party, using awkwardly, clumsily and repeatedly "if a = p.battle_members.include?($game_actors[id])", the conditional is ignored and the "if" state (state 6) is always applied. I would prefer something more direct and smoother to use. I've read through resources here on formulae, but I've came up unsuccessfully short, so far.  I tried the same formula in a blank project, as well, so I doubt it's a compatibility issue.

What do you think, Tsukihime?
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Checking equality is ==, not =. You will run into problems when you use = in your conditions improperly. That's probably the issue you're having with your other attempts.

If you mean you're not actually sure how to write the condition for a particular switch, that is just

// checking switch 1if s[1] # do somethingelse # something elseendDo not have leading zeroes in your numbers.
How can I make a conditional state that only applies to the enemy?
My script only supports checking the subject (as opposed to user/target kind of relationship,), so you'd want to know whether the subject is an actor or an enemy

Code:
if a.enemy?  # somethingelse  # something elseend
The reason why it does not support user/target is because this is for generic state application, not specifically when a user adds a state to a target.
 
Last edited by a moderator:

DrGurk

Warper
Member
Joined
Jan 30, 2014
Messages
1
Reaction score
0
First Language
German
Primarily Uses
I don't have that much experience with ruby yet, but if programing in C has taught me anything, it was that a=p is a command, not a check
Try this


Code:
   <conditional state>     if a == p       6     else       30     end   </conditional state>
Anyway, great script, no more common events for multiple iterations of states :)
 

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Why not another version that allows caster conditions? :)
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
I mean use the battler that caused the state as part of the conditions... I saw your answer above telling that you didn't add that since this was supposed to be a general purpose script that will work for any state addition... so I was thinking, why not just add another version that supports that?


though of course that is quite a bit harder to do than this if I remember correctly... I was simply curious... :)
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I'd say it's just more restrictive. This script was intended to allow you to create placeholder states for any sort of state adding purposes.


You would just overwrite the "Add state" effects if you want to include the user.


That would be a completely different script in my view, just because it's more restrictive.


EDIT: well, maybe not overwrite. It would just do a check to see whether the condition is met or not before even adding it.
 
Last edited by a moderator:

omen613

Veteran
Veteran
Joined
May 22, 2012
Messages
309
Reaction score
109
First Language
English
Primarily Uses
Hi Hime!

Trying to make a TP like resource using states with this script. I'm trying to have skills add state 67

and if they already have 67 it removes 67 and adds 68

if they already have 68 it removes 68 and adds 69

i can get it to add 68 just fine...its just adding 69 it messes up and adds 67 and 68 instead

here is what i got setup on state 67 and I hope a Wiz like you can see what i messed up

<conditional state>

if a.state?(68) & !a.state?(67)

a.remove_state(68)

69

if a.state?(67) & !a.state?(68)

a.remove_state(67)

68

else

67

end

else

67

end

</conditional state>
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
There is a similar question asked on the blog post.

Due to the increasing nature of your states, you can check them in reverse:

If 68 exists, add 69,

Else if 67 exists, add 68

else, add 67

Code:
if a.state?(68)  a.remove_state(68)  69elsif a.state?(67)  a.remove_state(67)  68else  67end
 

omen613

Veteran
Veteran
Joined
May 22, 2012
Messages
309
Reaction score
109
First Language
English
Primarily Uses
There is a similar question asked on the blog post.

Due to the increasing nature of your states, you can check them in reverse:

If 68 exists, add 69,

Else if 67 exists, add 68

else, add 67

if a.state?(68) a.remove_state(68) 69elsif a.state?(67) a.remove_state(67) 68else 67end
Thanks a bunch! 

that worked perfectly! Spent days trying to make this system work....so relieving to find your script made it happen.
 

deadly7h

Warper
Member
Joined
Feb 17, 2015
Messages
3
Reaction score
0
Primarily Uses
can someone tell me if this is alright?

<conditional state>

 if a.mhp? =< 30%

  a.state (37)

else

</conditional state>

 

this is supposed to be like a passive skill so whenever actor's hp is less or equal to 30% it will activate state 37 (which is regen) and regen is supposed to cancel state 36 (the state above mentioned), im using NB passive skill's script so (36) will trigger everytime a battle starts
 

AzraeLXIX

Villager
Member
Joined
Jun 18, 2015
Messages
9
Reaction score
1
Primarily Uses
I'm attempting to do something like deadly7h in that I wish to not only use the user's current hp (in the sense that upon taking damage something happens) but also if the enemy takes damage (also in the sense of upon any troop taking damage from the user then something happens)

 my current (and incorrect) script is

The number 28 in the scripts is the control state, so long as that state is active ebb and flow can continue to switch as many times as needed.

For "Ebb" (ebb is the state induced when the user deals damage and is represented in the script by the number 27)

<conditional state>
     if a.state?(28)
      if a.((mhp? > 0) && ( mhp? <= 100))
        29
        a.remove_state(27)
      else
        27
      end
     else
       a.remove_state(27)
       a.remove_state(29)
     end
   </conditional state>

For "Flow" (flow is the state that is induced and receiving damage and is referred to as 29. Uses Hamedo's improved counter script to induce the true counter attack state, not sure exactly how to tie that in but the state number for the true counter attack is 33)

<conditional state>
     if a.state?(28)
      if t.((mhp? > 0) && ( mhp? <= 100))
        27
        a.remove_state(29)
      else
        29
      end
     else
       a.remove_state(29)
       a.remove_state(27)
     end
   </conditional state>

Both Ebb and Flow are active until the condition given to cause a switch to the opposite and allow each states effect to take hold until the switch condition is met. Some help would be VASTLY appreciated. Thanks!
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
The return value of the formula is the ID that will be used.

It would be better to explicitly write out "return" so that it is clear what your logic is.

<conditional state> if a.state?(28) if a.((mhp? > 0) && ( mhp? <= 100)) a.remove_state(27) return 29 else return 27 end else a.remove_state(27) a.remove_state(29) return 0 # to be specific: no state will be added end </conditional state>However, it looks like you are using other scripts in order to apply these states.Depending on how those scripts are written, they might not even call the conditional state logic.
 

AzraeLXIX

Villager
Member
Joined
Jun 18, 2015
Messages
9
Reaction score
1
Primarily Uses
Thanks for the quick reply. I attempted to use the script given. I got an error saying unidentified method 'mhp?' for RPG::state:0x703cc9c

Also, the script Hamedo is just a state that would also be proc'd into from the conditional branch.
 
Last edited by a moderator:

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I just copied whatever you wrote and clarified that the formula must return a number.

You need to do

Code:
if a.mhp? > 0 && a.mhp? <= 100
Since the context of the formula is not evaluated inside the battler object.
 

Aoi Ninami

Veteran
Veteran
Joined
Sep 22, 2015
Messages
413
Reaction score
513
First Language
English
Primarily Uses
RMVXA
Just popping in to say huge thanks for this! :)
 

piksalh

Veteran
Veteran
Joined
Jun 14, 2014
Messages
106
Reaction score
9
First Language
Lithuanian
Primarily Uses
RMMV
Hello, the script is awesome! I figured out how to add up to 10 states. In my game there is a shield system. If enemy casts shield on all allies, it gives them state Shield lvl+1 from 1 to 10. But i cant find a working formula to configure a conditional state that removes states one by one. Maybe someone has an idea how to do it?

When player casts skill, I get an error: 

Script 'Game_Battler' line 92: TypeError occured.

no implicit conversion from nil to integer.

My not working formula for conditional state looks like that:

(state 100 = Shield level 1; state 109 = Shield level 10)

<conditional state>

if a.state?(109);

a.remove_state(109)

elsif a.state?(108);

a.remove_state(108)

elsif a.state?(107);

a.remove_state(107)

elsif a.state?(106);

a.remove_state(106)

elsif a.state?(105);

a.remove_state(105)

elsif a.state?(104);

a.remove_state(104)

elsif a.state?(103);

a.remove_state(103)

elsif a.state?(102);

a.remove_state(102)

elsif a.state?(101);

a.remove_state(101)

else

a.remove_state(100)

end

</conditional state>
 
Last edited by a moderator:

piksalh

Veteran
Veteran
Joined
Jun 14, 2014
Messages
106
Reaction score
9
First Language
Lithuanian
Primarily Uses
RMMV
Hello again. I dont know why, but it works and I'm not getting any error when I accidentally added 99 (it's empty state) below end. Now the skill removes shield by one level as it should. It looks like that:

if a.state?(109);

a.remove_state(109)

...

end

99

</conditional state>

 

Strange but it works :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top