Make events take HP from the player depending on its DEF?

Hello!


Hope someone can help me...


I am working on a simple, evented combat system. I have events to work as enemies and take HP from the player when touching it. But of course, he has a DEF attribute, so depending on it it should take less or more damage.


I guess there is a script call or way to do it. I am kinda noob still, so any help will be very appreciated.
You'll need to use variables a bit for this-


Pick three variables, we'll call 'em registers A and B for simplicity


Set register A to hold the base damage. This is probably a static value, you'll have to decide it yourself. Set variables -> constant


Set register B to the player's defense value. Set variables -> game data -> actor -> def / mdef, whichever.


Then, you're going to subtract B from A. Set variables -> variable and find B. This assumes 1 defense would subtract 1 from the damage taken, 2 defense, etc. If you want something more complicated, you can do more math on the variables, or involve extra variables.


Now, variable A contains the damage you want to deal! Change HP -> actor you want to damage -> variable amount, and specify register A.


If you want something more complicated, like every actor taking different damage, or even detecting different leaders, or factoring in elemental resistances? You're probably better off using some kind of script call.
Thanks a lot, @Doktor_Q !


I did as you suggested, and it works. It's a big step for my game, so I feel very grateful to you. Thanks again! 

Original thread: https://forums.rpgmakerweb.com/threads/make-events-take-hp-from-the-player-depending-on-its-def.70915/