4.5.9 Give different weapons different damage!

Hi People! so iv been searching through everything to find how to give my melee attack 1 point of damge to an enemy and my projectile do 3! aaaand iv just made a solution!
this is in my metrovania game but im sure the process could be adapted and more than likely improved lol

anyways lets get into it.........

: note : im not using NPCs in my game so i will use the NPC monster flag for my melee attack

OK firstly i had to make 2 hurt monster scripts, i made mine monster_hurt and monster_hurt1.
Go ahead and make a duplicate of the monster hurt script in the common folder called monster_hurt1
then in your project settings add that script as monster_hurt1 and define it as SCR_HANDLE_MONSTER_HURT1

We the need to point to this in the banks. locate Bank1C and near the top you will fine the player hurt and monster hurt stuff. make it look like this to point to our new monster_hurt1 script when needed.

Code:
;; Game specific, common
doHandleHurtPlayer:
    .include SCR_HANDLE_PLAYER_HURT
    RTS
doHandleHurtMonster:
    .include SCR_HANDLE_MONSTER_HURT
    RTS
doHandleHurtMonster1:
    .include SCR_HANDLE_MONSTER_HURT1
    RTS


these can be then adjusted in the monster_hurt scripts in the COMMON folder to take however many hit points for the monsters you desire with your weapons. most moster scripts will have the necessary requirements to do this i think.
the code needed to adjust damge taken is below

Code:
    DEC Object_health,x
    LDA Object_health,x

if you want to take 3 damage then use 3 of those lines together.

Code:
   DEC Object_health,x
   LDA Object_health,x
   DEC Object_health,x
   LDA Object_health,x
   DEC Object_health,x
   LDA Object_health,x

this will override the health in the monster details if u have the health set at 3 which i do. but the melee will still take 3 hits to kill the monster

Next step is to set up object collisions to point to both scripts. so locate your doHandleObjectCollisions and find this code, mine starts at line 81 but look for the start of weapon collisions

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Check the type of object.
;;; If it is a weapon, it will check against monsters only.
        LDA Object_flags,x
        AND #%00000100
        BNE +isWeapon
            JMP +notPlayerWeapon
        +isWeapon

                LDX #$00
                loop_objectCollision:
                    CPX selfObject
                        BNE +notSelfObject
                            JMP +skipCollision
                        +notSelfObject
                LDA Object_status,x
                AND #%10000000
                BNE +isActive
                    JMP +skipCollision
                +isActive:
                LDA Object_flags,x
                AND #%00001000
                BNE isMonsterWeaponCol
                    JMP +notAmonsterWeaponCollision
                isMonsterWeaponCol:
                    JSR getOtherColBox
                    JSR doCompareBoundingBoxes
                        ;;; if they have collided, it is a 1
                        ;;; if not, it is a zero.
                        BEQ +skipCollision
                           
                            TXA
                            STA otherObject
                            ;; There was a collision between a monster and a weapon.
                            ;; weapon is self.
                            ;; monster is other.
                            DestroyObject
                            ;ChangeActionStep otherObject, #$07
                           
                           
                                JSR doHandleHurtMonster
                               
                            LDX selfObject
                            DestroyObject
                            JMP +done              
                    +skipCollision
                +notAmonsterWeaponCollision
                INX
                CPX #TOTAL_MAX_OBJECTS
                BEQ +lastCollisionForThisObject
                    JMP loop_objectCollision
            +lastCollisionForThisObject
            JMP +done
           
           
        +notPlayerWeapon

you need to make 2 versions of this section so do that first with a commented out line between them so you know which is which.

at the top of that we have our object flags. LDA #%10000000 is the NPC flag that iv re named to melee in the project settings
and LDA #% 00001000 is the projectile/player weapon flag so make sur eyou have checked what flag you are using and then the corresponding bytes on the scripts need to be changed accordingly.

heres my finished version of the object collisions below.

Code:
;;; Check the type of object.
;;; If it is a weapon, it will check against monsters only.
         LDA Object_flags,x
         AND #%10000000
         BNE +ismelee
         JMP +notmelee
            +ismelee

                LDX #$00
                loop_objectCollision:
                    CPX selfObject
                        BNE +notSelfObject
                            JMP +skipCollision
                        +notSelfObject
                LDA Object_status,x
                AND #%10000000
                BNE +isActive
                    JMP +skipCollision
                +isActive:
                LDA Object_flags,x
                AND #%00001000
                BNE isMonsterWeaponCol
                    JMP +notAmonsterWeaponCollision
                    isMonsterWeaponCol:
                    JSR getOtherColBox
                    JSR doCompareBoundingBoxes
                        ;;; if they have collided, it is a 1
                        ;;; if not, it is a zero.
                        BEQ +skipCollision
                           
                            TXA
                            STA otherObject
                            ;; There was a collision between a monster and a weapon.
                            ;; weapon is self.
                            ;; monster is other.
                            ;DestroyObject
                            ;ChangeActionStep otherObject, #$07
                           
                           
                            JSR doHandleHurtMonster
                               
                            LDX selfObject
                            DestroyObject
                            JMP +done              
                    +skipCollision
                +notAmonsterWeaponCollision
                INX
                CPX #TOTAL_MAX_OBJECTS
                BEQ +lastCollisionForThisObject
                JMP loop_objectCollision
            +lastCollisionForThisObject
            JMP +done        
           
            +notmelee
;************************************************************************************
    LDA Object_flags,x
    AND #%00000100
    BNE +isprojectile
    JMP +notprojectile
    +isprojectile

                LDX #$00
                loop_objectCollision1:
                    CPX selfObject
                        BNE +notSelfObject
                            JMP +skipCollision
                        +notSelfObject
                LDA Object_status,x
                AND #%10000000
                BNE +isActive
                    JMP +skipCollision
                +isActive:
                LDA Object_flags,x
                AND #%00001000
                BNE isMonsterWeaponCol1
                    JMP +notAmonsterWeaponCollision
                    isMonsterWeaponCol1:
                    JSR getOtherColBox
                    JSR doCompareBoundingBoxes
                        ;;; if they have collided, it is a 1
                        ;;; if not, it is a zero.
                        BEQ +skipCollision
                           
                            TXA
                            STA otherObject
                            ;; There was a collision between a monster and a weapon.
                            ;; weapon is self.
                            ;; monster is other.
                            ;DestroyObject
                            ;ChangeActionStep otherObject, #$07
                           
                           
                            JSR doHandleHurtMonster1
                               
                            LDX selfObject
                            DestroyObject
                            JMP +done              
                    +skipCollision
                +notAmonsterWeaponCollision
                INX
                CPX #TOTAL_MAX_OBJECTS
                BEQ +lastCollisionForThisObject
                JMP loop_objectCollision1
            +lastCollisionForThisObject
            JMP +done        
           
            +notprojectile

the labels are the pointers to which routine is for what attack - melee and notmelee, projectile and notprojectile. The doHandleHurtMonster and doHandleHurtMonster1 point to which script you use for what health for each attack!

and thats it.... i think

feels good to give back to the community haha

thanks to everyone whos helped me so far :)
 
Last edited:

vanderblade

Active member
Since I was thinking about this today, couldn't you just add some checks in the monsterHurt script for specific weapon objects and then, if it's a bat versus a crowbar or whatever, take more life off the monster that way, without all of the extra stuff you're doing?
 

offparkway

Active member
Since I was thinking about this today, couldn't you just add some checks in the monsterHurt script for specific weapon objects and then, if it's a bat versus a crowbar or whatever, take more life off the monster that way, without all of the extra stuff you're doing?
I was looking at doing this, but I’m not sure how that check would go. Like, if my stronger weapon is object 08, what would the check for 08 look like?
 

offparkway

Active member
…I’ve tried creating an action step flag for this. If the box is ticked during action step 03, it deals double damage. It sort of works, but it has weird results (like making my action step 02 also deal double damage, even if the box isn’t ticked there). Right track?
 

Kanbei85

Member
I figured out how to implement the strength defense system. Check out the tutorial I posted:

 
Top Bottom