YesNoOk
avatar

Control P2 Throughout your Character's Win Pose (Read 1990 times)

Started by altoiddealer, July 03, 2014, 10:18:41 pm
Share this topic:
Control P2 Throughout your Character's Win Pose
#1  July 03, 2014, 10:18:41 pm
  • **
    • USA
    • altoiddealer@gmail.com
This tutorial will instruct you how to control P2 throughout a Win Pose.

EXAMPLE VIDEO

Please read this tutorial carefully, because the conditions for this to work properly are very strict.

As an example, this tutorial will assume that there are a total of 4 Win Poses: 3 "normal" ones, and this custom pose.  It is also assumed that each win pose will have a 25% chance of occurring

Overview / Checklist:
  • Add a variable in STATE -2 to determine whether the custom win pose will be executed. THIS MUST BE DETERMINED BEFORE THE ROUND ENDS
  • Adjust the triggers in your Win Pose selection (the VarRandom controller located in State 180)
  • Create a blank Animation that will put P2 into the "custom death state"
  • Create a helper that will appear when P2 is going to die, which will send P2 into a custom death state
  • Create a custom death state, which will be Statedef 5150
  • Create another custom state, which will contain all the fun stuff you want P2 to do.
  • Adjust ALL your HitDefs (Explained in Step 7)


Step 1: Code for State -2

Whether this win pose will be executed or not MUST be determined BEFORE the round ends, unlike an ordinary Win Pose.

Therefore, add the following code into State -2:

Code:
[State -2, Determine Win Pose] 
type = VarRandom
trigger1 = RoundState = 0 ;If this Win Pose will occur or not is determined at the beginning of each round
v = 2 ;Choose an unused variable. In this example, 2
range = 1,4 ;The range. I recommend using 1, followed by the total number of win poses you have

[State -2, Stun P2 for Win Pose]
type = Helper
trigger1 = var(2) = 1 ;In this example, there is a 25% chance that the win pose will be chosen (compare with range set above).
trigger1 = P2Life <= 1 ;And if P2 is going to die
trigger1 = p2stateno != [5150,5151] ;And if P2 is not in either of the custom states
name = "P2 Stunner" ;Name of the helper. Optional - you might need an ID but I did not.
postype = back ;Don't change
stateno = 7101 ;State # of your helper
ignorehitpause = 1 ;Don't change


Step 2: Adjustments to State 180

State 180 must be adjusted to take the new variable into account.  Please review the following code to see what must be done.

Code:
[State 180, 1] ;Determine Win Pose
type = VarRandom
trigger1 = Time = 0
v = 1
range = 1,3 ;The range. I recommend using 1, followed by the total number of NORMAL win poses you have

[State 180, 2] ;Win Pose 1 ("Normal" Win Pose)
type = ChangeState
trigger1 = Var(1) = 1
trigger1 = var(2) != 1 ;Prevents Win 1 from triggering if Var(2) is triggering the custom win pose.
value = 181

[State 180, 3] ;Win Pose 2 (CUSTOM WIN POSE)
type = ChangeState
trigger1 = var(2) = 1 ;IF Var(2) TRIGGERS THE CUSTOM WIN POSE, THE CORRECT WIN POSE WILL EXECUTE
value = 182

[State 180, 4] ;Win Pose 3 ("Normal" Win Pose)
type = ChangeState
trigger1 = Var(1) = 2
trigger1 = var(2) != 1 ;Prevents Win 3 from triggering if Var(2) is triggering the custom win pose.
value = 183

[State 180, 5] ;Win Pose 4 ("Normal" Win Pose)
type = ChangeState
trigger1 = Var(1) = 3
trigger1 = var(2) != 1 ;Prevents Win 4 from triggering if Var(2) is triggering the custom win pose.
value = 184


Step 3: Create a blank Animation that will put P2 into the Custom Death State

Create a new Animation with the following properties. Use any anim # you want, but you will need it in Step 4:

Code:
[Begin Action 9998] ;P2, You Have Nowhere to Hide
Clsn1: 1
  Clsn1[0] = 0, -480, 640, 480
-1,0, 0,0, -1


Step 4: Create the Helper that will put P2 into the Custom Death State

Create this StateDef.  The State # must match the one found in Step 1. The anim # must match the one in Step 3.

Code:
[StateDef 7101] ;P2 Stunner
type = S
movetype = A
physics = S
anim = 9998 ;The blank anim with giant Clsn1 box
velset = 0,0
ctrl = 1

[State 7101, 1] ;Full-screen hit
type = HitDef
trigger1 = Time = 0
attr = S, SA
damage = 0,0
animtype = Heavy
hitflag = MF
guardflag = A
priority = 7
pausetime = 0,3
sparkxy = 0,0
sparkno = -1
guard.sparkno = -1
hitsound = -1
guardsound = -1
ground.type = High
ground.slidetime = 0
ground.hittime = 0
ground.velocity = 0
air.velocity = 0,0
air.fall = 1
fall = 0
numhits = 0
p2stateno = 5150 ;*****MUST BE STATE 5150******

[State 7101, 2] ;DestroySelf
type = DestroySelf
trigger1 = P2StateNo = !5150 ;In combination with the code in Step 1, the helper will appear as much as necessary to succeed in putting P2 into the custom state


Step 5: Create the Custom Death State

THIS CUSTOM STATE MUST BE 5150, OTHERWISE THE ROUND WILL NEVER END.

With that in mind, go ahead and create this StateDef.  When P2 is dead, this will send him to another State containing all the fun stuff you want to do with P2:

Code:
[Statedef 5150] ;Custom P2 KO
type    = L
physics = U
sprpriority = -3
ctrl = 0

[State 5150, 1] ;This will kill P2
type = LifeSet
trigger1 = name != "Jailbot" ;YOUR CHARACTER's NAME GOES HERE
value = 0
ignorehitpause = 1

[State 5150, 2] ;Normal anim
type = ChangeAnim
triggerall = Time = 0
triggerall = SelfAnimExist(5140)
trigger1 = (anim != [5111,5119]) && (anim != [5171,5179])
trigger2 = !SelfAnimExist(5140 + (anim % 10))
value = 5140

[State 5150, 3] ;Hit up type anim
type = ChangeAnim
trigger1 = Time = 0
trigger1 = (anim = [5111,5119]) || (anim = [5171,5179])
trigger1 = SelfAnimExist(5140 + (anim % 10))
value = 5140 + (anim % 10)

[State 5150, 4] ;Match over anim
type = ChangeAnim
persistent = 0
;trigger1 = Time = 0
trigger1 = MatchOver = 1
trigger1 = Anim = [5140,5149]
trigger1 = SelfAnimExist(anim+10)
value = anim+10

[State 5150, 5] ;Switch to 5110 if liedead anim does not exist
type = ChangeAnim
trigger1 = Time = 0
trigger1 = Anim != [5140,5159]
trigger1 = Anim != [5110,5119]
value = 5110

[State 5150, 6] ;Friction
type = VelMul
trigger1 = 1
x = 0.85

[State 5150, 7] ;Friction
type = VelSet
trigger1 = abs(Vel x) < Const(movement.down.friction.threshold)
persistent = 0
x = 0

[State 5150, 8] ;Normal NotHitBy
type = NotHitBy
trigger1 = name = "Jailbot" ;YOUR CHARACTER's NAME GOES HERE
value = SCA
time = 1
ignorehitpause = 1

[State 5150, 9] ;Custom NotHitBy
type = NotHitBy
trigger1 = name != "Jailbot" ;YOUR CHARACTER's NAME GOES HERE
value = SCA
time = 1
ignorehitpause = 1

[State 5150, 10] ;More Custom
type = NotHitBy
trigger1 = name != "Jailbot" ;YOUR CHARACTER's NAME GOES HERE
value = , NA, SA, AP
time = 100
ignorehitpause = 1

[State 5150, 11] ;P2 IS NOW YOUR PUPPET
type = ChangeState
trigger1 = Roundstate = 4 ;DONT CHANGE THIS TRIGGER
trigger1 = name != "Jailbot" ;YOUR CHARACTER's NAME GOES HERE
value = 5151 ;I Recommend you use State 5151


Step 6: Create State(s) containing all the things you want P2 to do in your Win Pose(s)

You can now have P2 do whatever it is you want him or her to do during your character's Win Pose.  In this example, you would put the State Controllers in StateDef 5151.

If you were able to understand everything above, you can also probably figure out how to control P2 for multiple Win Poses at this point, if you so desire.  It would involve creating yet another custom state for P2 to go into from State 5150 (such as State 5152, 5153, etc), and then basically adjusting all the values and triggers from the previous steps accordingly.


Step 7: Adjust ALL Your Character's HitDefs

Don't skip this Step, because this is the most important one :)

Add the following line to ALL of your character's HitDefs:

This will ensure that P2's health will become 1 instead of 0 from a death-blow, allowing the helper to hit P2 and finish the job.

Code:
kill = var(2) != 2


GOOD LUCK,HAVE FUN!
Last Edit: July 04, 2014, 03:59:25 pm by altoiddealer
Re: Control P2 Throughout your Character's Win Pose
#2  July 08, 2014, 12:03:56 am
  • ****
  • Hey.
    • Ukraine
    • mugencoder.com

  • Online
Nice tutorial, though my only comments are that you should force people to use their custom death state as the same 5150. That's just known as overriding. Instead, you should have a separate custom death state that puts the character into state 5150, because as you know the round won't end if the dead player isn't in state 5150. The difference here is that you leave the original untouched and can do whatever you want to the custom one without have to worry about messing things up for the character's normal deaths.

     Posted: July 08, 2014, 12:06:04 am
It will also avoid much (not all) of the String comparison triggers, which by nature are slower than integer computations.

-[Все слова это только слова.]-
Re: Control P2 Throughout your Character's Win Pose
#3  July 08, 2014, 07:01:18 am
  • **
    • USA
    • altoiddealer@gmail.com
Nice tutorial, though my only comments are that you should force people to use their custom death state as the same 5150. That's just known as overriding. Instead, you should have a separate custom death state that puts the character into state 5150, because as you know the round won't end if the dead player isn't in state 5150. The difference here is that you leave the original untouched and can do whatever you want to the custom one without have to worry about messing things up for the character's normal deaths.

Thanks for the comments!  I appreciate any suggestions to help improve this code.

I think I know what you are saying... but I'm really not sure how to go about that, aside from how I handled it above,  ...Or can you have 2 custom states using the same number?  I really don't know how else you could segregate P1's and P2's State 5150 to achieve the desired result.

I'm not prepared to test right now, but if you use a custom common1.cns, could adding a "SelfState" controller send P1 from this custom State 5150 to the one in common1?  I don't know all the ins and outs yet but I wouldn't be too surprised if it worked this way.

It will also avoid much (not all) of the String comparison triggers, which by nature are slower than integer computations.

I'll keep that in mind, thanks for the tip!
Re: Control P2 Throughout your Character's Win Pose
#4  July 08, 2014, 03:35:55 pm
  • ****
  • Hey.
    • Ukraine
    • mugencoder.com

  • Online
No problem! What I meant was that you make a custom state with any number other than 5150 so you can leave it untouched. At the end of your custom state, that player 2 lands into, you would SelfState P2 into 5150. Honestly, it depends what you're doing with P2. For example, if you want P2 to blow up, obviously you want them off  screen then. In that case, you move player 2 off screen in their custom state before SelfStating to 5150.

See if you have a state with the same number as one in the common1.cns, in your local .cns files, you are effectively overriding that state entirely. Your local state is the new 5150 for that character. This maybe okay, but if you want it to behave like the normal 5150, but need to make extra changes to it, I think it's more work that way than just separating the two and passing your character to the global 5150 afterwards. There's no way to pass from the local to the global version of an overridden state. You're redefining the state.

The same goes for you using a custom common1.cns. You will be overriding the global states with the local ones, even if they're the same, lol.

-[Все слова это только слова.]-
Re: Control P2 Throughout your Character's Win Pose
#5  July 08, 2014, 04:38:33 pm
  • **
    • USA
    • altoiddealer@gmail.com
No problem! What I meant was that you make a custom state with any number other than 5150 so you can leave it untouched. At the end of your custom state, that player 2 lands into, you would SelfState P2 into 5150. Honestly, it depends what you're doing with P2. For example, if you want P2 to blow up, obviously you want them off  screen then. In that case, you move player 2 off screen in their custom state before SelfStating to 5150.

See if you have a state with the same number as one in the common1.cns, in your local .cns files, you are effectively overriding that state entirely. Your local state is the new 5150 for that character. This maybe okay, but if you want it to behave like the normal 5150, but need to make extra changes to it, I think it's more work that way than just separating the two and passing your character to the global 5150 afterwards. There's no way to pass from the local to the global version of an overridden state. You're redefining the state.

The same goes for you using a custom common1.cns. You will be overriding the global states with the local ones, even if they're the same, lol.

Thanks again for the comments.  Well that would certainly be the more practical option for the scenario you proposed.  :yes:

However, if you really want full control of P2 like I did for my character's win pose, I don't think there's any other option than to send P2 into a custom State 5150, and then just deal with it.  I think I have it set up just about as un-intrusive as possible to achieve this... P1 should die normally every time, and P2 will only go into the Custom State if the associated Win Pose is set to occur.

I think it's failproof right now in sending P2 to the custom StateBut maybe a few things could be adjusted to eliminate the "all-in" commitment... and allow it to fail under certain circumstances where P2's death physics might be altered to a degree, and to let another Win Pose play instead.  For now, though, I'm not 100% sure IF or how much this alters P2's normal death.
Re: Control P2 Throughout your Character's Win Pose
#6  July 08, 2014, 05:51:45 pm
  • ****
  • Hey.
    • Ukraine
    • mugencoder.com

  • Online
I mean it terms of the general populous, more than you per se. I'm sure you know what you're doing here, since you wrote the tutorial. XD But, it might get hairy for someone who's following it to learn. I'm just saying the easier way, from a learning perspective possible, is CUSTOM_STATE_NUM -> 5150 (at the end of the custom state). What you have here will work without a doubt, I'm only offering an alternative. :)

I like to help where I can. Most of the time, in the graphics department, I'm useless, but I know a thing or two about coding. :)

-[Все слова это только слова.]-