YesNoOk
avatar

Guardian Buddy (Read 9968 times)

Started by Noctis, May 10, 2016, 05:42:40 pm
Share this topic:
Guardian Buddy
#1  May 10, 2016, 05:42:40 pm
  • ****
  • Hey, I'm Grump!
    • USA
    • soldier.ucoz.net/
This is a little snippet for a buddy helper that'll glide around your character protecting you, fighting for you, counterattack for you, etc. Whatever you want it to do! There's not much to it. If you're new or have no idea how anything works, don't worry as I explain everything I can and point out what you should and should not edit and how to edit it properly without breaking it.

These are your essentials. For starters, if he has hitboxes and you don't want him to get hit but maybe just push a player around, a nothitby so he won't get hit, the trans, noshadow, scaling, rotation (if desired) blahblahblah. This Guardian Buddy code is designed to look like he's protecting you so keep that in mind when editing.
Also, we're going to be using Statedef and anim 10000 for this helper.
Code:
;------------------------------------------------------------------------------
[StateDef 10000]
Type = S
MoveType = I
Physics = S
anim = 10000

[State -1]
type     = NotHitBy
trigger1 = 1
value    = SCA
time     = 1

[State -1]
Type     = Trans
Trigger1 = 1
Trans    = Addalpha
IgnoreHitPause = 1

[State -1]
Type     = AngleDraw
Trigger1 = 1
scale = 1,1

[State -1]
Type     = AngleAdd
Trigger1 = 1
value = 0

[State -1]
Type = AssertSpecial
Trigger1       = 1
Flag           = Noshadow
IgnoreHitPause = 1

Below is the sprite priority (controls whether or it's in front of you or in back of you).
It'll look decent enough for any normal sized character. Normal sized being CVS2 sized like Mai, Yuri, Chun-Li, etc. Someone big like Zangief, there might be some clipping. To fix that, just edit accordingly.
A regular sized character is from say 40 to -40. So below it's set to just that and since we're using Sin, it'll never fully reach 40 which is why it's 35 instead of 40. For a larger character like Zangief, add about 15 to each value and done.
The Sin multiplier is like a loop. Whatever you multiply it by, it will increase to that value, then decrease to the negative value. So it's going from 40 to -40 in increments of 0.5 per tick. Very simple.
However, the value of fvar(3), which right now is 40 multiplied by sin, must be the exact same as the value in the next few bit's of coding. And obviously, the values for the sprpriority triggers must also be edited to match the new value. of fvar(3). So if fvar(3) is changed to say 75, the triggers must be changed to somewhere around 70. I'll explain more later on.
You could also use Cos in place of Sin. To get a better understanding of how they would work.
Sine vs Cosine
Code:
[State 1, SprPriority]
type = SprPriority
trigger1 = fvar(3) >= 35
value = -5
ignorehitpause = 1

[State -1, SprPriority]
type = SprPriority
trigger1 = fvar(3) <= -35
value = 5
ignorehitpause = 1

[State 0, VarSet]
type = VarSet
trigger1 = 1
fvar(3) = 40*Sin(Time*0.05)

These vars are used for explode sprpriority. Exact same concept as above. Say you got some sparklies you wanna shine off of your Guardian Buddy. Well you don't want the immersion to break when the Guardian is in front of you, but the sparkles are still behind you.
Also, the explod is the way I personally would want it to work. The scale, for example, is set up so that when I'm moving a little faster than usual, the explod increases in size so that the tiny sparkles which would be spread too thinly are now bigger and not spread apart as much as before.
If you don't want the sparkles to be there during a specific time, edit the removeexplod accordingly.
Code:
[State 10000, VarSet]
type = VarSet
trigger1 = fvar(3) >= 35
var(3) = 1

[State 10000, VarSet]
type = VarSet
trigger1 = fvar(3) <= -35
var(3) = 0

[State 10000]
type = Explod
trigger1 = Time%5=0
anim = 10001
ID = 10001
postype = p1
accel = ifelse(random<500,.0125,-.0125),ifelse(random<500,.0125,-.0125)
pos = 10-random%20,10-random%20
scale = ifelse(parent,vel x >3||parent,vel x < -3,.75,.65),ifelse(parent,vel x >3||parent,vel x < -3,.75,.65)
ownpal = 1

[State 10000, ModifyExplod]
type = ModifyExplod
trigger1 = var(3) = 0
trigger2 = enemynear,movetype = A && fvar(4) < 0
ID = 10001
sprpriority = 5

[State 10000, ModifyExplod]
type = ModifyExplod
trigger1 = var(3)>= 1
ID = 10001
sprpriority = -5

[State 10000, RemoveExplod]
type = RemoveExplod
trigger1 = root,stateno = [insert state here]
id = 10001

The best part. Vars and math. The way this is working is whenever an fvar reaches a certain value through increasing, a var will trigger, triggering the fvar to now decrease. Once it decreases to a certain value, the var that was triggered will now untrigger/detrigger, causing the fvar to once again increase.
fvar4 is for horizontal positioning whilst fvar1 and fvar2 are for vertical positioning.
To save you the headache, ONLY edit what's been pointed out in the coding below.
Also, the secondary bindtoparent with the max values are for when you want it to temporarily disappear, but not destroy it. It's not needed and if unwanted, feel free to remove it.
Code:
[State 10000, VarAdd]
type = VarAdd
trigger1 = Time%60
trigger1 = !var(1)
fvar(1) = 0.5

[State 10000, VarAdd]
type = VarAdd
trigger1 = Time%60
trigger1 = var(1)
fvar(1) = -0.5

[State 10000, VarSet]
type = VarSet
trigger1 = fvar(1) >= 60 ;<----------  THIS VALUE CAN BE EDITED, BUT IT MUST BE WITHIN RANGE OF THE Y VALUE OF THE BINDTOPARENT BELOW
                                     ;                 i.e pos = 40,(0+fvar(1)*Cos(Time*0.01+fvar(2)))-60 <--- SO IF THIS Y VALUE (-60) BECOMES -120
                                     ;                 THEN THE VARSET MUST BE EDITED TO 120 FOR THE BEST RESULTS
var(1) = 1

[State 10000, VarSet]
type = VarSet
trigger1 = fvar(1) <= 0
var(1) = 0

[State 10000, VarAdd]
type = VarAdd
trigger1 = Time%1
trigger1 = !var(2)
fvar(2) = 0.001

[State 10000, VarAdd]
type = VarAdd
trigger1 = Time%1
trigger1 = var(2)
fvar(2) = -0.001

[State 10000, VarSet]
type = VarSet
trigger1 = fvar(2) >= 0.1
var(2) = 1

[State 10000, VarSet]
type = VarSet
trigger1 = fvar(2) <= 0.009
var(2) = 0

[State 10000, VarAdd]
type = VarAdd
trigger1 = enemynear,movetype = A
trigger1 = fvar(4) >= -40 ;<----------  THIS VALUE CAN BE EDITED, BUT IT MUST BE WITHIN RANGE OF THE X VALUE OF THE BINDTOPARENT BELOW
                                     ;                 i.e pos = ((40+fvar(4))*Sin(Time*0.05))-(fvar(4)) <--- SO IF THIS X VALUE (40) BECOMES 60, THEN THE VARADD
                                     ;                 MUST BE EDITED TO -60 FOR THE BEST RESULTS
fvar(4) = -5

[State 10000, VarAdd]
type = VarAdd
trigger1 = enemynear,movetype != A
trigger1 = fvar(4) < 0
fvar(4) = 5

[State 10000, BindToParent]
type = BindToParent
;trigger1 = root,stateno != [insert state here]
;or
;trigger1 = 1
time = 1
pos = ((40+fvar(4))*Sin(Time*0.05))-(fvar(4)),(0+fvar(1)*Cos(Time*0.01+fvar(2)))-60 ;<---  THE ((40+fvar(4) AND fvar(2)))-60 VALUES CAN BE EDITED
                                                                                                                       ;        NOT THE FVARS. ONLY THE 40 AND -60 VALUES.
                                                                                                                       ;        THE SPRPRIORITY VALUES ABOVE MUST BE THE SAME VALUE
                                                                                                                       ;        AS THIS BINDTOPARENT'S X POS WHICH IS RIGHT NOW AT
                                                                                                                       ;        40. IF EDITED TO 75, THEN THE SPRPRIORITY FVARS MUST BE
                                                                                                                       ;        EDITED TO 75 AS STATED BEFORE OTHERWISE CLIPPING.
ignorehitpause = 1

[State 10000, BindToParent]
type = BindToParent
trigger1 = root,stateno = [insert state here]
time = 1
pos = 999999999,999999999
ignorehitpause = 1

If you want it to have a nice little glowy trail.
Code:
[State 10000]
type = AfterImage
trigger1 = !Time
time = 999999999
timegap = 2
framegap = 1
length = 6
palbright = 0,0,0
palcontrast = 128,128,128
palpostbright = 0,0,0
paladd = 0,0,0
palmul = 0.7,0.7,0.7
trans = Add



Now that that's all been explained, here's the entire code if you just want to copy/paste.
Spoiler, click to toggle visibilty

Here's what it looks like in-game.
Guardian Buddy helper

It's very simple and explained as thoroughly as I could explain it.
Before someone points out how much more optimized it can be, I find that optimized coding can look fancy and cool or whatever and at most save you a few MB's of space, but gives you less control over things for future edits and makes things MUCH harder to learn from especially if you're a beginner.

This helper works best together with my Super Armor helper.

(Youtube) (WIP) (Mediafire) (New Anime Shop) My Manga Reviews! Personal favorite Patreon! Check her out!

"There is nothing either good or bad, but thinking makes it so."
Re: Guardian Buddy
#2  May 10, 2016, 05:52:56 pm
  • ****
  • Robotics Engineer
    • USA
    • altoiddealer@gmail.com
Interesting.  I might have a need for using this as a base for one of my character's Supers.

Thanks for sharing!

Re: Guardian Buddy
#3  May 10, 2016, 06:05:41 pm
  • ****
  • stillRetired.
  • Formerly Known As Genesis
    • USA
    • www.mediafire.com/folder/7j1slkpa7lm0w/Public_Works
I'll have to give this a read later. Looks really interesting and it gives me an idea...
Re: Guardian Buddy
#4  May 10, 2016, 06:48:15 pm
  • ****
  • Hey, I'm Grump!
    • USA
    • soldier.ucoz.net/
Interesting.  I might have a need for using this as a base for one of my character's Supers.

Thanks for sharing!
You're welcome and I'm happy it might be of use to you!

I'll have to give this a read later. Looks really interesting and it gives me an idea...
I tell yah what. It wasn't easy after coming back to Mugen after such a long hiatus, but I like it. It's suuuper simple and has a really neat effect.
And I'm glad it gave you an idea! Thanks.

(Youtube) (WIP) (Mediafire) (New Anime Shop) My Manga Reviews! Personal favorite Patreon! Check her out!

"There is nothing either good or bad, but thinking makes it so."