This works best for melee attacks. If you have both melee and projectiles in your game, then I would suggest using this method for just the melee, and having projectiles get destroyed as they already do by default in NESmaker. If you want a projectile that can go through multiple enemies, then that will require some more thought than what I am going to be covering here.
Difficulty: Easy. You only have to make a couple of small changes in two files.
Pros and Cons:
+You character won't look like they lost an arm or has an invisible weapon when you successfully attack an enemy.
How to Do It:
1. Go to Project>Project Settings and click on the Script Settings tab. Select the Script for Handle Monster Hurt and click the edit button. Go all the way to the bottom of the code where it says DeactivateCurrentObject. This is the line that makes your weapon disappear, so either comment it out or delete it. In its place put the following code:
LDA Object_flags,x AND #%11111011 STA Object_flags,x
2. Next go back to the Script Settings tab. This time select the script for Handle Object Collision and again click edit. Search for the label continueObjectCollisions_objectIsNotHurtOrInvincible. It will probably be around line 60 or so. You should see the following code there:
continueObjectCollisions_objectIsNotHurtOrInvincible LDY Object_type,x LDA ObjectFlags,y AND #%00000110 BNE continueObjectCollisions_onlyPlayerTypesCheck JMP doneWithThisObjectCollision
Delete the first line after the label, and change the second line from LDA ObjectFlags,y to LDA Object_flags,x. That section should now look like this:
continueObjectCollisions_objectIsNotHurtOrInvincible LDA Object_flags,x AND #%00000110 BNE continueObjectCollisions_onlyPlayerTypesCheck JMP doneWithThisObjectCollision
Go down a couple more lines to where you see another ObjectFlags,y in the continueObjectCollisions_onlyPlayerTypesCheck section. Change that one also to an Object_flags,x. Save the changes.
And you're done! You should be able to run the game and your melee weapon should be able to hit an enemy without vanishing.
If you also have projectiles in your game (that do disappear upon hitting an enemy), then you will need to do a check for what kind of player weapon it is. This is my suggestion for doing that, but I am writing this one off the top of my head, because I'm not in a position to test this easily right now. Use something like this code instead of the code in step 1 for the Handle Monster Hurt Script:
LDA Object_type,x CMP #$01 ;; this means it's checking if it is your second game object in the NESmaker Editor BEQ WeaponIsMelee DeactivateCurrentObject JMP DoneHurtingMonster WeaponIsMelee: LDA Object_flags,x AND #%11111011 STA Object_flags,x DoneHurtingMonster
If you have more than one melee attack object as suggested in Adventure tutorials, you will have to modify this suggested code a bit.
A Brief explanation of what is going on:
ObjectFlags,y holds the the flag information that an object of type y should have when it is created. Upon creation that gets copied to Object_flags with an "id" of x. So when we change the Object_flags, we are saying that this object is no longer a weapon. So when the object collision checks occur, the weapon will be ignored for the rest of its lifetime. When we attack again, again ObjectFlags gets copied into Object_flags for our new instance and this attack object is ready to do some hurting.
Ok. That's everything. Once again feel free to ask any questions. I'll remember to subscribe to this topic so I will be notified if anyone comments.