• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] A bug in my weapon system.

Status
Not open for further replies.

Deleted member 177737

D

Deleted member 177737

Hey,

I just began making a DnD (Dungeons & Dragons) style combat-modifier system where if you pick up certain items it gets added through a formula to decide how much damage you deal.
Now the problem I'm facing is with the 3 triggers that deal with stopping the player from equipping 2 weapons at the same time, and trigger that deals with equipping, and the trigger that deals with unequipping.

The Bug:
When I go to pickup the Rusty Axe or the Rusty Sword the trigger that prevents picking up 2 weapons turns on somehow which is causing me to be unable to pick up either of the items to test the other triggers.

(The triggers "Weapon UnEquip" and "Weapon Stop Equip" have been initally turned off)

  • Weapon Equip
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Hero manipulating item) Equal to Unit_Hero
    • Actions
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • -------- Damage +3 --------
          • Set Damage_WeaponDamageModifier = 3
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • -------- Damage +6 --------
              • Set Damage_WeaponDamageModifier = 6
            • Else - Actions
      • Trigger - Turn on Weapon UnEquip <gen>
      • Trigger - Turn on Weapon Stop Equip <gen>
      • Trigger - Turn off (This trigger)
  • Weapon UnEquip
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Hero manipulating item) Equal to Unit_Hero
    • Actions
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • Set Damage_WeaponDamageModifier = 0
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • Set Damage_WeaponDamageModifier = 0
            • Else - Actions
      • Trigger - Turn on Weapon Equip <gen>
      • Trigger - Turn off Weapon Stop Equip <gen>
      • Trigger - Turn off (This trigger)
  • Weapon Stop Equip
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Hero manipulating item) Equal to Unit_Hero
    • Actions
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • Item - Move (Item being manipulated) to (Position of (Hero manipulating item))
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • Item - Move (Item being manipulated) to (Position of (Hero manipulating item))
            • Else - Actions
      • Game - Display to (All players) the text: You already have a ...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
A a rough guess, it is probably due to how WC3 dispatches events to the JASS interpreter. The first trigger turns on a trigger with the exact same event as it, which results in it being added to the observer notification list. After the trigger finishes, the game then moves on to aleart the Weapon Stop Equip trigger as it runs on the same event. As the logic is not designed for this, the system bugs. I believe the event fires before the item acutally enters the inventory so that is why the second trigger does not run.

There are 2 solutions.
1. Recommended.
Try merging both Weapon Equip and Weapon Stop Equip triggers to run from the same event (adding tests to decide which to run). A simple if then else statement with a single global boolean would be all it takes to merge them and fix this bug.

2. Catch the exception state.
You set a boolean global represeting that the top trigger run and the bottom one will fire. You then catch this state in the bottom one (as you have the boolean value to tell when it is present) and simply turn the state off. If it is not this exception state you then run code normally in the bottom trigger.
 

Deleted member 177737

D

Deleted member 177737

A a rough guess, it is probably due to how WC3 dispatches events to the JASS interpreter. The first trigger turns on a trigger with the exact same event as it, which results in it being added to the observer notification list. After the trigger finishes, the game then moves on to aleart the Weapon Stop Equip trigger as it runs on the same event. As the logic is not designed for this, the system bugs. I believe the event fires before the item acutally enters the inventory so that is why the second trigger does not run.

There are 2 solutions.
1. Recommended.
Try merging both Weapon Equip and Weapon Stop Equip triggers to run from the same event (adding tests to decide which to run). A simple if then else statement with a single global boolean would be all it takes to merge them and fix this bug.

2. Catch the exception state.
You set a boolean global represeting that the top trigger run and the bottom one will fire. You then catch this state in the bottom one (as you have the boolean value to tell when it is present) and simply turn the state off. If it is not this exception state you then run code normally in the bottom trigger.

I did what you said for #1 because its the only one of the two I could understand (I'm not very good with the proper words when triggering).
But after inserting a test to check if it should run certain things by using either a 0 or a 1 integer, I still get the same error.

Here are all the modified triggers, including the initialization trigger for all variables (used to set the 0 to start):

  • Combat Initilization
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set Unit_Hero = Footie Fred 0000 <gen>
      • Set Damage_BaseDamage = ((Level of Unit_Hero) x 3)
      • Set Damage_WeaponDamageModifier = 0
      • Set Damage_WeaponSkillModifier = 0
      • Set Damage = (Damage_BaseDamage + (Damage_WeaponDamageModifier + Damage_WeaponSkillModifier))
      • Set WeaponSkill_ExperienceCheck = (WeaponSkill_ExperienceCheck x ((Level of Unit_Hero) + 1))
      • Set WeaponSkill = 0
      • Set Weapon_YesOrNo = 0
  • Weapon Equip
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Hero manipulating item) Equal to Unit_Hero
    • Actions
      • -------- Equip --------
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Weapon_YesOrNo Equal to 0
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • -------- Damage +3 --------
          • Set Damage_WeaponDamageModifier = 3
          • Set Weapon_YesOrNo = 1
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Weapon_YesOrNo Equal to 0
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • -------- Damage +6 --------
              • Set Damage_WeaponDamageModifier = 6
              • Set Weapon_YesOrNo = 1
            • Else - Actions
      • -------- Stop Equip --------
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Weapon_YesOrNo Equal to 1
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • Item - Move (Item being manipulated) to (Position of (Hero manipulating item))
          • Game - Display to (All players) the text: You already have a ...
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Weapon_YesOrNo Equal to 1
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • Item - Move (Item being manipulated) to (Position of (Hero manipulating item))
              • Game - Display to (All players) the text: You already have a ...
            • Else - Actions
  • Weapon UnEquip
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Hero manipulating item) Equal to Unit_Hero
    • Actions
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Weapon_YesOrNo Equal to 1
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • Set Damage_WeaponDamageModifier = 0
          • Set Weapon_YesOrNo = 0
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Weapon_YesOrNo Equal to 1
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • Set Damage_WeaponDamageModifier = 0
              • Set Weapon_YesOrNo = 0
            • Else - Actions
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Try this:
  • Weapon Equip
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Hero manipulating item) Equal to Unit_Hero
    • Actions
      • -------- Equip --------
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Weapon_YesOrNo Equal to 0
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • -------- Damage +3 --------
          • Set Damage_WeaponDamageModifier = 3
          • Set Weapon_YesOrNo = 1
          • Skip remaining actions
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Weapon_YesOrNo Equal to 0
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • -------- Damage +6 --------
              • Set Damage_WeaponDamageModifier = 6
              • Set Weapon_YesOrNo = 1
              • Skip remaining actions
            • Else - Actions
      • -------- Stop Equip --------
      • -------- Rusty Axe --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Weapon_YesOrNo Equal to 1
          • (Item-type of (Item being manipulated)) Equal to Rusty Axe
        • Then - Actions
          • Item - Move (Item being manipulated) to (Position of (Hero manipulating item))
          • Game - Display to (All players) the text: You already have a ...
        • Else - Actions
          • -------- Rusty Sword --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Weapon_YesOrNo Equal to 1
              • (Item-type of (Item being manipulated)) Equal to Rusty Sword
            • Then - Actions
              • Item - Move (Item being manipulated) to (Position of (Hero manipulating item))
              • Game - Display to (All players) the text: You already have a ...
            • Else - Actions
I'd use a hashtable to init item type thingies and to save the status of having a weapon equipped.
 

Deleted member 177737

D

Deleted member 177737

Thanks, it works as intended now. I'll try to figure out how to use hashtables eventually.
 
Status
Not open for further replies.
Top