[4.1.5] Trigger Screen If No Monster Tile Type (because, why not?)

dale_coop

Moderator
Staff member
Sometimes, I want my screen to be triggered when I killed on the monsters (special rooms, boss rooms, ...) I already had a trigger screen tile type but it was not exactly the behavior I wanted. I could have trigger the screen when all monster killed... but it would have that behavior in all my screens, and don't want that either...

So I made a special tile type: Trigger Screen If No Monster... When the player walks on that tiles, it trigger the screen, ONLY if there is no monsters on screen:

1/ Make a new "TriggerScreenIfNoMonster.asm" script (in your "Routines\Basic\ModuleScripts\TileScripts" folder):
Code:
;;Triggers the Current Screen If No Monster:
	CPX player1_object
	BEQ +
	JMP ++
+
	CountObjects #%00001000, #$00 ;; count monsters.
	LDA monsterCounter
	CLC
	BNE ++
	;;; Trigger the screen only if no monster on screen:
	TriggerScreen screenType
++


2/ Assign that script to an unused "Tile Colission XX" element in the "Project Settings > Script Settings"

2019-04-25-14-54-11-Project-Settings.png



3/ In th e"Project Settings > Project Labels", rename the corresponding Tile Type to "Trigger Screen If No Monster":

2019-04-25-14-54-38-Project-Settings.png



4/ Now make your assets and place them at strategic points, near the screen exits (where the player will walk on before leaving the screen).

VoilĂ  :)




PS: and here's the "TriggerScreenIfNoMonster.asm" script, to use with the Two Players module:
Code:
;;Triggers the Current Screen If No Monster:
	CPX player1_object
	BEQ +
	CPX player2_object
	BEQ +
	JMP ++
+
	CountObjects #%00001000, #$00 ;; count monsters.
	LDA monsterCounter
	CLC
	BNE ++
	;;; Trigger the screen only if no monster on screen:
	TriggerScreen screenType
++
 
Question:
Can I change this to count NPCs just by changing the CountObjects bit? Or do I need to setup a NPCcounter variable?

My NPCs are killable, and I'd like to trigger in some consequences.
 

dale_coop

Moderator
Staff member
Exactly, just change the CountObjects bits... according to the CountObjects.asm macro:
Code:
	;; arg0: What object flags should we be looking for?
			;; the number of monsters?  the number of monsters + monster projectiles?  The number of NPCs?
			;; the number of triggers?  Pickups?  ALL object types?  
			;; by default, these are set up to be:
			;; #%00000000
			;;         |+--persistent
			;;         +---player
			;;        +----player weapon
			;;       +-----monster 
			;;      +------monster wewapon
			;;     +-------pickup
			;;    +--------target
			;;   +---------NPCs
			;;
			;; So, for instance, to count all monsters + targets, arg0 would be #%01001000
 

SciNEStist

Well-known member
This a great script and exactly what I was looking for! It does the job of triggering the same screen perfectly.

I tried adapting it to trigger another screen (for example, i changed it to "TriggerScreen #$0F" to trigger screentype 15, and it also works, but I did run into an issue:

if i place this modified tile type on a screen that is already triggered, it will trigger screentype 15 if there are monsters onscreen or not.

I ran into this issue when I triggered a screen to spawn a boss that wasnt there previously, then tried to trigger another screen (screentype 15) after beating the boss and walking through a corridor. I guess I need to find another way of checking if there are any monsters on screen.
 
Top Bottom