Guardian Buddy

Guardian Buddy Tutorial
 

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.

;------------------------------------------------------------------------------
[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

[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.

[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.

[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.

[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.

Text File

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.

Tuesday
27/June/2017
15:41
Search
Site friends