Disable jumping over ledges onto obstacle tiles or NPCs - pret/pokecrystal GitHub Wiki

Ledges are always placed in maps so that you can safely jump over them, without landing on an obstacle tile (like a building, tree, or water) or an NPC. It's a common mistake for beginners to misplace ledges so that you might jump onto an obstacle and get stuck. But if for some reason you want to design your map that way, you can add a check in the ledge-hopping code to only jump when it's safe to do so.

Edit DoPlayerMovement in engine/overworld/player_movement.asm:

+; d = x coordinate of tile across the ledge
+	ld a, [wPlayerMapX]
+	ld d, a
+	ld a, [wWalkingX]
+	add a
+	add d
+	ld d, a
+; e = y coordinate of tile across the ledge
+	ld a, [wPlayerMapY]
+	ld e, a
+	ld a, [wWalkingY]
+	add a
+	add e
+	ld e, a
+; make sure the tile across the ledge is walkable
+	push de
+	call GetCoordTileCollision
+	call .CheckWalkable
+	pop de
+	jr c, .DontJump
+; make sure there's no NPC across the ledge
+	xor a
+	ldh [hMapObjectIndex], a
+	farcall IsNPCAtCoord
+	jr c, .DontJump

 	ld de, SFX_JUMP_OVER_LEDGE
 	call PlaySFX
 	ld a, STEP_LEDGE
 	call .DoStep
 	ld a, PLAYERMOVEMENT_JUMP
 	scf
 	ret
 
 .DontJump:
 	xor a
 	ret