Users browsing this thread: 1 Guest(s)
Final Requests for Help
05-08-2021, 09:45 AM
Okay, I have some code to make tools randomly break:
Notes:
1. You have to set the "destroy if used" bit on all of the tools you want to have a chance to break.
2. When tools are used, they will temporarily be removed from the inventory, then added back after the character's turn if they didn't break.
3. When a tool breaks, it displays the "Ogre Nix broke!" message. You probably want to edit that message to be more generic or add a new one.
4. If the Air Anchor breaks, the "Move and you're dust!" message clobbers the break message.
Code:
hirom
org $C1FFE5 ; freespace
check_command:
CMP #$09
BEQ check_command_end
CMP #$01
BEQ check_command_end
CMP #$08
check_command_end:
RTS
org $C1710F
JSR check_command
NOP
NOP
NOP
org $C21887
JSR check_break
NOP
org $C24DA7
JSR check_command_c2
NOP
NOP
NOP
org $C26469 ; freespace
check_command_c2:
CMP #$09
BEQ check_command_c2_end
CMP #$01
BEQ check_command_c2_end
CMP #$08
check_command_c2_end:
RTS
check_break:
PHA
PHP
JSR $2B63 ; Multiply A by 30, size of item data block
REP #$10 ; Set 16-bit X and Y
TAX
LDA $D85012,X ; equipment spell byte. Bit 7: 1 = remove from inventory upon usage, 0 = nope
BPL no_break ; if the flag is not set, this tool never breaks
JSR $4B5A
AND #$1F ; 1/32 chance of breaking
BNE no_break
LDA #$44 ; "Orge Nix broke!" dialog. Works for most tools but gets clobbered by the Air Anchor "Move and you're dust!"
STA $3401
SEP #$10 ; Set 8-bit X and Y
TYX
LDA #$FF
STA $32F4,X ; null item index to add to inventory. This means the item will stay deducted from your inventory.
LDA $3018,X
BRA check_break_end
no_break:
LDA #$10
TSB $B1 ; set flag to re-add item to inventory at the end of the character's turn
check_break_end:
TSB $3A8C ; flag character to have any applicable item in $32F4,X added back to inventory when turn is over.
PLP
PLA
SBC #$A2 ; carry was clear, so subtract 163
STA $B6 ; save unique Tool index. 0 = NoiseBlaster, 1 = Bio Blaster, etc.
RTS
Notes:
1. You have to set the "destroy if used" bit on all of the tools you want to have a chance to break.
2. When tools are used, they will temporarily be removed from the inventory, then added back after the character's turn if they didn't break.
3. When a tool breaks, it displays the "Ogre Nix broke!" message. You probably want to edit that message to be more generic or add a new one.
4. If the Air Anchor breaks, the "Move and you're dust!" message clobbers the break message.
The following 3 users say Thank You to Subtraction for this post:
• C-Dude (07-08-2021), Gi Nattak (06-06-2021), PowerPanda (05-08-2021)
• C-Dude (07-08-2021), Gi Nattak (06-06-2021), PowerPanda (05-08-2021)
« Next Oldest | Next Newest »
Users browsing this thread: 1 Guest(s)