The Mugen Fighters Guild

Help => M.U.G.E.N Development Help => Topic started by: MarioManX1983 on December 31, 2018, 01:42:46 am

Title: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on December 31, 2018, 01:42:46 am
First a bit of background information.

I've been looking through other peoples posts as well as MFG's code library, Mugen Class Forum, YouTube, and other sources and am STILL not able to do what I want.

I basically want a variable that will increment every time the opponent is hit with, and damaged by, any kind of successful attack. (Not when the opponent blocks the Attacks.) And also decreases every second the opponent is not being hit with any attack and also resets when the opponent is dizzied.

I have included the code I am currently using, along with code documentations in the hopes it might help show you exactly what I want the code to do.

Spoiler, click to toggle visibilty

The Dizzy Statedef is working fine. I can place that "p2stateno = 830" at the end of any hitdef and it will make P2 dizzy no problem.

It's the Dizzy Controller Statedef that's giving me hassle. I just don't know/can't figure out the proper triggers. Or maybe I have the whole Dizzy Controller code wrong. I just don't know. :(

Any help is greatly appreciated.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: beterhans on December 31, 2018, 02:32:32 am
So you didn't want put yourself P1 into dizzy but P2?

them plz ignore my previous post.
My Char only count stun points on them self.

Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on December 31, 2018, 10:27:52 pm
Yes. And thank you anyway. :)
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on January 04, 2019, 06:27:49 am
Time for an update!

I've FINNALY been able to (somewhat) accomplish what I am after.

I have been able to code a Float Variable to keep track of whenever the character (self) is hit by an attack, as well as automatically count down every second that the character (self) is not being attacked and if the Float Variable get to high, the character is placed into the dizzy state. The character can then ether wait it out or mash the attack buttons to escape early.

I have also made a second Float Variable useing the exact same code, only for the opponent instead of the character. It is supposed to keep track of whenever the opponent is damaged and send them into the character's custom dizzy state accordingly.

Now, the problems I am still having are;
1. The dizzy sound keeps playing after the character exits the dizzy state. (By ether mashing buttons or state time out.) But if the character is hit out of the dizzy the sound stops.
2. If the player taps any of the buttons, the Float Variable subtracts 1 immediately. (Which is not wanted.) But if the player is standing still it subtracts 1 every second. (Which IS wanted.)
3. The VarAdd for Float Variable 2 does not seem to be adding to the Float Variable when the player hits the opponent.

Here is the code I am using for your refrence. I will of course continue to try and fix this myself but any help anyone can give me will be greatly appreciated.

Code:
; Self Dizzy
; CNS difficulty: medium
; This is a custom state that, once activated, will make the character "Dizzy" or "Stunned" for a short period of
; time. The character will not be able to move and will be left completely open to all attacks, but can also
; repeatly press any attack button(s) to escape from the dizzy early.
;
; p2stateno = 5300

[Statedef 5300, Dizzy]
type = S
movetype = H ;H-Hit or Hurt.
physics = S
velset = 0, 0

[State 5300, ChangeAnim] ;Change to dizzy Animation.
type = ChangeAnim ;ChangeAnim for Self, ChangeAnim2 for Opponent.
trigger1 = time = 0
value = 5300

[State 5300, Dizzy Sound]
type = PlaySnd
trigger1 = time = 0
value = 5300, 0
loop = 1
;loop = ifelse(stateno = 5300,1,0) ;Loops the sound.
channel = 0 ; Stops the sound from playing if the character is hit out of the dizzy.

[State 5300, VarSet] ;Creates the Dizzy Escape Counter Variable (Variable Three or var(3) ).
type = VarSet
trigger1 = time = 0
var(3) = 0 ;Sets the Variable name to the number. (Ex. Variable Three or var(3)) and the starting value to 0.

[State 5300, VarAdd] ;Rapidly Press any attack button(s) to escape the dizzy.
type = VarAdd
trigger1 = command = "a" || command = "b" || command = "c"
trigger2 = command = "x" || command = "y" || command = "z"
var(3) = 2 ;Tells this VarAdd to add the value to Variable Three.
persistent = 1 ;Makes the VarAdd keep adding the value to the Variable every time a button is pressed.

[State 5300, ChangeState] ;Will place P1 back into there own CNS after they hit the button enough times.
type = ChangeState
trigger1 = var(3) >= 30 ;P1 escapes dizzy after Variable Three reaches 30.
value = 0 ;Brings P1 back to there standing state.
ctrl = 1  ;Gives control back to P1.

[State 5300, ChangeState] ;Will place P1 back into there own CNS after a certain amount of time.
type = ChangeState
trigger1 = time = 300 ;Time before P1 escapes the dizzy. (5 seconds.) (60 = 1 second.)
value = 0 ;Brings P1 back to there standing state.
ctrl = 1  ;Gives control back to P1.

[State 5300, SelfState] ;Will place P2 back into there own CNS after they hit the button enough times.
type = SelfState
trigger1 = var(3) >= 30 ;P2 escapes dizzy after Variable Three reaches 30.
value = 0 ;Brings P2 back to there standing state.
ctrl = 1  ;Gives control back to P2.

[State 5300, SelfState] ;Will place P2 back into there own CNS after a certain amount of time.
type = SelfState
trigger1 = time = 300 ;Time before P2 escapes the dizzy. (5 seconds.) (60 = 1 second.)
value = 0 ;Brings P2 back to there standing state.
ctrl = 1  ;Gives control back to P2.

And Then

Code:
; Self Dizzy Controller and Activator.

[State -2, VarSet] ;Creates the Self Dizzy Controller Variable (Float Variable One or fvar(1) ).
type = VarSet
trigger1 = time = 0
fvar(1) = fvar(1) ;Sets the Float Variable name to the number. (Ex. Float Variable One or fvar(1)) and
;          the starting value to 0.
persistent = 1

[State -2, VarAdd] ;Adds the value to fvar(1) every time the character is damaged.
type = VarAdd
trigger1 = time = 0 && gethitvar(damage) ;Activates the VarAdd whenever the character is damaged.
fvar(1) = 5 ;Tells this VarAdd to add the value to fvar(1).
persistent = 1 ;Makes the VarAdd keep adding the value to the Variable.

[State -2, VarAdd]
type = VarAdd
trigger1 = fvar(1) >= 1 && var(time%60) ;Takes 1 away from fvar(1) every second.
fvar(1) = -1 ;Tells this VarAdd to add the value to fvar(1).
persistent = 1

[State -2, VarSet] ;Resets fvar(1) to Zero after the character has been dizzed.
type = VarSet
trigger1 = stateno = 5300
fvar(1) = 0 ;Tells this VarSet to set the value to fvar(1).

[State -2, ChangeState] ;Puts the character into the dizzy state after fvar(1) reaches the value.
type = ChangeState
trigger1 = fvar(1) >= 20 ;Character enters dizzy state once fvar(1) reaches 30.
value = 5300 ;Brings Character into the dizzy state.
ctrl = 0  ;Takes control away from the character.

;-----------------------------------------------------------------------------------------------------------------
; Opponent Dizzy Controller and Activator.

[State -2, VarSet] ;Creates the Opponent Dizzy Controller Variable (Float Variable Two or fvar(2) ).
type = VarSet
trigger1 = time = 0
fvar(2) = fvar(2) ;Sets the Float Variable name to the number. (Ex. Float Variable Two or fvar(2)) and
;          the starting value to 0.
persistent = 1

[State -2, VarAdd] ;Adds the value to fvar(2) every time the opponent is damaged.
type = VarAdd
trigger1 = time = 0 && HitCount >= 1 ;Activates the VarAdd whenever the opponent is damaged.
fvar(2) = 2 ;Tells this VarAdd to add the value to fvar(2).
persistent = 1 ;Makes the VarAdd keep adding the value to the Variable.

[State -2, VarAdd]
type = VarAdd
trigger1 = fvar(2) >= 1 && var(time%60) ;Takes 1 away from fvar(2) every second.
fvar(2) = -1 ;Tells this VarAdd to add the value to fvar(2).
persistent = 1

[State -2, VarSet] ;Resets fvar(2) to Zero after the opponent has been dizzied.
type = VarSet
trigger1 = p2stateno = 5300
fvar(2) = 0 ;Tells this VarSet to set the value to fvar(2).

[State -2, TargetState]
type = TargetState ;Puts the opponent into the dizzy state after fvar(2) reaches the value.
trigger1 = fvar(2) >= 30 ;Opponent enters the dizzy state once fvar(2) reaches 30.
value = 5300 ;Brings the opponent into the dizzy state.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: ink on January 04, 2019, 10:37:00 pm
persistent = 1 Will cause these to only trigger once. That’s why these varadds aren’t working.

I haven’t looked at how the rest of your code works yet though.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on January 07, 2019, 04:26:51 am
Another Update.

I have been able to make some progress. (Yay for me!) :) I have fixed all of the issues listed in my last post. But now I have some other problems.

1. The dizzy sound does not stop playing after the opponent exits the dizzy state.
2. I have tried to create a helper that display's "Dizzy Birds" above the player or opponents' heads when they enter the dizzy state. The birds display above the P1's head just fine, but when I put P2 into the dizzy state, a clone of P2 is displayed above there head instead.

As usual, here is the code I am using.

Code:
[state 5300, Birds/Stars]
type = helper
trigger1 = time = 0
helpertype = normal
name = "Dizzy Birds/Stars"
ID = 5305
stateno = 5305
postype = p1
pos= 10,-74
ownpal = 1
persistent = 0

And Then

Code:
; Dizzy Birds/Stars

[Statedef 5305, Dizzy Birds/Stars]
type = S
physics = N
anim = 5305
sprpriority = 1
ctrl = 0

[state 5305, bind]
type = bindtoparent
trigger1 = stateno = 5300
pos = 0,0

[state 5305, remove]
type = destroyself
trigger1 = parent,stateno != 5300
trigger2 = roundstate != 2
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: ink on January 08, 2019, 01:39:39 am
The clones are caused by P2 not having access to your states. While in a custom state, if P2 spawns a helper it looks in its own states not P1’s.

You could have your player(p1) spawn a helper with postype = p2, if p2 is in the dizzy state.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: Odb718 on January 09, 2019, 12:20:10 am
I'd suggest using changeanim2 if possible. But you may want to make the dizzy bird's be P1's state and not P2's.
My reasoning is, once P2 is out of being dizzy, you can have the birds switch to an invisible state and stop the sound being played.
You'll want to play the sound on a particular channel, and stop that particular channel in the bird's "death" state. You wont need much, a blank animation lasting a few tics, then stopsnd, and the destroyself.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on January 11, 2019, 06:50:25 pm
Thank you both for the advice. I'll let you know if it works.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on January 14, 2019, 12:57:14 am
Nothing seems to be working. I've tried everything that has been suggested by both ink and Odb718 but all I get are clones.

Maybe describing in a different manner what I'm trying to accomplish will help.

I'm trying to make a failsafe of sorts for my character template. That will bring the opponent into a dizzy (Custom) state, (Complete with "Dizzy Birds/Stars".), if the opponent does not have there own Dizzy State.

Or, If the opponent does not have there own Dizzy State, (With or without birds/stars.), then my character will bring them into it's own dizzy state, (With birds/stars.)

I hope that was not confusing.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: ink on January 14, 2019, 01:03:38 am
I believe the problem is p2 in a custom state can’t make a helper use your states. So if p2 spawns a helper in the custom states to make dizzy stars/birds that will not work.

When p2 is in a custom state you should have p1 spawn the helper instead. If I’m understanding everything correctly.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: Nep Heart on January 14, 2019, 01:04:34 am
 You can't put unique graphics like that in custom states. What you should do instead is call the helper in statedef -2 whenever the opponent is in the dizzy custom state (so, a trigger like "p2stateno = whatever number the dizzy state is) and make sure you have a "triggerall = !numhelper(####)" so that the helper doesn't get called more than once during that p2stateno. The reason for this is because custom states, while being your character's state numbers, still calls graphics and sounds from the files of the victim themselves.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: Odb718 on January 14, 2019, 09:27:15 am
Technically you CAN get P2 to get the sprites, but it's long and tedious and should only be done for certain things.
My Sagat has a trick, P1 puts P2 into a custom state. Waaaaaaay under the map, P2 has a hit box and P1 spawns a hit box at that same spot. P2's in P1's custom state, but put's P1's helper into it's custom state allowing access

@MarioManX1983 do what Ink and Nep suggest and use Statedef -2 to spawn the helper/explod.  Use P2's height as the Y position and you should be good. Maybe P2's Y pos + like 20 or 10 to have it above the head. You'll be using (enemynear,const()) if you're not sure how to get at it.
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on January 15, 2019, 07:08:02 pm
Thanks to everyone's efforts, I am now so very close to getting my universal dizzy coding perfect. :)

I now have it to where the "Dizzy Birds" appear over either players heads when they enter the dizzy state and disappear when the Dizzy is over by any means. No clones what so ever.

Now. The only problems I seem to be having are...
1. The "Dizzy Birds" do not lock onto P2. (When I push P2 during a dizzy, the birds stay where they spawned instead of following the opponent.) And yes I have tried BindToParent, BindToTarget, TargetBind, etc.

2. If the player has not yet been dizzied, the "damage counter" counts down normally. (One point every second while the player is not being damaged.) Which is good. However, after the player has already been dizzied once before, the "damage counter" counts down really fast. (Like 2+ points every second or whenever the player moves/attacks.) Which is NOT good.

Here is all the code I am currently using.

The Dizzy Code
Spoiler, click to toggle visibilty

The Dizzy Activator Code For P1.
Spoiler, click to toggle visibilty

The Dizzy Birds Activator Codes
Spoiler, click to toggle visibilty

And Finally, The actual Dizzy Birds Helper Codes.
Spoiler, click to toggle visibilty

We are so close I can almost touch it! :) Let's get these last two hurtles cleared folks! :)
Title: Re: Need Help With Dizzy/Stun Codeing
Post by: Odb718 on January 15, 2019, 07:55:35 pm
Edited your post only to put the <code> into it to make it easier to read.

I don't have enough time to dig through your code, but the double counting sounds like you're using a varadd where it needs to be a varset. OR You NEED to use a varadd, and once everything is done, it doesn't reset to 0.  Use DisplayToClipboard to monitor the value(s) and you'll be able to see if something doesn't reset, or if it is actually going up by 2 instead of 1 or whatever.

For the birds not following P2, do something like a PosSet based off of P2's Pos.


[State 0, PosSet]
type = PosSet
trigger1 =   Pos X != P2.Pos X
x = P2.Pos X
ignorehitpause = 1

[State 0, PosSet]
type = PosSet
trigger1 = Pos Y != P2.Pos Y
y = P2.Pos Y
ignorehitpause = 1


^^^ All that is wrong but you get the idea. You'll more than likely want the X and Y posset individual. You probably dont want the Y, and if you use the head height, obviously you dont want to use the pos y.

Title: Re: Need Help With Dizzy/Stun Codeing
Post by: MarioManX1983 on January 20, 2019, 09:10:54 pm
I've done it! (sort of) FINNALY!

After seemingly trying everything under the sun and then some and getting no ware. I decided to scrap the opponent dizzy coding for now and instead focus on the self dizzy coding.

At first the only problem I was having was this weird issue where after the character had already been dizzied once before, the "Hit Counter" would count down by 2+ every second or whenever any buttons where pressed or released.

At first I was completely stumped, but, after A LOT of experimenting, a little creative thinking and a little dumb luck. :) I have FINNALY discovered and fixed the problem. For some unknown reason the issue was arising because the character was being placed into the "H - GetHit" state type when dizzied. In order to counteract this, I created a -2 state that resets the character to the "I - Idle" state type whenever the character is placed into the dizzy state. And now, everything seams to be working perfectly. :D

Here is all the code involved.
Spoiler, click to toggle visibilty

I would like to thank all who have offered there help and will now be marking this topic as solved. :D

I would also like to post a reply on the Mugen Class Dizzy Mechanics Post, containing my code along with detailed details for the sake of other newbs like me if I may.