Display Damage on map

Hey everyone, I'm working on a sort of ARPG system, kind of a shooter that does damage outside of turn-based combat. I want to display the damage done on the event im shooting at. I know how to do this with a conditional branch

"If damage is 10: display the picture 1 and 0."

But that would obviously require me to make a condition for EVERY number up until 9999, which is silly of course. Has anyone learned of a way to set a variable and keep track of the One's, Ten's, Hundred's and Thousands, and then do a conditional branch saying:

"If One's = 3: show picture 3"

Hopefully this is clear what I'm saying. Thanks in advance.

I have this implemented as a counter in my time system, but since it's just a counter that counts up, its much simpler to implement.
Your best bet is to write or commission someone to write a plugin to just use the damage popups from the battle scene on the map scene- I did a form of this as part of my work on extensions for the SRPG_Core plugin, and it wasn't too bad.

While I would suggest a plugin, you can check the value of individual digits, one at a time, using events with some "control variables" work, and a lot of Mod.

Code:
Set Ones = Damage
Mod Ones 10
[stuff to show your ones digit]
---
if Damage > 9
  Set Tens = Damage
  Div Tens 10
  Mod Tens 10
  [stuff to show your tens digit]
---
if Damage > 99
  Set Hundreds = Damage
  Div Hundreds 100
  Mod Hundreds 10
  [stuff to show your hundreds digit]
---
if Damage > 999
  Set Thousands = Damage
  Div Thousands 1000
  Mod Thousands 10
  [stuff to show your thousands digit]

An explanation: Mod, properly Modulo, gives you the remainder after division. Mod 10, then, gives you the first digit. Dividing by 10/100/1000 removes all the lower digits you don't care about.

To work through an example, lets use 123.

120 is divisible by 10, so 123 mod 10 = 3. That's our ones digit.

123 divided by 10 is 12, 12 mod 10 =2. That's our tens digit.

123 divided by 100 is 1, 1 mod 10 is of course 1. That's our hundreds digit.

123 divided by 1000 is just 0. Since you wanted to show "123" not "0123", we don't bother checking for a thousands digit if the damage is under 1000.
But that would obviously require me to make a condition for EVERY number up until 9999, which is silly of course. Has anyone learned of a way to set a variable and keep track of the One's, Ten's, Hundred's and Thousands, and then do a conditional branch saying:
To print the number you just need to print the digits. It can be altered to exit early if you don't want to print the leading zeros.

In the sample below the length can be used to figure out where the desired X position.
In my case the digits are 24 pixels wide, 32 pixels tall and set X and Y both to 500 and Number to 5678.

Unfortunately there isn't a way to dynamically assign a unique image numbers, but this is a huge improvement over 9999 conditional branches.

[Variables]
1 Number
2 Temp
3 Digits
4 Length
5 X
6 Y

Preview:
Spoiler
printNumbersPreview.png

Event Code:
Spoiler
PrintNumbersEvent.png
That looks like a lot of work... Let me show you how I did it https://galvs-scripts.com/2016/03/23/mv-timed-message-popups/ will allow you to pop up a message over the player or an event. Just put your damage in a variable (like 53) then have the event that's hit run the following message command <c:0,30,0> \v[53] It will show up for 30 seconds before vanishing. If you're a cool kid you can also make the window transparent so it looks like the numbers are floating there. :LZSwink:
Your best bet is to write or commission someone to write a plugin to just use the damage popups from the battle scene on the map scene- I did a form of this as part of my work on extensions for the SRPG_Core plugin, and it wasn't too bad.

While I would suggest a plugin, you can check the value of individual digits, one at a time, using events with some "control variables" work, and a lot of Mod.

Code:
Set Ones = Damage
Mod Ones 10
[stuff to show your ones digit]
---
if Damage > 9
  Set Tens = Damage
  Div Tens 10
  Mod Tens 10
  [stuff to show your tens digit]
---
if Damage > 99
  Set Hundreds = Damage
  Div Hundreds 100
  Mod Hundreds 10
  [stuff to show your hundreds digit]
---
if Damage > 999
  Set Thousands = Damage
  Div Thousands 1000
  Mod Thousands 10
  [stuff to show your thousands digit]

An explanation: Mod, properly Modulo, gives you the remainder after division. Mod 10, then, gives you the first digit. Dividing by 10/100/1000 removes all the lower digits you don't care about.

To work through an example, lets use 123.

120 is divisible by 10, so 123 mod 10 = 3. That's our ones digit.

123 divided by 10 is 12, 12 mod 10 =2. That's our tens digit.

123 divided by 100 is 1, 1 mod 10 is of course 1. That's our hundreds digit.

123 divided by 1000 is just 0. Since you wanted to show "123" not "0123", we don't bother checking for a thousands digit if the damage is under 1000.
So, I kind of have it working. However, it only shows the rounded up digit. So if I hit 9310 I assume it's only showing the 9 in the Thousands spot (I have animations set up to put the numbers in its corresponding spot) So if I hit 550, it only shows 5 in the hundreds spot. I suppose this would work but I could only show rounded up/down numbers. 5000, 400, 60 etc.

I included a small snippet of my code if that helps, perhaps I'm doing something wrong. Thanks alot for your help.
That looks like a lot of work... Let me show you how I did it https://galvs-scripts.com/2016/03/23/mv-timed-message-popups/ will allow you to pop up a message over the player or an event. Just put your damage in a variable (like 53) then have the event that's hit run the following message command <c:0,30,0> \v[53] It will show up for 30 seconds before vanishing. If you're a cool kid you can also make the window transparent so it looks like the numbers are floating there. :LZSwink:
I may try this way, but I'm going to look into the other ways, thanks!
To print the number you just need to print the digits. It can be altered to exit early if you don't want to print the leading zeros.

In the sample below the length can be used to figure out where the desired X position.
In my case the digits are 24 pixels wide, 32 pixels tall and set X and Y both to 500 and Number to 5678.

Unfortunately there isn't a way to dynamically assign a unique image numbers, but this is a huge improvement over 9999 conditional branches.

[Variables]
1 Number
2 Temp
3 Digits
4 Length
5 X
6 Y

Preview:

Event Code:
I'm going to try this way next if I can't make it work, appreciate your response.
I'm going to try this way next if I can't make it work, appreciate your response.
I just want to make sure you didn't miss the Spoiler buttons in my previous post.
The first reveals a screenshot of the test that I did.
The second Spoiler button reveals the working Event Code.
You just need to set the X, Y and Number variables set before running it.
---
I thought of a way to improve my method, but I'll need to post that later today (requires using a JavaScript event Command to replace the Show Picture event Command).

---
Done! Calling showPicture() from JavaScript allows us to save a lot of work.

PrintNumberEvent.png
The JavaScript Event Command:
Code:
$gameScreen.showPicture($gameVariables.value(7), '' + $gameVariables.value(3), 0, $gameVariables.value(5), $gameVariables.value(6), 100, 100, 255, 0);

To dynamically remove the images you can create a loop where you subtract 1 from Variable 7 after each erasePicture() call, then break when Variable 7 is 0.
Code:
$gameScreen.erasePicture($gameVariables.value(7));
I just want to make sure you didn't miss the Spoiler buttons in my previous post.

The first reveals a screenshot of the test that I did.

The second Spoiler button reveals the working Event Code.

You just need to set the X, Y and Number variables set before running it.
---
I thought of a way to improve my method, but I'll need to post that later today (requires using a JavaScript event Command to replace the Show Picture event Command).
So how do the x and y coordinates line up from? Because I want them to display on my event by
I just want to make sure you didn't miss the Spoiler buttons in my previous post.
The first reveals a screenshot of the test that I did.
The second Spoiler button reveals the working Event Code.
You just need to set the X, Y and Number variables set before running it.
---
I thought of a way to improve my method, but I'll need to post that later today (requires using a JavaScript event Command to replace the Show Picture event Command).

---
Done! Calling showPicture() from JavaScript allows us to save a lot of work.

View attachment 128327
The JavaScript Event Command:
Code:
$gameScreen.showPicture($gameVariables.value(7), '' + $gameVariables.value(3), 0, $gameVariables.value(5), $gameVariables.value(6), 100, 100, 255, 0);

To dynamically remove the images you can create a loop where you subtract 1 from Variable 7 after each erasePicture() call, then break when Variable 7 is 0.
Code:
$gameScreen.erasePicture($gameVariables.value(7));
Ok I will give this a shot! Without being on my computer I'm just curious how you are determining the x and y coordinates of the event (enemy). Because I used animations for my numbers because it was easier to show an animation on event (with a common event) then it was to determine the coordinates of an event. Thanks for your help so far
Ok I will give this a shot! Without being on my computer I'm just curious how you are determining the x and y coordinates of the event (enemy).
You can get the coordinates of the Player, Current event, or a specific event, then call the Common Event with the previous information.

PrintNumberEventPosition.png

[Notes]
This assumes the code I previously posted is in the Show Damage Numbers common event.

This will print the numbers below the event. To display the numbers above the event you can subtract 60 (12+48) from Variable 6 which is where Y is stored. Best to do this from the Show Damage Numbers Common Event.

To center the numbers you can try adding half of the Length of the Number, in pixels, to Variable 5 where X is. (This is the only reason why the previous code calculates the number of digits in the number). If the Length is 5 and the width of the digits are 24 then you want to add 24*5 => 120 / 2 => 60 to X.

The numbers I was using are from the system/Damage.png file in the default project.
You can get the coordinates of the Player, Current event, or a specific event, then call the Common Event with the previous information.

View attachment 128329

[Notes]
This assumes the code I previously posted is in the Show Damage Numbers common event.

This will print the numbers below the event. To display the numbers above the event you can subtract 60 (12+48) from Variable 6 which is where Y is stored. Best to do this from the Show Damage Numbers Common Event.

To center the numbers you can try adding half of the Length of the Number, in pixels, to Variable 5 where X is. (This is the only reason why the previous code calculates the number of digits in the number). If the Length is 5 and the width of the digits are 24 then you want to add 24*5 => 120 / 2 => 60 to X.

The numbers I was using are from the system/Damage.png file in the default project.
Oh yeah, I should have known about the X and Y coordinates of the event. Although I have the numbers displaying, I'm still having issues. I'm only getting 4's and 5's showing up.

Now, as I was copying all your code, I realized I hadn't related this to my Player_Damage variable at all. What would I do to make this work? I ended up using your first example as you can see from the screenshot. I'm having issues with my coordinate placements too, but haven't fooled around with the math yet. Also, what's the relevance in the "Numbers = 12345" Thanks so much for your help, I'm close!
Now, as I was copying all your code, I realized I hadn't related this to my Player_Damage variable at all. What would I do to make this work?

Also, what's the relevance in the "Numbers = 12345" Thanks so much for your help, I'm close!
"Numbers = 12345" are the test damage numbers I used. You would either "Numbers = Player_Damage" or just use player damage directly.

I'm only getting 4's and 5's showing up.
I would need to see what your code is doing. My second example is a lot more concise, the only downside is that you need to add a "Script..." Event from tab 3 and be comfortable enough with JavaScript to know what it is doing.

Here is what the parameters for the JavaScript function call mean:
$GameScreen.showPicture(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode)

I ended up using your first example as you can see from the screenshot.
??? You might have forgotten to add the image or thumbnail. I don't see any images in your previous post.
"Numbers = 12345" are the test damage numbers I used. You would either "Numbers = Player_Damage" or just use player damage directly.


I would need to see what your code is doing. My second example is a lot more concise, the only downside is that you need to add a "Script..." Event from tab 3 and be comfortable enough with JavaScript to know what it is doing.

Here is what the parameters for the JavaScript function call mean:
$GameScreen.showPicture(pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode)


??? You might have forgotten to add the image or thumbnail. I don't see any images in your previous post.
lol sorry, I did forget. Here it is
lol sorry, I did forget. Here it is
??? Is it not uploading???
Nevermind, I refreshed and it is showing up now. . .
??? Is it not uploading???
Yeah, having issues, gimme a minute.
Your code looks good.

The only thing to note is that you are trying to print the number 12345, but the first version only prints up to 4 digit numbers so in the end it would print 2345 and omit the 1. You would need to either extend it to print the extra digit or use my second version which programmatically prints all digits.
Your code looks good.

The only thing to note is that you are trying to print the number 12345, but the first version only prints up to 4 digit numbers so in the end it would print 2345 and omit the 1. You would need to either extend it to print the extra digit or use my second version which programmatically prints all digits.
I'm going to try and I'll get back to you, makes more sense now.
Your code looks good.

The only thing to note is that you are trying to print the number 12345, but the first version only prints up to 4 digit numbers so in the end it would print 2345 and omit the 1. You would need to either extend it to print the extra digit or use my second version which programmatically prints all digits.
K, it seems to work but my pictures are displaying in the top left in a few different spots. I think it's just a placement issue, so I have to fart around with it, I'll let you know how it goes, thanks!
Just make sure the "DMG_Display_X = X of This Event" (and Y version) are inside the actual Map Event and NOT a Common Event. If they are inside a Common Event then the common event doesn't really have a location.
Just make sure the "DMG_Display_X = X of This Event" (and Y version) are inside the actual Map Event and NOT a Common Event. If they are inside a Common Event then the common event doesn't really have a location.
Oh, but will I have to make a variable for every enemy then? Cause I think that is my issue.

Original thread: https://forums.rpgmakerweb.com/threads/display-damage-on-map.115839/