• 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.
  • Vote for the theme of Hive's HD Modeling Contest #7! Click here to vote! - Please only vote if you plan on participating❗️

[Trigger] Hero Revive System

Status
Not open for further replies.
Level 19
Joined
Apr 21, 2013
Messages
1,194
So I created a hero revival system which drops an item on the ground(hero death location) unless another player takes the item and gets into a region(hospital) the dead hero will not respawn. If the item has been brought to the hospital the item will be removed from the inventory of the carrying hero. But I'm having some kind of bugs. It seemed like it worked but it turned out it had some issues I checked this over and over again but can't find the mistake...

  • ItemUponDeath
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Simple Adventurer
          • (Unit-type of (Triggering unit)) Equal to Simple Adventurer Acher
          • (Unit-type of (Triggering unit)) Equal to Simple Adventurer(Mage)
    • Actions
      • Set DyingHeros[DyingHeroCount] = (Triggering unit)
      • Set DyingHeroCount = (DyingHeroCount + 1)
      • Item - Create Ashes at (Position of (Triggering unit))
  • HospitalArea
    • Events
      • Unit - A unit enters Hospital <gen>
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Simple Adventurer
          • (Unit-type of (Triggering unit)) Equal to Simple Adventurer Acher
          • (Unit-type of (Triggering unit)) Equal to Simple Adventurer(Mage)
    • Actions
      • For each (Integer A) from 1 to 7, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to Ashes
            • Then - Actions
              • Hero - Instantly revive DyingHeros[DyingHeroCount2] at (Center of Hospital <gen>), Show revival graphics
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DyingHeroCount Equal to 0
                • Then - Actions
                • Else - Actions
                  • Set DyingHeroCount = (DyingHeroCount - 1)
              • Set DyingHeroCount2 = (DyingHeroCount2 + 1)
              • Item - Remove (Item carried by (Triggering unit) in slot (Integer A))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Integer A) Greater than 6
                • Then - Actions
                  • Set DyingHeroCount2 = 0
                • Else - Actions
 
Level 25
Joined
May 11, 2007
Messages
4,650
Why do you check inventory slots 1 to 7 when you can only have 6 slots in an inventory? :)

Your first trigger leaks a location #LeakFanatic

I just feel like mr ZBithe says, use a custom value for the item you create.

Like:
  • Events:
  • A unit dies
  • Conditions: unit is a hero
  • Actions: set tempPoint1 = unit position of triggering unit
  • create 1 ashes at temPoint1
  • set dyingHero = dyingHero + 1
  • set custom value or whatever of item1 to dyingHero
  • set deadHero[dyingHero] = triggering unit
  • remove tempPoint1
  • Events: A unit enters hospital
  • Conditions: item carried by triggering unit in slot 1-6 == ashes
  • Actions: remove ashes from triggering unit
  • set tempPoint1 = position of triggering unit
  • hero - revive instantly deadHero[custom value of item carried by hero] at tempPoint1
  • remove tempPoint1
pseudo code and whatnot but it should work with some editing.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,266
When you create the ashes you add them to an array list. The array list uses parallel arrays to map ash item with the unit to revive.

When a unit enters the region which has an inventory and if the array list has more than 1 entry then you check if it has any ashes on it. This is done by iterating through all elements in the array list and checking if the unit has the corresponding ashes item. If it does then revive the corresponding unit where you feel fit.

Although the complexity of this is bad (O(n) scaling) it makes no difference as long as the number of ashes is reasonable (even 50 should not be a problem).
 
Level 19
Joined
Apr 21, 2013
Messages
1,194
Why do you check inventory slots 1 to 7 when you can only have 6 slots in an inventory? :)

Your first trigger leaks a location #LeakFanatic

I just feel like mr ZBithe says, use a custom value for the item you create.

Like:
  • Events:
  • A unit dies
  • Conditions: unit is a hero
  • Actions: set tempPoint1 = unit position of triggering unit
  • create 1 ashes at temPoint1
  • set dyingHero = dyingHero + 1
  • set custom value or whatever of item1 to dyingHero
  • set deadHero[dyingHero] = triggering unit
  • remove tempPoint1
  • Events: A unit enters hospital
  • Conditions: item carried by triggering unit in slot 1-6 == ashes
  • Actions: remove ashes from triggering unit
  • set tempPoint1 = position of triggering unit
  • hero - revive instantly deadHero[custom value of item carried by hero] at tempPoint1
  • remove tempPoint1
pseudo code and whatnot but it should work with some editing.

I don't know how custom value of items work but I'll take a look at tomorrow evening.

Although the complexity of this is bad (O(n) scaling) it makes no difference as long as the number of ashes is reasonable (even 50 should not be a problem).

I know I couldn't find a good loop for the checking :( Btw you surely know good stuff I wouldn't think that I would hear any time complexity here :D I'm studying computer science and I know these O(N) or log2(N) but I didn't think like that in GUI triggers :D
 
Status
Not open for further replies.
Top