All that the function needs is a position to start at. In the example it is the horizontal center of BadGuy and the vertical top.
To make this function work independent of BadGuy, just add 2 parameters to the function, the x and y of the starting point. Let's say you have a sprite named "anotherBadGuy". When calling the function, do this:
-> Function: Add Parameter someDamage
-> Function: Add Parameter anotherBadGuy.Left + anotherBadGuy.Width / 2
-> Function: Add Parameter anotherBadGuy.Top
-> Function: Call function "DMG"
Now change the function itself to work with the new parameters.
Change the following:
-> System: Create object "numbers" on layer 1 at (BadGuy.Left+BadGuy.Width/2-Global('width')/2+Global('temp'), BadGuy.Top)
-> System: Create object "numbers" on layer 1 at (Function.param(2) - Global('width') / 2 + Global('temp'), Function.param(3))
Whenever you want to display damage near an object, just pass an x and y value as parameters 2 and 3 like in the "anotherBadGuy" example above.