Weapon check/destroy weapon 4.5.9 (SOLVED)

baardbi

Well-known member
The script I had was not so great. This method is better. It's actually what you suggested yourself. Destroy the sword when the player is hurt. However, this is not straight forward. The sword object can have a different object ID every time it is created. So we need to make sure we have a way of addressing the sword object. So do this:

1. Make a new User Variable called swordObject

2. In the input script ChangeToAttack_AdventureBase.asm you need to add something below these lines:

CreateObject tempA, tempB, tempC, #WEAPON_DOWN_STATE, currentNametable
CreateObject tempA, tempB, tempC, #WEAPON_RIGHT_STATE, currentNametable
CreateObject tempA, tempB, tempC, #WEAPON_UP_STATE, currentNametable
CreateObject tempA, tempB, tempC, #WEAPON_LEFT_STATE, currentNametable


So it should look like this:

CreateObject tempA, tempB, tempC, #WEAPON_DOWN_STATE, currentNametable
STX swordObject

CreateObject tempA, tempB, tempC, #WEAPON_RIGHT_STATE, currentNametable
STX swordObject

CreateObject tempA, tempB, tempC, #WEAPON_UP_STATE, currentNametable
STX swordObject

CreateObject tempA, tempB, tempC, #WEAPON_LEFT_STATE, currentNametable
STX swordObject

You need to hunt through the file to find those lines and add STX swordObject below. Don't add STX swordObject for the last CreateObject line. That's the projectile weapon.

3. Then finally in the playerHurt file add this just before +notAlreadyInHurtState :

TXA
PHA
LDX swordObject
DestroyObject
PLA
TAX

Now the sword object should be destroyed when the player is hurt.
 

dale_coop

Moderator
Staff member
Another one...
In your Handle Hurt Player, just after the "CanHurtPlayer" line, add that code:
Code:
    ;; Destroy the weapon object:
    TXA
    PHA
    LDX #$00
    -loopWeapon:
        LDA Object_type,x
        CMP #$01  ;; the weapon object ID
        BNE +notWeapon
            DestroyObject
        +notWeapon:
        INX
        CPX #TOTAL_MAX_OBJECTS
        BNE -loopWeapon   
    PLA
    TAX
 

Dietz33

Member
The script I had was not so great. This method is better. It's actually what you suggested yourself. Destroy the sword when the player is hurt. However, this is not straight forward. The sword object can have a different object ID every time it is created. So we need to make sure we have a way of addressing the sword object. So do this:

1. Make a new User Variable called swordObject

2. In the input script ChangeToAttack_AdventureBase.asm you need to add something below these lines:

CreateObject tempA, tempB, tempC, #WEAPON_DOWN_STATE, currentNametable
CreateObject tempA, tempB, tempC, #WEAPON_RIGHT_STATE, currentNametable
CreateObject tempA, tempB, tempC, #WEAPON_UP_STATE, currentNametable
CreateObject tempA, tempB, tempC, #WEAPON_LEFT_STATE, currentNametable


So it should look like this:

CreateObject tempA, tempB, tempC, #WEAPON_DOWN_STATE, currentNametable
STX swordObject

CreateObject tempA, tempB, tempC, #WEAPON_RIGHT_STATE, currentNametable
STX swordObject

CreateObject tempA, tempB, tempC, #WEAPON_UP_STATE, currentNametable
STX swordObject

CreateObject tempA, tempB, tempC, #WEAPON_LEFT_STATE, currentNametable
STX swordObject

You need to hunt through the file to find those lines and add STX swordObject below. Don't add STX swordObject for the last CreateObject line. That's the projectile weapon.

3. Then finally in the playerHurt file add this just before +notAlreadyInHurtState :



Now the sword object should be destroyed when the player is hurt.
i have to try dales thing first ,.. seems easier lol .. but thank you . I encountered another problem though .. your input scripts make it so that when a player weapon is on screen we can't move, thats great for the sword but when i shoot a projectile i can't move till it hits a solid , which is a bit annoying .. any workarround ?
I tried to do it with monsterbits to check if it is a projectile or sword but thats new territory for me ^^
 

Dietz33

Member
Another one...
In your Handle Hurt Player, just after the "CanHurtPlayer" line, add that code:
Code:
    ;; Destroy the weapon object:
    TXA
    PHA
    LDX #$00
    -loopWeapon:
        LDA Object_type,x
        CMP #$01  ;; the weapon object ID
        BNE +notWeapon
            DestroyObject
        +notWeapon:
        INX
        CPX #TOTAL_MAX_OBJECTS
        BNE -loopWeapon  
    PLA
    TAX
it worlks , strangley i cant manage to make it work for hurt tiles
 

baardbi

Well-known member
i have to try dales thing first ,.. seems easier lol .. but thank you . I encountered another problem though .. your input scripts make it so that when a player weapon is on screen we can't move, thats great for the sword but when i shoot a projectile i can't move till it hits a solid , which is a bit annoying .. any workarround ?
I tried to do it with monsterbits to check if it is a projectile or sword but thats new territory for me ^^
Yes. I have a fix. Change the first part of the input scripts to CountObjectType instead of CountObjects. I just posted a tutorial about making a new macro called CountObjectType (it's not default in NESmaker). You need to follow that tutorial first (very simple).

;If the sword object is on-screen we can't move
CountObjectType #1 ;;; Sword object
BEQ +
RTS
+

 

Dietz33

Member
Yes. I have a fix. Change the first part of the input scripts to CountObjectType instead of CountObjects. I just posted a tutorial about making a new macro called CountObjectType (it's not default in NESmaker). You need to follow that tutorial first (very simple).



 

Attachments

  • fuck.png
    fuck.png
    3.5 KB · Views: 8
Top Bottom