[4.1] Alternate script for Sword Weapon damage (taking Monster's health in consideration) for the platform module

dale_coop

Moderator
Staff member
Based on the original "HandleSpriteWeapon.asm" script, I made a alternate script for the Sword Weapon damage system (taking Monster's health in consideration) for the platform module of NESMaker 4.1 :
Code:
	GetCurrentActionType player1_object
	CMP #$03 ;; attack state (03 for platform module... and 02 for the adventure module)
	BEQ checkSpriteWeapon
	JMP skipSpriteWeaponCheck
checkSpriteWeapon:

	;;;;;;;;;;;;;;;;;;;;;;;;;
	;;here it did equal the melee attack pose.
	LDX player1_object
	LDA Object_movement,x
	AND #%00000111
	TAY ;; direction for offset table index
	LDA Object_x_hi,x
    ;;; offset x for creation
    CLC
    ADC weaponOffsetTableX,y
	STA selfRight
	SEC 
    SBC #$08 ;; width of weapon 
	STA selfLeft
	
	LDA Object_y_hi,x
    ;;; offset x for creation
    CLC
    ADC weaponOffsetTableY,y
	STA selfBottom
	SEC 
    SBC #$08 ;; width of weapon 
	STA selfTop
	;; run through objects.
	
	LDX #$00	
DoMonsterWeaponSpriteLoop:
	LDA Object_flags,x
	AND #%00001000
	BNE +
	JMP ++
+
	JSR GetOtherCollisionBox
	LDA selfRight
	CMP otherLeft
	BCS + ;; no player object collision
	JMP ++
+
	LDA otherRight
	CMP selfLeft
	BCS +
	JMP ++
+
	
	LDA otherBottom
	CMP selfTop
	BCS +
	JMP ++
+
	LDA selfBottom
	CMP otherTop
	BCS +
	JMP ++
+
;; ok, there is a collision with an monster object, from HERE :
;;; what should we do with the monster?
		LDA Object_vulnerability,x
		AND #%00000100 ;; is it weapon immune?
		BEQ notWeaponImmuneSpriteWeapon
		;PlaySound #SFX_MISS
		JMP skipHurtingMonsterAndSoundSpriteWeapon
    notWeaponImmuneSpriteWeapon:
		LDA Object_status,x
		AND #HURT_STATUS_MASK
		BEQ dontskipHurtingMonsterSpriteWeapon
		JMP skipHurtingMonsterSpriteWeapon
    dontskipHurtingMonsterSpriteWeapon:
		LDA Object_status,x
		ORA #%00000001
		STA Object_status,x
		LDA #HURT_TIMER
		STA Object_timer_0,x
		;;; assume idle is in step 0
		ChangeObjectState #$00,#$02
		;;;; unfortunately this recoil is backwards
		LDA Object_status,x
		AND #%00000100
		BNE skipRecoilBecauseOnEdgeSpriteWeapon
		LDA Object_vulnerability,x
		AND #%00001000 
		BNE skipRecoilBecauseOnEdgeSpriteWeapon ;; skip recoil because bit is flipped to ignore recoil

		LDA selfCenterX
		STA recoil_otherX
		LDA selfCenterY
		STA recoil_otherY
		LDA otherCenterX
		STA recoil_selfX
		LDA otherCenterY
		STA recoil_selfY
		JSR DetermineRecoilDirection
    skipRecoilBecauseOnEdgeSpriteWeapon:
		LDA Object_health,x
		SEC
		SBC #$01
		CMP #$01
		BCC isMonsterDeathSpriteWeapon:
		JMP notMonsterDeathSpriteWeapon
		isMonsterDeathSpriteWeapon:

		LDA Object_x_hi,x
		STA temp
		LDA Object_y_hi,x
		STA temp1
		DeactivateCurrentObject
		;CreateObject temp, temp1, #OBJ_MONSTER_DEATH, #$00, currentNametable
		PlaySound #SND_SPLAT
		TXA
		STA tempx
		AddValue #$08, myScore, #$01, #$00

		UpdateHud HUD_myScore
		LDX tempx

		JSR HandleDrops
		JSR HandleToggleScrolling
			
		;; check for monter locks begin:
		CountObjects #%00001000, #$00
		LDA monsterCounter
		CLC
		BEQ +
		JMP ++
	+
		.include SCR_KILLED_LAST_MONSTER
		JMP skipHurtingMonsterSpriteWeapon
    notMonsterDeathSpriteWeapon:
		STA Object_health,x
    skipHurtingMonsterSpriteWeapon:
		;PlaySound #SFX_MONSTER_HURT
    skipHurtingMonsterAndSoundSpriteWeapon:
	
++
	INX 
	CPX #TOTAL_MAX_OBJECTS
	BEQ skipSpriteWeaponCheck ;; done with checking against objects 
	JMP DoMonsterWeaponSpriteLoop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
skipSpriteWeaponCheck ;; there is no collision here horizontally.

Save it as "HandleSpriteWeapon_UsingMonsterHealth.asm" in your scripts folder, and assign this one to the "Handle Sprite Weapon" in the "Project settings > Script settings".

Of course, this script might be not perfect, it might cause some issues that I am not aware of yet. Feel free to update it, fix it, make your own modifications... or use the original one.

UPDATES
2019/01/13:
Fixed a problem of compatibility with the monster locks, that was when you killed the 1st monster the locks was removed.
 

vanderblade

Active member
Hey Dale.

How do I "assign" it in script settings? I see an Add button, but then I have three fields to input 1) Name; 2) Define; 3) Script. How do I do this?
 

dale_coop

Moderator
Staff member
By any chance, have you made any modification in the HandleDrops.asm?
(because now, this script executes the handledrops --which creates the death object--)
 

dale_coop

Moderator
Staff member
Because just removing the "RTS" in the handleDrops isn't enought to make it works correctly.
Here's is a better fix for that: http://nesmakers.com/viewtopic.php?p=10649#p10649
 

clay

New member
Hello. I'm a newb who tried to implement these changes for the sprite weapon (and the quick fix for monster drops). However, when trying to emulate on MESEN, I see that "Label already defined" message for HandleSpriteWeapon.asm(5, 33, and 84). This is also the only original script that I failed to save before committing. Could someone provide either the original asm for "HandleSprite Weapon" or a fix for the already defined labels mentioned above? Be well!
 

dale_coop

Moderator
Staff member
Have you assigned this script "HandleSpriteWeapon.asm" to another element in the "Project Settings > Script Settings" dialog?
Or maybe under "Scripts > Input Scripts" (in the NESmaker treeview)?

This error message means this script is used twice in your project. So you might have assigned it to a incorrect element.
(And don't hesitate to share screenshots of your settings)
 

clay

New member
Thank, Dale! I accidentally assigned "Handle Sprite Weapons" script to "Handle Monster Death" as well. Now it works perfectly. I appreciate your posts!
 
Hi Jacking thread alert here!! sorry to jump on this old one but im in need of help. im using Metrovania 4.5.9 and i want to have melee attack do 1 damage and projectile do 3. iv looked everywhere for something that will help but so far no good. would you have an idea of what may help me please @dale_coop
 
Top Bottom