monster lock triggered when only 1 enemy defeated

I would like the monster lock to only trigger when ALL enemies have been defeated, not just one.

I am using Dale's fixed monster lock code, and his melee object script...frankly I don't remember anymore what edits have and have not been made, it's been a while :)
 

dale_coop

Moderator
Staff member
Hmmm... maybe an error somewhere in your code.
Could you share your handle monster hurt script?
 
sure, thank you:

Code:
;;; what should we do with the monster?
        ;;; monster is loaded in x
        LDA Object_vulnerability,x
        AND #%00000100 ;; is it weapon immune?
        BEQ notWeaponImmune
        ;PlaySound #SFX_MISS
        JMP skipHurtingMonsterAndSound
    notWeaponImmune:
        
        LDA Object_status,x
        AND #HURT_STATUS_MASK
        BEQ dontskipHurtingMonster
        JMP skipHurtingMonster
    dontskipHurtingMonster:
        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 skipRecoilBecauseOnEdge
        LDA Object_vulnerability,x
        AND #%00001000 
        BNE skipRecoilBecauseOnEdge ;; 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
    skipRecoilBecauseOnEdge:
        LDA Object_health,x
        SEC
        SBC #$01
        CMP #$01
        BCC +
		JMP notMonsterDeath
	+
	
		
		LDA Object_x_hi,x
		STA temp
		LDA Object_y_hi,x
		STA temp1

		DeactivateCurrentObject

		CreateObject temp, temp1, #OBJ_MONSTER_DEATH, #$00, currentNametable


        ;DeactivateCurrentObject
        PlaySound #SND_SPLAT
        ;;;;;;;;;;;;;;;;;; ok, so now we also add points to score
        ;LDY Object_type,x
        ;LDA ObjectWorth,y
        ;STA temp
;       AddValue #$03, GLOBAL_Player1_Score, temp
                ;arg0 = how many places this value has.
                ;arg1 = home variable
                ;arg2 = amount to add ... places?
        ;; and this should trip the update hud flag?
        
        ;;;; 
    

	TXA
	STA tempy

	AddValue #$08, myScore, #$01, #$00

	;STA hudElementTilesToLoad
	;	LDA #$00
	;	STA hudElementTilesMax
		; LDA DrawHudBytes
		; ora #HUD_myScore
		; STA DrawHudBytes
	UpdateHud HUD_myScore
	LDX tempy

        JSR HandleDrops
        JSR HandleToggleScrolling
		
		CountObjects #$00001000, #$00
		LDA monsterCounter
		CLC
		BEQ +
		JMP ++
	+
		.include SCR_KILLED_LAST_MONSTER
	++
        
        JMP skipHurtingMonster
    notMonsterDeath
        STA Object_health,x
    skipHurtingMonster: 
        ;PlaySound #SFX_MONSTER_HURT
    
    skipHurtingMonsterAndSound:
        ;LDX tempx
        ;; what should we do with the projectile?
        ;DeactivateCurrentObject
 

dale_coop

Moderator
Staff member
In the script, you should keep the LDX tempx" line at the end of the script. The object collision code needs it. I'd suggestion to uncomment it.
Else the script looks correct.
You said you're using the Melee object (instead of the sprite sword). Have you correctly disabled the Handle Sprite Weapon ? (assigned a BlankScript to it, in "Project Settings > Script Settings"?
 
Hmm if I recall correctly there was a reason why that tempx line was commented out...Maybe had to do with melee disappearing when it collided with an enemy? I'l check.
 
Yep, just checked and when I don't comment that stuff out, the melee disappears when it collides with an enemy. It also doesn't fix the initial problem unfortunately.

Correct, I have a black script assigned to that.
 

dale_coop

Moderator
Staff member
It's the "DeactivateCurrentObject" line that would make disapear your player melee... not the "LDX tempx".
But yeah, I agree, I was aware that would not have solved your issue.

If you want to share your project (send me a zipped), I could check and tell you how to fix it?
 

dale_coop

Moderator
Staff member
Could you send me again? didn't find it (maybe I deleted it, by accident? my PM mailbox is full...>_<)
 
Ugh PMs are being weird and I am not sure if it is being sent.

I'll just share it here, thanks again! https://filebin.net/4tmavdjjth4b00du
 

dale_coop

Moderator
Staff member
BentPawGames said:
Ugh PMs are being weird and I am not sure if it is being sent.

I'll just share it here, thanks again! https://filebin.net/4tmavdjjth4b00du

Got some time to check today...
I see your issue. Modify the script assigned to the "Handle Monster Hurt" element in your "Project Settings > Script Settings"... search the like:
Code:
	CountObjects #$00001000, #$00
And replace it with this one:
Code:
	CountObjects #%00001000, #$00
(the difference is the "%" instead of the "$")

Now it should work better.
 

dale_coop

Moderator
Staff member
Glad it fixed your issue ;)
#$ is used to represent values as hex (#$0E)
#% is used to represent values as binary (#%01010101)

But when coding quickly, it's easy to make that kind of errors, writing a $ instead of a %... (Even in the NESmaker 4.1.5 code, Joe made a few mistakes like that).
 
Top Bottom