YesNoOk
avatar

Help With Auto-Regen (Read 20458 times)

Started by Krendall, January 27, 2008, 02:52:15 am
Share this topic:
Help With Auto-Regen
#1  January 27, 2008, 02:52:15 am
  • avatar
  • *
I'm looking at adding auto-regeneration to a character. However, the code I'm trying to use doesn't seem to do anything. I've tried looking around the forums but every LifeAdd codes seems to be connected to a specific move.

What I'm looking to have happen is that when the character is damaged, he slowly (50 is just for test purposes, I'm looking something like 1 point per second) regains health until he's back to full. I want this regeneration to be constant whether he's doing other attacks, getting attacked, or standing still.

Here's the code I've done so far:
;Life Regen
[Statedef -4]

[State -4,0]
type = LifeAdd
trigger1 = Life < LifeMax
trigger1 = RoundState = 2
value = 50
persistent = 10

Please help.

PS: What does "persistent" mean? I can't find it in the docs, but I saw it attached to all related coding.
Last Edit: January 27, 2008, 03:29:01 am by Krendall
Re: Help With Auto-Regen
#2  January 27, 2008, 03:19:12 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Try statedef -2, not -4. There is no such thing as state -4 anyway.

Persistent will not take effect in state -2

if you want that effect you'll be using trigger1 = gametime%10 = 0

50 life every 10 ticks = 300 life per second. I don't forsee that character dying quickly.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: Help With Auto-Regen
#3  January 27, 2008, 03:28:34 am
  • avatar
  • *
Thanks a TON! It works perfectly! :D And you can rest assured that the new value is MUCH lower. Basically, I'm only looking to recover 1-5 points per second. Maybe even less.
Try statedef -2, not -4. There is no such thing as state -4 anyway.
I thought statedef created a state and the actual number didn't matter. Guess not...

Just curious, why does this work so well in -2?
Re: Help With Auto-Regen
#4  January 27, 2008, 04:01:15 am
  • ******
  • Legendary XIII
  • I am the eye of the storm to come!
    • New Zealand
    • network.mugenguild.com/cyanide/
Answer is in the docs, but explanation anyway.

State -2 is always checked. Every tick. No questions.

State -3 is also always checked, except when you're in a custom state. Then it's not checked. State -1 is also always checked, but only during roundstate = 2, I think. AI's tend to stop if coded in state -1 so that's probably correct. Explanation in the docs seems a little limited on that one for me.

Anyway, -2 and -3 are special. -4 would probably be the same as writing 987474 in mugen terms. I've never actually tried a - state that's not one of the normal 3.


In M.U.G.E.N there is no magic button

They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance.
Re: Help With Auto-Regen
#5  January 27, 2008, 04:35:07 am
  • ***
  • Small characters can kick big ass.
    • USA
Quote
ii. Trigger persistency

In the case where you do not want the trigger to activate every single time the condition is true, you will need to add a "persistent" paramter. Let us begin with an example:

[State 310, 1]
type = PosAdd
trigger1 = Vel Y > 1
x = 10

This state controller moves P1 forwards by 10 pixels for every tick of game time where P1's Y-velocity is greater than 1. That is, the controller is being activated everytime the trigger condition is true. If we want the controller to be activated only once, we will need to add a line:

[State 310, 1]
type = PosAdd
trigger1 = Vel Y > 1
persistent = 0       ;<-- Added this line
x = 10

"Persistent" has a default value of 1, meaning that the controller is activated everytime the trigger is true.
Setting "persistent" to 0 allows the controller to be activated only once during that state. This holds true until P1 leaves that state. If P1 returns to that state later, the controller can be activated once again.

The "persistent" parameter can also take values other than 0 and 1:

[State 310, 1]
type = PosAdd
trigger1 = Vel Y > 1
persistent = 2       ;<-- Modified this line
x = 10

In this case, setting "persistent" to 2 means the controller will be activated once of every two times the trigger is true. Setting "persistent" to 3 activates the controller every 3rd time, and so on.
This is what I found in the docs.

As for regeneration, here's a code I used for my own character. Make sure to put this under [StateDef -3] and feel free to modify it to your preferences:
[State -3, Regeneration]
type = LifeAdd
triggerall = Alive = 1
trigger1 = (GameTime%10) = 0
ignorehitpause = 0
value = 2
I hope this helps.
Re: Help With Auto-Regen
#6  January 27, 2008, 05:05:38 am
  • avatar
  • *
Thanks again for all your help, everyone! I'm really trying to get a handle on how the coding in MUGEN works, and I think a lot of it is really starting to click.

BTW, I'm sorry I didn't notice the CNS doc to check out both persistancy and the state conditions. I was looking through triggers, sctrls, and expressions, but obviously I didn't find what I was looking for in those docs.

Also, I'm the kind of person who learns a lot better seeing a practical application of code (such as the life regen we just made) and then being told how the parts of it work. I guess it's easier for me to understand when I can see it at work.