How can I recreate apply dmg function?

Thx for the answear, but I had already watched that video and it only tells you how to use this function and not how it’s made.