[Trigger] Changing the attack range for the same unit

Level 8
Joined
Jul 22, 2021
Messages
83
Hello,

I'm trying to create a system where the hero can carry only one weapon at a time (the weapon's item class is campaign). When you try to pick more than one weapon into the inventory, the weapon is moved to the backpack or to the ground when the backpack is full.

Whatever weapon the hero has in the inventory determines its abilities, skin, attack range, and projectile art.

I do not want to use a metamorphosis/bear form kind of spell. I've found a similar thread here with a solution: https://www.hiveworkshop.com/threads/problems-of-switching-ranged-to-melee-mode.359003/ I basically copied the triggers and added my own tweaks.

However, my problem is that everything seems to be working except for the attack range. When I change stances from none to melee and then to ranged, I still attack melee, and when I pick ranged stance first, then change to melee, I can attack only melee.
So far, I've noticed that these weird bugs occur only when I pick up a melee weapon, which is kinda weird because "no weapon" and melee weapon stances are basically the same. Meaning, when I have no weapon in inventory, then my attacks are close range, as intended -- and after that, when I pick a melee weapon and change it to a ranged/wand weapon later, then my attacks are not ranged...
I hope I expressed myself clearly enough for you to understand.

I tried many different things, like adding/removing wait commands, removing set skin triggers, etc. But nothing seems to make any difference as the issue persists. I'm clueless.
Below are all triggers related to this system.

--- EDIT ---
I tried Lua custom scripts, but nothing helped.

For Melee Stance:
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 0, -600.0)
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1, -600.0)
For Ranged Stance:
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 0, 600.0)
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1, 600.0)

--- EDIT 2 ---
I've received help on Hive's Discord channel, thanks to user named Arxos.

I actually had to use the following (weird) formula:
BlzSetUnitWeaponRealField(unit, UNIT_WEAPON_RF_ATTACK_RANGE, 1, desiredRange - BlzGetUnitWeaponRealField(unit, UNIT_WEAPON_RF_ATTACK_RANGE, 0) + BlzGetUnitWeaponRealField(unit, UNIT_WEAPON_RF_ATTACK_RANGE, 1))
Which translates into the below codes for my own use case:
- Melee
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1, -600 - BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 0) + BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1))
- Ranged:
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1, 600 - BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 0) + BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1))
- Wand
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1, 600 - BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 0) + BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1))
- No weapon
BlzSetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1, 0 - BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 0) + BlzGetUnitWeaponRealField(udg_HERO, UNIT_WEAPON_RF_ATTACK_RANGE, 1))

I'd probably never get there on my own :ogre_rage:
PROBLEM SOLVED

  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Trigger - Turn off (This trigger)
      • Set VariableSet HERO = Gnoll Outcast 0001 <gen>
      • Set VariableSet HEROname = Outcast
      • Hero - Set Name of HERO to HEROname
      • Camera - Pan camera for Player 1 (Red) to (Position of HERO) over 0.00 seconds
      • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: -600.00
      • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: -600.00
      • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:0 to Value: <Empty String>
      • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:1 to Value: <Empty String>
      • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: 0.00
      • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:1 to Value: 0.00
      • -------- Backpack --------
      • Unit - Create 1 Backpack for Player 1 (Red) at (Position of HERO) facing Default building facing degrees
      • Set VariableSet Backpack = (Last created unit)
      • Trigger - Turn on Backpack Move <gen>
  • Weapon Acquired
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Campaign
    • Actions
      • Set VariableSet WeaponCount = 0
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-class of (Item carried by HERO in slot (Integer A))) Equal to Campaign
            • Then - Actions
              • Set VariableSet WeaponCount = (WeaponCount + 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WeaponCount Greater than 1
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of items carried by Backpack) Equal to 2
            • Then - Actions
              • Set VariableSet WeaponDrop = (Position of HERO)
              • Item - Move (Item being manipulated) to WeaponDrop
              • Custom script: RemoveLocation(udg_WeaponDrop)
              • Game - Display to (All players) the text: Cannot carry more t...
            • Else - Actions
              • Hero - Give (Item being manipulated) to Backpack
        • Else - Actions
      • Trigger - Run WeaponType Check <gen> (checking conditions)
  • Weapon Dropped
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Triggering unit) Equal to HERO
          • (Item-class of (Item being manipulated)) Equal to Campaign
    • Actions
      • Set VariableSet WeaponCount = (WeaponCount - 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WeaponCount Equal to 0
        • Then - Actions
          • -------- remove RANGED spells --------
          • Unit - Remove Fan of Knives from HERO
          • -------- remove WAND spells --------
          • Unit - Remove Entangling Roots from HERO
          • -------- remove MELEE spells --------
          • Unit - Remove Bash from HERO
          • Game - Display to (All players) the text: STANCE: none
          • -------- none --------
          • Unit - Remove Melee Stance from HERO
          • Unit - Remove Ranged Stance from HERO
          • Unit - Remove Wand Stance from HERO
          • Unit - Set Unit Skin of HERO to (Skin ID of Gnoll Scout 0130 <gen>)
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: -600.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: -600.00
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:0 to Value: <Empty String>
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:1 to Value: <Empty String>
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: 0.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:1 to Value: 0.00
        • Else - Actions
  • WeaponType Check
    • Events
    • Conditions
      • WeaponCount Equal to 1
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-class of (Item carried by HERO in slot (Integer A))) Equal to Campaign
            • Then - Actions
              • Set VariableSet WeaponType = (Item-type of (Item carried by HERO in slot (Integer A)))
              • Game - Display to (All players) the text: Weapon Type Set
            • Else - Actions
      • -------- MELEE --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WeaponType Equal to Melee Weapon
        • Then - Actions
          • -------- remove RANGED spells --------
          • Unit - Remove Fan of Knives from HERO
          • -------- remove WAND spells --------
          • Unit - Remove Entangling Roots from HERO
          • -------- add MELEE spells --------
          • Unit - Add Bash to HERO
          • Game - Display to (All players) the text: STANCE: melee
          • -------- MELEE --------
          • Unit - Remove Wand Stance from HERO
          • Unit - Remove Ranged Stance from HERO
          • Unit - Add Melee Stance to HERO
          • Unit - Set Unit Skin of HERO to (Skin ID of Gnoll Warrior 0131 <gen>)
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:0 to Value: <Empty String>
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:1 to Value: <Empty String>
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: 0.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:1 to Value: 0.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: -600.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: -600.00
        • Else - Actions
      • -------- RANGED --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WeaponType Equal to Ranged Weapon
        • Then - Actions
          • -------- remove MELEE spells --------
          • Unit - Remove Bash from HERO
          • -------- remove WAND spells --------
          • Unit - Remove Entangling Roots from HERO
          • -------- add RANGED spells --------
          • Unit - Add Fan of Knives to HERO
          • Game - Display to (All players) the text: STANCE: ranged
          • -------- RANGED --------
          • Unit - Remove Wand Stance from HERO
          • Unit - Remove Melee Stance from HERO
          • Unit - Add Ranged Stance to HERO
          • Unit - Set Unit Skin of HERO to (Skin ID of Gnoll Huntsman 0135 <gen>)
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:0 to Value: Abilities\Weapons\Dryadmissile\Dryadmissile.mdl
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:1 to Value: Abilities\Weapons\Dryadmissile\Dryadmissile.mdl
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: 900.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:1 to Value: 900.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: 600.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: 600.00
        • Else - Actions
      • -------- WAND --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WeaponType Equal to Wand Weapon
        • Then - Actions
          • -------- remove MELEE spells --------
          • Unit - Remove Bash from HERO
          • -------- remove RANGED spells --------
          • Unit - Remove Fan of Knives from HERO
          • -------- add WAND spells --------
          • Unit - Add Entangling Roots to HERO
          • Game - Display to (All players) the text: STANCE: wand
          • -------- WAND --------
          • Unit - Remove Melee Stance from HERO
          • Unit - Remove Ranged Stance from HERO
          • Unit - Add Wand Stance to HERO
          • Unit - Set Unit Skin of HERO to (Skin ID of Gnoll Warden 0124 <gen>)
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:0 to Value: Abilities\Weapons\FarseerMissile\FarseerMissile.mdl
          • Unit - Set Unit: HERO's Weapon String Field: Attack Projectile Art ('ua1m')at Index:1 to Value: Abilities\Weapons\FarseerMissile\FarseerMissile.mdl
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:0 to Value: 900.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Projectile Speed ('ua1z')at Index:1 to Value: 900.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: 600.00
          • Unit - Set Unit: HERO's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: 600.00
        • Else - Actions
1776106552071.png
1776106578724.png
 
Last edited:
Back
Top