The RPG Maker Resource Kit

Other Game Creation => Program Troubleshooting => Topic started by: HowlingWinds on January 04, 2009, 07:05:32 AM

Title: [RESOLVED]Either I'm not seeing it or....
Post by: HowlingWinds on January 04, 2009, 07:05:32 AM
Well, for my game I'm working on making the AI for the first party member that joins you, a healer. What I'm trying to do is make it so if the player falls below 60% HP, then the healer will take his next turn to cast a healing spell on that player. Here is the event code:

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi313.photobucket.com%2Falbums%2Fll387%2FFeliusfeefee%2FLevinshealingAI.png&hash=e7d6a76a23ebcadeca255db1b771f432640a7d47)

Here is what it's suppost to do line by line

[spoiler]Line 1: Recast label
Line 2: Sets the variable equal to Levin's (the healer) MP (though I call it TP)
Line 3: Sets the variable equal to Mihli's MaxHP
Line 4: Sets the variable equal to Mihli's current HP
Line 5:    "
Line 6: Divides Mihli's current HP by her max HP and saves the remainder (This is where I might be going wrong. I don't understand Mod 100%)
Line 7: Condition Branch: If the variable is less then or equal to 60
Line 8: Checks to see if Levin has enough TP to use the healing move
Line 9: If he doesn't, then the sweat drop appears showing he is low on TP
Line 10: If he does, it calls the common event to calc how much he can heal for
Line 11: Animation blah blah
Line 12: Healing blah blah
Line 13: Delay untill next turn
Line 14: Jump to Label Recast[/spoiler]

Even though Mihli is at max HP and not below 60%... this happens....

[youtube=425,350]Cr8J6oWAoW4[/youtube]

So either it's something I'm not understanding about Mod (since I'm not 100% sure what it completely does) or it's something else I'm not seeing =x
Title: Re: Either I'm not seeing it or....
Post by: Revo on January 04, 2009, 08:54:14 AM
Mod actually stores the remainder into the variable.

So what's happening is this...

[spoiler]Check Max HP
  (Max HP = 50)
Check current HP
  (HP = 50)
Mod HP Calc
  (Max/HP)
  (50/50)
  (1)
  (Remainder = 0)
HP Calc = 0
Check if HP Calc <= 60
  (HP Calc = 0)
  (0 >= 60)
  (HP Calc >=60)
Heal
Repeat[/spoiler]

I used the 50 HP as an example number. Basically, Mod isn't the thing to use. I figure you saw the % sign and thought it did percents, but it actually doesn't.

I hope that helped, ask any questions if I confused you at all.
Title: Re: Either I'm not seeing it or....
Post by: HowlingWinds on January 04, 2009, 09:12:41 AM
oh, I'm guessing mod stores up to set amount of numbers like a variable could. I just took a calculator and tried: 30(current)/58(Max) and got .51724137(yada yada) so it's probably storing "51724137" into the variable ><; and it probably reads left to right until it hits capped amount it can store.

Bummer, guess I'll have to think of another way to do his AI  :-\

EDIT: Was just talking to a friend and he figured out a way (if above is the case) I would just make a simple loop of

loop
if number > 100
number /10
end loop

and before the loop I just make a condition branch that checks if the mod is = 0 (full HP) I'll put resolved in the title once I test this out.

EDIT2: Ugh... still doesn't work. Here is what I have now

[spoiler]
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi313.photobucket.com%2Falbums%2Fll387%2FFeliusfeefee%2Flevinsglitch.png&hash=554ecf912c216f579983b64ad35a1a8221c3ede5)
[/spoiler]

If my math is wrong, then that could be the problem (again), but if it isn't it "should" work. Though it doesn't... could it be possible that since this is a parallel process that RMVX is over looking the labels and is skipping them completely?
Title: Re: Either I'm not seeing it or....
Post by: modern algebra on January 04, 2009, 02:14:16 PM
No, mod stores a remainder. Any number can be written as a*b + c

When you mod something by a, then c is the reminder and c is what mod stores.

So:  17 % 5

17 = 5*3 + 2

2 is the remainder, so 17 % 5 = 2

24 % 7

24 = 7*3 + 3,     24 % 7 = 3


What you really want to do is multiply by 100 and then divide.

So:


Control Variables: [32:Levin HP Calc (Max)] = [Mihli]'s Max HP
Control Variables: [41:HP Calc] = [Mihli]'s HP
Control Variables: [41: HP Calc] *= 100
Control Variables: [41: HP Calc] /= [32:Levin HP Calc (Max)]


The number in Hp Calc should now be the percentage of HP left. Make sure that you don't bother using the Heal spell if the actor's HP is 0
Title: Re: [RESOLVED]Either I'm not seeing it or....
Post by: HowlingWinds on January 04, 2009, 06:55:06 PM
oohh >< Now I feel stupid lol. I've been thinking of "remainer" in the wrong way. Thanks MA and Revo for the help, as the AI works now.