[4.5.9] Enabling support for the Strength/Defense System in your game!

Kanbei85

Member
For reasons that remain a complete mystery, Joe and/or the devteam, such as it is, for NESmaker did not see fit to enable the use of the strength and defense system already present in the GUI. Out of the "box", NESmaker will only enable your weapon to do a single hitpoint of damage to any monster, and likewise a monster can only do a single HP of damage to the player.

Out of desperation, I began doing my own study, alongside Francois Brodeur. With his help, and by following a tiny bit of assembly tutorial, I have now got the str/def system working!

First, you will need to add two variables to the Zero Page RAM tab under Project settings: tempDE (for defense) and tempWD (for weapon damage).

Next, add Object_strength and Object_defense as Object Variables.

Last, you will need to add one variable under User Variables: myDefense. This is because I noticed that, for whatever reason, the player1_object variable "defense" value gets cleared to 0 if you die.

Now in your "script/Define Scripts/Subroutines/Create state" Add this between "STA Object_health,x" and "return bank". (Courtesy of Francois)

Code:
LDA ObjectStrengthDefense,y
AND #%11110000
ROR
ROR
ROR
ROR
STA Object_strength,x
LDA ObjectStrengthDefense,y
AND #%00001111
STA Object_defense,x

The result is now that strength and defense are available in the scripts to use as needed for objects (i.e. weapons and monsters). These also work for the player object, but as I said, for some reason they seem to get cleared when the player dies. This could probably be fixed in its own right, but I found it easier to use User Variables myHealth and myDefense instead.

I have gotten this to work for my game (WIP) now in both my Player Hurt and Monster Hurt scripts. I'll include the relevant bits below and you can adapt this to your own scripts as needed. What this does is a simple series of math equasion:
Strength - Defense = Damage

Health - Damage = Updated health


Player Hurt:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DAMAGE SECTION

;DEC myHealth ;old Code from Joe, just decreases by 1 increment
;LDX player1_object ;This doesn't work because player1_object defense is getting set to 00 after a death
;LDA Object_defense,x
;STA tempDE ;Player Defense stat in tempDE
LDX otherObject ;Loading monster strength
LDA Object_strength,x
SEC ;Strength - player defense
SBC myDefense
STA tempWD ;Monster strength - player defense value set to tempWD
;LDX player1_object ;Loading player health to accumulator
;LDA Object_health,x
LDA myHealth
SEC
SBC tempWD
BMI +healthBelowZero
BEQ +healthBelowZero
JMP +notDeadYet
+healthBelowZero
JMP +playerHealthIsZero
+notDeadYet
;STA Object_health,x ;this would update the Player Object health stat, rather than the User Variable myHealth
STA myHealth
UpdateHudElement #$01 ;;Update HUD Hearts
ChangeActionStep player1_object, #$07 ;;Send player object into Action Step 07
PlaySound #sfx_GetHurt

Monster Hurt:


ChangeActionStep temp, #$07

LDX otherObject
LDA Object_defense,x
STA tempDE ;;tempDE is monster defense
LDX selfObject ;;now Player Weapon Object is in X register
LDA Object_strength,x ;;Weapon Strength is in Accumulator
SEC ;;Start Subtract
SBC tempDE ;; Monster Defense subtracted from Accumulator (Weapon Strength)
BMI +End ;;if the result is negative, then no damage happens, so end.
BEQ +End
STA tempWD ;;tempWD is player weapon damage after going through defense

LDX otherObject ;;Loading Monster Health
LDA Object_health,x
SEC ;;Subtracting Weapon Damage from Health
SBC tempWD
BEQ +killThisObject ;;if health is 0, kill
BMI +killThisObject ;;if health is negative, kill
STA Object_health,x ;;Save monster health
JMP +End
+End
JMP +doSkipKILLINGthisObject ;; Return
 
Last edited:

Bucket Mouse

Active member
You're awesome for figuring this out!

Maybe we can get weapons and armor (which would help make this relevant), the shop menus and other things like that working too. There are remnants of the code for them in the RPGBase folder...
 

Kanbei85

Member
You're awesome for figuring this out!

Maybe we can get weapons and armor (which would help make this relevant), the shop menus and other things like that working too. There are remnants of the code for them in the RPGBase folder...

Well, if it's anything like the strength/defense situation, then the ability is just sitting there waiting to be enabled without much trouble.
 

Kanbei85

Member
You're awesome for figuring this out!

Maybe we can get weapons and armor (which would help make this relevant), the shop menus and other things like that working too. There are remnants of the code for them in the RPGBase folder...
Did you notice ShopInfo.dat ?
 

Bucket Mouse

Active member
Did you notice ShopInfo.dat ?
What is it for? It doesn't seem to be loading into any of the banks, and it doesn't correspond to anything in the GUI.
Something called NT_Shop is loaded into Bank 1E, but it's kind of a mess:
Code:
                                     õõõ                           õìáèé                           õõõõõ                                                                                        õ                               õõõõõõõõ
That's what it looks like.

Bank 16 has NT_Shop listed among a few other things that aren't used:
Code:
NameTablePointers:
    .dw NT_StartScreen, NT_Register, NT_SongBook, NT_Death, NT_Menu, NT_NPC, NT_Shop, NT_Hud, NT_Win, NT_Story
I'm not sure where to begin with that.
 

Retrofaija

Member
Thanks for this! It's great how many bits and pieces of diamond solid info you find on the forums just by digging around. Works like a charm this one!
 

CashThulhu

New member
This is great! Finally registered on the forum to say thanks for this. I was banging my head on it for a while before finding this post.
 
Top Bottom