SHLIM
Active member
Hi guys, theres a few AI proxy scripts floating around which all seem to have various issues when trying to use them. The best i could find was the tutorial by Craigery HERE. However, that still had various issues with it (ie monsters always had blind spots and there was no screen edge check) so i took the liberty of making a new one that works without any hassles.
Please note that this will only work on single screens, It will not work with scrolling!
To start the installation you are first going to need to have access to UserScreenBytes by completing this tutorial HERE
Now copy and paste the code below into a new ASM file called easyAIProxy.asm and save in your BASE_4_5\Game\AI_Scripts folder.
Now assign this script to one of your Monster action steps and set UserScreeByte1 to how far youd like your monsters forward vision to be, and set UserScreeByte2 to your monsters wide vision. These numbers are calculated in pixels and you will need to set them for each screen the easyAIProxy script will be used on. If you do not set either of the bytes then the script will not execute.
This script will work no matter where you place your monster, it will check for the screen edge and all fields of vision dependant on the direction that the enemy is facing! Youl also see theres some tile detection code added which was created by BucketMouse! With this you can create special tiles which if the player is stood on it will act as if the player is hiding from the NPC and will not be seen!
And thats it easy peasy!
Love from SHLIM
Please note that this will only work on single screens, It will not work with scrolling!
To start the installation you are first going to need to have access to UserScreenBytes by completing this tutorial HERE
Now copy and paste the code below into a new ASM file called easyAIProxy.asm and save in your BASE_4_5\Game\AI_Scripts folder.
Code:
;; easyAIProxy by SHLIM
;;userScreenByte1 = Facing Proxy Distance
;;userScreenByte2 = Peripheral Proxy Distance
;; transfer Monster
TXA ;; move x to a (monster is already stored in x)
STA temp ;; store monster in temp
LDX player1_object ;; load player
LDA Object_x_hi,x ;; horizontal position
ADC #$08 ;;this moves the X position to the players center (if using a 16 pixel wide player)
STA temp2
LDA Object_y_hi,x ;; vertical position
STA tempB
JSR getPointColTable ;; here you can use a special tile to hide the player if necessary
CheckCollisionPoint temp2, tempB, #$0C, tempA ;; checks if player is on special tile
BNE +notBehindObject
JMP +doneProxy
+notBehindObject
;;Load Monster
LDX temp
LDA Object_x_hi,x
ADC #$08 ;;adds 8 pixels so it is centered on 16 pixel wide monster. Change if necessary
STA tempC ;; horizontal
LDA Object_y_hi,x
STA tempD ;; vertical
;; check enemy direction
LDA Object_direction,x
CMP #%00000110
BEQ +NPCfacesLeft
CMP #%00000010
BEQ +NPCfacesRight
CMP #%00000100
BEQ +NPCfacesUp
CMP #%00000000
BEQ +NPCfacesDown
JMP +doneProxy
+NPCfacesLeft ;; npc is facing left
LDA tempC ;; monsters hori position
CMP temp2 ;; compare to players hori position
BCC +gotodoneProxy ;; if player is behind enemy end
CMP userScreenByte1 ;; compare byte to enemys position (check for screen edge)
BCC +checkPeripheralU ;; if distance is more than space left on screen we know player is in range so skip next check
SBC userScreenByte1 ;; deduct byte from temp c
CMP temp2 ;; compare to see if carry is now set (checks if player is now behind enemy once byte is deducted, this indicates hes in range)
BCC +checkPeripheralU ;; if temp2 is now higher than tempc
JMP +doneProxy
+NPCfacesRight
LDA tempC
CMP temp2
BCS +doneProxy
CMP userScreenByte1
BCS +checkPeripheralU
ADC userScreenByte1
CMP temp2
BCS +checkPeripheralU
JMP +doneProxy
+checkPeripheralU ;; check sides for l/r sight
LDA tempD
SBC userScreenByte2
CMP tempB
BCC +checkPeripheralD
JMP +doneProxy
+checkPeripheralD ;; check sides for l/r sight
LDA tempD
ADC userScreenByte2
CMP tempB
BCS +doAttack
JMP +doneProxy
gotodoneProxy:
JMP +doneProxy
+NPCfacesUp
LDA tempD
CMP tempB
BCC +doneProxy
CMP userScreenByte1
BCC +checkPeripheralL ;; if byte is higher than monster we can skip next check as we know player is in range of screen wrap
SBC userScreenByte1 ;;
CMP tempB
BCC +checkPeripheralL
JMP +doneProxy
+NPCfacesDown
LDA tempD
CMP tempB
BCS +doneProxy
CMP userScreenByte1
BCS +checkPeripheralL
ADC userScreenByte1
CMP tempB
BCS +checkPeripheralL
JMP +doneProxy
+checkPeripheralL ;; check sides for up/down sight
LDA tempC
SBC userScreenByte2
CMP temp2
BCC +checkPeripheralR
JMP +doneProxy
+checkPeripheralR ;; check sides for up/down sight
LDA tempC
ADC userScreenByte2
CMP temp2
BCS +doAttack
JMP +doneProxy
+doAttack
ChangeActionStep temp, #$05 ;; Action Step 5
+doneProxy
Now assign this script to one of your Monster action steps and set UserScreeByte1 to how far youd like your monsters forward vision to be, and set UserScreeByte2 to your monsters wide vision. These numbers are calculated in pixels and you will need to set them for each screen the easyAIProxy script will be used on. If you do not set either of the bytes then the script will not execute.
This script will work no matter where you place your monster, it will check for the screen edge and all fields of vision dependant on the direction that the enemy is facing! Youl also see theres some tile detection code added which was created by BucketMouse! With this you can create special tiles which if the player is stood on it will act as if the player is hiding from the NPC and will not be seen!
And thats it easy peasy!
Love from SHLIM
Last edited: