Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

[MMF2] RPG Random Numbers Pop up


Asuma

Recommended Posts

I'm having trouble creating random number pop up.

I do something like

[Zero] Attacks [Enemy]

-Set Counter random(5)+1

-Create [Counter] at [Enemy] 0,0

-Subtract [Enemy's Alt Value A] from Counter

When I do that, sometimes is doesn't subtract what number pops up. At other times it pops as zero like 10 times in a row.

Link to comment
Share on other sites

I never seem to be terribly helpful to you, but here goes...:)

First, have you tried switching the order of the last two events, so you'd be creating an instance of the counter AFTER you've subtracted the enemy's hit points from it?

Secondly, how are you limiting the value setting and creation of the counters? I assume all these events occur when Zero collides with the enemy. Have you tried only allowing the counter to be set to a random variable when a flag is off? Then, when the counter is created, set that flag on (this should prevent the multiple pop-ups).

Is that any help?

  • Like 1
Link to comment
Share on other sites

Okay, I wrote something up for you.

http://www.sonicfangameshq.com/forum/attachment.php?attachmentid=815&stc=1&d=1212956132

The idea is, create an active object instead of a counter. Stick the numbers so that they correspond to the directions (IE : Right is represented as 0; so, the animation there should be a 0. Slightly above right is 1; so, the animation there should be one).

You do all the math, then set Flag 0 on. At that point, the active object is draw off-screen, flag 0 is flipped OFF, and Flag 1 is flipped ON.

When Flag 1 is on, the active object is set above the enemy, and it's DIRECTION is set to the value of the counter minus the hitpoints of the enemy.

-----------------------

Take a look at it, and if you need anything else explained, just let me know.

AzuNumbers.gam

Link to comment
Share on other sites

Lol, I though the file said "AznNumbers" XD

This is nice, but active counters seems limiting. I plan to have damage values at least in the hundreds. I might be able to use this same method though.

Link to comment
Share on other sites

First, I'd suggest that you stop using counters. Counters are stupid.

Second, you need to keep order of operations in mind. Not the math stuff where you do parenthesis before anything and then powers and then yadda yadda yadda etc... but the way you are ordering your own events.

Link to comment
Share on other sites

WARNING, GREAT WALL OF SEREPH TEXT APPROACHING, VENTURE ONLY IF YOU ARE WILLING.

YOU ARE GOING TO HAVE TO READ THIS. Just letting you know.

This is the engine i created for my game. I dont know if i did too much or more than i should have, but it works perfectly for me. It took me about 5 hours to perfect from scratch.

This is going to sound really complicated, so if you can find another method i might not try to use mine if it works for you. But mine seems to work perfectly and doesnt glitch up your application like Counters do.

Setting this up (Pay attention.)

Youre going to need to make as many Active Objects as there are place numbers of the max damage you want in your game. you are also going to need the String Parser object.

Put pictures of the numbers 0-9 (in that order) as the animation frames. For each of the Active Objects, make sure that you have Four Alt. Values free in them. They can be any Alt Value, but for not confusing you we're just going to use A, B, C, and D.

Name the alt values:

Alt A = Display_Number

Alt B = Give?

Alt C = Whole_number

Alt D = Place_elminate

---------------

What we are going to do is simple in theroy, but actually takes a small bit of systematic work.

For my example, im going to use the number 251,531. What we need to do is take each individual number (2, 5, 1, 5, 3, 1) and give it to the "Display_Number" value of the place it belongs to MINUS 1. That way, since the frames in the object go from 0 -> 9, when the value is given for it to display 2, it will display Frame 1, which in fact is the number 2.

(keep in mind, that for some reason the value kind of went odd for me, and MMF kind of did this for me. I dont know why, so if your numbers are a tad off, just switch things around. This mostly is going to be so it displays the number 0 correctly, since there is no 0 frame. So make alterations if you need if the numbers are off by one.)

Basically, you create an active for each number place that youre going to have. (So if the max damage in your game is 999,999 like mine, create an active object for Hundred_Thousands, Ten_Thousands, ect ect) Now do the damage calculation. When you come up with the number that you want, store it in the value of something. Or, you can create an equation everytime you do the damage, it doesnt matter.

Take the String Parser object, and make an event that says [Always] --> Set Source String to ( String( *insert finished value here*). What you do here is always turn the number that is supposed to pop up into a String, and store it in the Source value of the String Parser Extention.

The reason we are turning this into a String is because you have to get the value of each individual place in the number. For Example, in order for your active objects to display the number "531,431", you have to be able to take each number place out of that number and give it to the right Active Object for it to be displayed, so that the active "Hundred_Thousands" displays "5", "Ten_Thousands" displays "3", ect ect.

Now that you have the number in the String Parser as a String, you can get data from it like you would a word of letters. (more specifically, you can shift through the characters to get data. In this case, the string is made of numbers.)

Hitting an enemy /creating numbers (pay attention here too.)

When you hit an enemy, set a flag on (lets use Flag 10.) For each instance where a number can be created, you're going to need to create all the number places where you want them to be created (in the same event plz), and set the flag 10 of that enemy on. In the same event, you need to set these alt values as such :

Alt A = Display_Number = (getting to that, look below)

Alt B = Give? =(any number, but make sure it is ABOVE ZERO.)

Alt C = Whole_number = (This should = the number that will be created the second it is created. It should be present in every Active that displays a number.)

Alt D = Place_elminate = Set this to 1.

Getting the place number

Group{enemy} Flag 10 is on -->

Here, youre going to have to get the number places and give them to the right active. (Be prepared for a really long expression. Lets use the Hundred Thousands Place to be clear on this)

This is really hard to explain, since i programmed it in a high mode of thinking, so im just going to paste the expression and go through it step by step.


(Val(Right$(string$( "Damage Number String" ), 6))-Val(Right$(string$( "Damage Number String" ), 5)))*1e-005[/CODE]

Intimidating, but not too complicated.

1) "[b](Val"[/b] First off, we're taking the number from the String Parser Object, so naturally its going to be a string. So that [b]"(Val"[/b] is turning the whole expression into a Value. (Special-->conversions --> Convert String to Number)

2)[b]"(Right$"[/b] What this is is picking what to show from the RIGHT of the string your getting. when you use this option it tells you to input the String youre using, and afterwards the number of characters to move over from the right. [b](Special --> Strings ---> Extract Right Sub-string)[/b]

3) [b](string$( "Damage Number String"), 6)[/b] All this is is the rest of the "Extract Right Substring function. [b]"Damage Number String"[/b] is my String Parser object. [b]"6"[/b] is telling how far over to move from the right. (Which means if the number was 251,531, it would retrieve everything from 6 places to the right and down. So this is getting the entire number.

4) [b]- Val(Right$(string$( "Damage Number String" ), 5)))[/b]

First off, notice the "[b]-[/b]", Minus sign. Here, we are subtracting. This step is simple. Its the same thing, except its taking only 5 places to the right.

See, now we have the full number 6 places to the right which = 251,531 minus that number 5 places from the right which = 51,531.

So now at this point, we have the number 200,000. [b]Now all we need to do is strip this down to just "2".[/b]

5)[b]*1e-005[/b]

This is actually how MMF displays large decimal numbers. [b]However, in reality it reads 0.00001.[/b] Here, you are multiplying 200,000 by 0.000001, which will result in the number "2".

[b]

And boom, you have the Hundred thousands place number. [/b]

Do this with the rest of them, following suit the same calculation and dividing to get the place number you need.

And basically, that was the hard part. In the exact same event where you do these events, make sure to set group[enemy] Flag 10 off so it does it once and immediately stops.

[b][i]FINISHING UP! Actually displaying the number[/i][/b]

From here, you need to set up a Value system that determines WHEN IT SHOULD AND SHOULD NOT set the numbers to the value of the counter, so that all of them dont change to the newest number. And you also need to create a value system that DELETES THE NUMBER PLACES THAT ARE NOT USED UPON CREATION.

Its pretty easy. In the same event where you created this, you set the [b]Alt B "Give?"[/b] to any number that is greater than zero. This is going to be really important.

This is where you make the actives show the number that is in the [b]"Display_Number" [/b]value.

Now make an event.

[CODE]"Pick all objects by value (whatever Display_Number is) = 0.

"Pick all objects by value (whatever Place_eliminate is) = 1.[/CODE]

Now, go through each place active and do this :

Force animation frame [b](value of Display_Number)[/b]

[b]Set Alt Value "Give?" = -1.[/b]

Now, for all numbers who dont have a place number (which is by default a number just created), MMF will tell it to turn its frame number to [b]"Display_Number"[/b] and then set the [b]"Give?"[/b] Value to -1, so that it will never loop again.

There. Now each number should be completely unique. Usual counter glitch method eliminated

Only one more thing to do.

[b][u][i]Eliminate unused place numbers[/i][/u][/b]

Remember [b]Alt C "Whole_number" [/b] and [b]Alt D "Place_elminate"?[/b] Well that is what these are used for.

When the numbers were created, the full number shown was given to every place number active and stored in "Whole_Number". The value "Place_Eliminate" was set to 1.

What we are going to do is now start a check that will eliminate the place numbers depending on if they are needed to complete the whole number shown. This is pretty simple.

Make an event :

[HTML]Pick all objects (whatever Alt-Whole_Number value is) <100,000 [/HTML]

[b]

- Destroy active object Hundred_Thousands Place.

- Make object "Hundred_thousands Place" invisible.

- Set value "Place_eliminate" to 2[/b]

See what we did? Since the Whole Number value stored in the Hundred_Thousands place is LESS than 100,000, then there is no reason for that number place to exist, so it is immediately destroyed.

the other events under that are just precautions, since i was having problems with MMF destroying the other places too slow, or just flat out not destroying them at all. This makes sure they arent seen when they are destroyed either way........

attachment.php?attachmentid=816&stc=1&d=1212966422

Annnnnnnnnnnnnd there you have it.

I was going to make a tutorial on this because it works so well (no errors at all, it works flawless for me), but i havent because god damn it takes so much time to even explain.

The only problem is going to be that if two objects are hit at the same time, its going to display the same number, and if you have defense modifiers or something, they will take the damage but will be shown as the first number to hit them. Im currently finding a way around this problem. It is by no means hard, i just havent gotten to it since i wont be having that problem.

I understand this is alot of shit to deal with, so if you run into any bumps or dont understand something, feel free to catch me on AIM.

post-143-138639762106_thumb.jpg

  • Like 1
Link to comment
Share on other sites

are you creating a different active object for each number? That is crazy.

You can use a simple counter.

If enemy is hurted:

set alterable value Z to Random (5)+1

if alterable value Z > 0

-create counter object at 0,0 from enemy

-set contuer to value Z

-set counter x position to (center the position depending of the number of digits)

-Substract enemy.alterable value Z from enemy.alterable value A

then you can manipulate counter as you want. Give it movement and else.

Having 5 active objects for each object is cpu killer.

And against what DW says, try using counters instead actives when possible. Counters uses less cpu than actives. Counters are god specially for hud or background animations. They use less memory resources that there are much fewer conditions to check on each loop. Doesn't have alterable values or animations. Also they can be drawn as backdrop using less resources. You can have this way big animated active objects like flowers, waterfalls or lights that can be animated by using the value. Instead having a number, you can have a flower and in each number, one animation. Using a global counter you can have it like this:

always

-add 1 to global counter

if counter >=(max frames)

-set counter to 0

-always

-set bgdecorcounter to global counter /(speed of the animation)

  • Like 1
Link to comment
Share on other sites

Actually, no. When it comes to moving and being active, Counters can screw up an application worse than anything.

When i used counters for my damage numbers, not only did they not work right, i got erdt errors everytime i closed the application

Link to comment
Share on other sites

I dunno. But even if i could use counters, i doubt i would ditch my system for them.

Since they are active objects, i can make them do whatever i want and give them special effects (similar to the Text Blitter object stuff)

Now that I got that working. Would someone mind telling me how I can have lifebars above my enemies had showing their health?

Now thats a bit tricky. I personally would once again use active objects.

Maybe have about 20 frames of varied bar health, and have that reflect a percentage of their health.

It wouldn't be 100% precise, but then again you dont need it to be that precise anyway. You would also need to use Alt Values to bind the counter to the object.

In fact, that might be a good addition to my engine instead of just one bar overhead. Ill look into it myself, Azu, and tell you how it goes.

Link to comment
Share on other sites

Lifebars eh?

The tricky part comes with (I'm assuming) having one above each enemy that represents their health. You *can* do this with some sneaky Value/Unique Object Reference NUmber sneakery, but for now I'll outline the basics of health bars since I don't have MMF with me right now.

You'll need 2 objects, a "Health Bar Back" (A large black rectangle that represents the size AND border of a ful health bar) and the actual Bar "A nice red bar.

Now, you'll need to store 2 values in your enemy - Current Health and Max Health. With this, you'll be able to do the math ( Current_Health / Max_Health ) which'll return a number between 0 and 1, where 1 is when the enemy has full health.

Now, MMf2 can resize objects, so you can do something like:

Always/Every 0.00/Constantly/HealthBar is visible

- Set Position of HealthBar Back to Enemy.X and Enemy.Y

- Set Position of HealthBar to HealthBar_Back.X and HealthBar_Back.Y (change this to center it if you wish

- Set size of HealthBar object to height of HealthBar Back, and Width = (HealthBar_Back * (Current_Health / Max_Health ) )

This scales the health bar to maximum size when the enemy has full health, and makes it pretty much invisible (Width of 0 ) when the enemy has no health.

As I mentioned, the tricky part is creating a health bar for each enemy and "pointing" it to the enemy it's attached to so it can get its Position (So it stays above) and its Health (So it resizes). I know MMF2 gives each object a kind of ID Ref number and you can get objects by this number, so it could be possible to link objects together this way..

Chances are there's a better way though, so I'll let someone else explain one :)

  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...