YesNoOk
avatar

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

Started by altoiddealer, July 03, 2014, 10:18:41 pm
Share this topic:
Control P2 Throughout your Character's Win Pose
New #1  July 03, 2014, 10:18:41 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
UPDATED 2/16/2017

This tutorial will instruct you how to control the defeated opponent throughout one or multiple Win Poses.

EXAMPLE VIDEO

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

Required Steps: (ALL STEPS ARE EXPLAINED IN DETAIL BELOW)
  • Add a variable in STATE -2 (OR State 5900 - round initialization) to determine whether the custom win pose will be executed.
  • Adjust the triggers in State 180 (Where Win Poses are initiated from)
  • Create a custom KO state, which must be Statedef 5150
  • Create another custom state (or states), which will contain all the fun stuff you want the defeated opponent to do.
  • Adjust ALL of your character's HitDefs

===========================================================
COMMENTS (READ THIS)

Before starting off, there are some things that you must understand.
Your character will always go into this Custom State 5150 when defeated!!!
Your character will NOT be affected by any of the custom code, as long as you follow the instructions carefully.
The custom code will only affect the defeated opponent.

Also, as will be explained in the very last step... you must include a few often completely unused parameters (which do not affect gameplay) in ALL of your character's HitDefs
Code:
fall.envshake.freq = TeamSide ;Optional... but recommended as another failproof
fall.envshake.ampl = ID ;REQUIRED
fall.envshake.phase = var(59) ;A VAR IS REQUIRED
By doing this, you can actually access this information from the Custom State that you send your opponent into, by using the "GetHitVar" trigger.

Here is an example from one of the controllers found in this tutorial:
Code:
[State 5150, CUSTOM] ;SEND OPPONENT TO CUSTOM WIN POSE
type = ChangeState
trigger1 = Roundstate = 4
trigger1 = gethitvar(fall.envshake.freq) != Teamside
trigger1 = gethitvar(fall.envshake.phase) = 1 ;value of var(59)
value = 5151 ;The state you want to send the opponent into

trigger1 = gethitvar(fall.envshake.freq) != Teamside
This will prevent the code from being triggered by your own character.

trigger1 = gethitvar(fall.envshake.phase) = 1
As mentioned above, "fall.envshake.phase" actually represents the value of your var(59), or whatever var you are going to use to select the Win Pose.

If you use the parameter "fall.envshake.ampl = ID" as mentioned above, you can then redirect trigger to your character from the opponent's custom state by using for example "PlayerID(gethitvar(fall.envshake.ampl)),Pos X"   If your character has Player ID 57, then this would essentially translate to "PlayerID(57),Pos X"

If you don't understand, then just copy and paste all the code and it will work. K?
===========================================================


Step 1: Code for State -2 (or State 5900)

Whether this win pose will be executed or not MUST be determined BEFORE the round ends, unlike an ordinary Win Pose.  In this tutorial, I am using var(59) to store the Win Pose selection.

Also required in State -2 is a TargetState controller that will send the opponent into the custom state when he is being KO'd

Therefore, add the following code into State -2 (or State 5900):
Code:
[State -2, Randomly Select Win Pose at Beginning of Each Round] 
type = VarRandom
trigger1 = RoundState = 0 ;Win Pose is selected at the beginning of each round
v = 59 ;Dedicate a variable to assign the win pose selection to.  In this example, I am using var(59)
range = 1,4 ;The range. Start with 1, followed by the total number of win poses you have.  In this example there are a total of 4 win poses.

Add the following code into State -2:
Code:
[State -2, Send Dying Target to Custom State 5150 for Custom Win pose]
type = TargetState
triggerall = numtarget = 1 ;if you have ONE target (use custom winpose for simul mode at your own peril)
triggerall = target,life <= 0 ;if P2 is ready to die
triggerall = var(59) = 1 ;SPECIFY THE CUSTOM WIN POSE, OR MULTIPLE WIN POSES.  In this example, the FIRST win pose will control the opponent.  SO this will not trigger when var(59) = 2 or 3 or 4.
triggerall = TeamMode != Simul ;Not for TeamMode (use custom winpose for simul mode at your own peril)
trigger1 = target,StateNo = 5110 ;enemy is lying on ground, defeated
value = 5150
ignorehitpause = 1


Step 2: Adjustments to State 180

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

Code:
[Statedef 180] ;Win Pose is predetermined at round start.
type = S

[State 180, CUSTOM WIN POSE]
type = ChangeState
trigger1 = var(59) = 1 ;THE CUSTOM WIN POSE
value = 181

[State 180, NORMAL WIN POSE]
type = ChangeState
trigger1 = var(59) = 2 ;NORMAL WIN POSE
value = 182

[State 180, 3] ;Win Pose 3 ("Normal" Win Pose)
type = ChangeState
trigger1 = Var(59) = 3 ;NORMAL WIN POSE
value = 183

[State 180, 4] ;Win Pose 4 ("Normal" Win Pose)
type = ChangeState
trigger1 = Var(59) = 4 ;NORMAL WIN POSE
value = 184


Step 3: Create the Custom KO State 5150

The conditions for any round to end are:
1. The winning character must be in State 0.
2. The defeated opponent must be in State 5150.

THEREFORE, THE CUSTOM STATE MUST BE 5150, OTHERWISE THE ROUND WILL NEVER END!

With that in mind, go ahead and create this StateDef.  It uses all of the default controllers found in common1.cns, but with a few custom controllers and modifications.
As with any State, this will override the State 5150 found in common1.cns.

Code:
;CUSTOM KO
[Statedef 5150]
type = L
movetype = H
physics = U
sprpriority = -3
ctrl = 0

[State 5150, DEFAULT] ;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, DEFAULT] ;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, DEFAULT] ;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, DEFAULT] ;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, DEFAULT] ;Friction
type = VelMul
trigger1 = 1
x = 0.85

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

[State 5150, DEFAULT]
type = NotHitBy
trigger1 = 1
value = SCA
time = 1

[State 5150, CUSTOM] ;SEND OPPONENT TO CUSTOM WIN POSE
type = ChangeState
triggerall = Roundstate = 4
trigger1 = PlayerIDExist(gethitvar(fall.envshake.ampl)) ;Triggers only if your character delivered the finishing blow
trigger1 = gethitvar(fall.envshake.freq) != Teamside ;Double-checks that this is not your own character!
trigger1 = gethitvar(fall.envshake.phase) = 1 ;This means var(59) = 1 (custom win pose was selected)
value = 5151 ;The state you want to send the opponent into

If you want to control the opponent for multiple Win Poses, just add another controller at the end, specifying another variable.

Code:
[State 5150, CUSTOM] ;SEND OPPONENT TO A DIFFERENT CUSTOM WIN POSE
type = ChangeState
triggerall = Roundstate = 4
trigger1 = PlayerIDExist(gethitvar(fall.envshake.ampl)) ;Triggers only if your character delivered the finishing blow
trigger1 = gethitvar(fall.envshake.freq) != Teamside ;Double-checks that this is not your own character!
trigger1 = gethitvar(fall.envshake.phase) = 2 ;This means var(59) = 2 (custom win pose #2 was selected)
value = 5152 ;The state you want to send the opponent into


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

You can now have the defeated opponent do whatever it is you want him or her to do during your character's Win Pose.


Step 5: Adjust ALL Your Character's HitDefs

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

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

Code:
fall.envshake.freq = TeamSide ;Provide your character's current Teamside.
fall.envshake.ampl = ID ;Provide your character's PlayerID.  Useful for redirecting triggers to your character, from the opponent's custom state!
fall.envshake.phase = var(59) ;Provides your characters pre-determined win pose.  This parameter is required if you have multiple custom win poses.

ENJOY! HAVE FUN!

Last Edit: February 16, 2017, 10:55:44 pm by altoiddealer
Re: Control P2 Throughout your Character's Win Pose
#2  July 08, 2014, 12:03:56 am
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.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.

     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
  • ****
  • Robotics Engineer
    • 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
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.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.

-[Все слова это только слова.]-
Re: Control P2 Throughout your Character's Win Pose
#5  July 08, 2014, 04:38:33 pm
  • ****
  • Robotics Engineer
    • 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
  • ****
  • Target Acquired.
    • Ukraine
    • mugencoder.com
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. :)

-[Все слова это только слова.]-
Re: Control P2 Throughout your Character's Win Pose
#7  July 29, 2015, 02:24:41 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
FIRST POST UPDATED.

If anyone has any questions, just ask!!!!!!

This should be the FINAL version of this technique which I have spent a lot of time perfecting and bugfixing.

Re: Control P2 Throughout your Character's Win Pose
#8  August 16, 2015, 09:11:26 pm
  • avatar
  • ***
  • Go and download my improved creations!
  • NOW IT'S MY TURN!
    • UK
    • https://sites.google.com/site/wlanmanslab/home
That's a very great code you put, I must add this code for my characters!
Re: Control P2 Throughout your Character's Win Pose
#9  August 17, 2015, 06:00:11 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
That's a very great code you put, I must add this code for my characters!
Good luck!  Feel free to ask any questions.

I have yet to see anyone else trying out this code with their characters

Re: Control P2 Throughout your Character's Win Pose
#10  August 19, 2015, 11:58:29 am
  • ******
  • Limited time to use Infinite power !
    • France
    • network.mugenguild.com/cybaster/
Well, several characters use this kind of code to trigger some basic interaction during the winpose (Majin Vegeta Z2 with a little Bakuhatsuha, Splode's Juggernaut stomping P2, etc.), but I guess nothing as advanced in terms of visuals.
Re: Control P2 Throughout your Character's Win Pose
#11  August 19, 2015, 04:03:51 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Well, several characters use this kind of code to trigger some basic interaction during the winpose (Majin Vegeta Z2 with a little Bakuhatsuha, Splode's Juggernaut stomping P2, etc.), but I guess nothing as advanced in terms of visuals.

And they control the defeated opponent through a custom state?

Re: Control P2 Throughout your Character's Win Pose
#12  October 23, 2016, 01:26:37 am
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Sort of a pointless necro (at the moment).

I'm just excited that finally, after all this time, and all the countless amounts of guessing and checking... I finally found the cleanest way of doing this.

No need to attempt simulating hit velocity.  No need to force P2 immediately into State 5150, and kill them with a LifeSet controller.  No need for "kill" parameters on all the HitDefs.

I'll be updating this guide very shortly.  But it's basically self-explanatory after seeing this code:
Spoiler, click to toggle visibilty

Yes, apparently you can simply targetstate the enemy after the entire hit sequence is over, when lying on the ground... immediately before they would naturally go into the common state 5150.

The added hitdef attributes are still essential, though, to detect that it is actually the enemy in this state and not yourself.  And surprisingly they carry over throughout the enemy's entire death fall sequence.

Last Edit: October 23, 2016, 01:29:56 am by altoiddealer

2OS

Re: Control P2 Throughout your Character's Win Pose
#13  October 29, 2016, 02:59:57 pm
  • ****
  • 608 Wannabe
  • Ich schicke dich zur HOELLE!! STIRB DU FEIGLING!!
    • Egypt
    • deuceovspadez.webs.com/
^ that won't work on anything that has either a custom 5110 that uses selfstate instead of changestate or anything that overrides 5110 entirely ( 5110 has a weird hardcoded behavior that ignores liedown.time after being juggled a lot. my own common1 file overrides this state partially due to this ).


the absolute surefire simplest way of doing this unfortunately involves a bug; reversaldef stops accorded targetdropping even with hitdef. it simply needs to exist.

you won't have to modify hitdefs or anything this way.

Code:
[Statedef -2]

[State ]
type=reversaldef
trigger1=roundstate>2
reversal.attr=acs,aa,ap,at

[State ]
type=targetstate
trigger1=numtarget
trigger1=target,stateno=5150
trigger1=!target,alive
value=5150

Spoiler: this is what's used here (click to see content)
Re: Control P2 Throughout your Character's Win Pose
#14  October 29, 2016, 03:26:27 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
^^^ Nice info, and that's a great win pose.  I see you're on a roll sprinkling some gems around the board!

I will include this in the OP when I decide to re-write it (soon).


Personally, I'm going to stick with what I have because I've tested it a million times and I'm releasing my character tonight :)

For rare instances like that, and other anomalies that may occur, I made it so it will fall back on a normal win pose.

trigger3 = !(PlayerIDExist(var(58)) && PlayerID(var(58)),StateNo = 5151) ;If ice cream pose unexpectedly fails
value = 181

and the custom one

trigger1 = PlayerIDExist(var(58)) && PlayerID(var(58)),StateNo = 5151 ;Enemy is ready for ice cream
value = 182

Re: Control P2 Throughout your Character's Win Pose
#15  February 16, 2017, 10:50:45 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Finally got around to updating this guide with the much cleaner activation that made it into the public release of my Jailbot character