• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Problem with keeping Items

Status
Not open for further replies.
Level 2
Joined
Feb 18, 2008
Messages
21
Ok, so I have a problem with Hippogryph Riders.

I have 3 custom units, a hero Archer with a 2 slot inventory, a Hippogryph Hero with no inventory and a Hippogryph Rider with a 2 slot inventory.

I had everything working as I want it, except when I mount I want any items from the Archer to transfer the the Hippogryph Rider and vice versa when I dismount. At the moment both items simply drop to the floor. I did have it working briefly but I changed something and now it isn't.

I originally wanted to have the items transfer from inventory to inventory properly, but I lack the technical knowhow to accomplish that atm, so I was trying to simply grab them off the ground around the Archer (or Rider) and put them back into the inventory straight away.

If someone can fix my triggers (or find a much nicer way than my hacky version, JASS accepted, but I don't really know much about it) then that would be totally awesome :)

  • Mount
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • ((Unit-type of (Casting unit)) Equal to Archer (new)) or ((Unit-type of (Casting unit)) Equal to Hippogryph (new))
    • Actions
      • Set Player = (Owner of (Casting unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player controller) Equal to User
          • ((Ability being cast) Equal to Mount Hippogryph (new)) or ((Ability being cast) Equal to Pick up Archer (new))
        • Then - Actions
          • Set Hippogryph = (Region centered at (Position of (Casting unit)) with size (256.00, 256.00))
          • Unit Group - Add all units of (Units in Hippogryph owned by Player) to TempGroup
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempUnit = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of TempUnit) Equal to Hippogryph Rider (new)
                  • (Hero experience of TempUnit) Equal to 0
                • Then - Actions
                  • Hero - Set TempUnit experience to (((Hero experience of (Casting unit)) + (Hero experience of (Target unit of ability being cast))) / 2), Hide level-up graphics
                  • Item - Pick every item in Hippogryph and do (Actions)
                    • Loop - Actions
                      • Hero - Create (Item-type of (Picked item)) and give it to TempUnit
                      • Item - Remove (Picked item)
                • Else - Actions
        • Else - Actions
  • Dismount
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • (Unit-type of (Casting unit)) Equal to Hippogryph Rider (new)
    • Actions
      • Set Player = (Owner of (Casting unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player controller) Equal to User
          • (Ability being cast) Equal to Dismount (new)
        • Then - Actions
          • Set Hippogryph = (Region centered at (Position of (Casting unit)) with size (256.00, 256.00))
          • Unit Group - Add all units of (Units in Hippogryph owned by Player) to TempGroup
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempUnit = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Unit-type of TempUnit) Equal to Archer (new)) or ((Unit-type of TempUnit) Equal to Hippogryph (new))
                  • (Hero experience of TempUnit) Equal to 0
                • Then - Actions
                  • Hero - Set (Picked unit) experience to (Hero experience of (Casting unit)), Hide level-up graphics
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of TempUnit) Equal to Archer (new)
                    • Then - Actions
                      • Item - Pick every item in Hippogryph and do (Actions)
                        • Loop - Actions
                          • Hero - Create (Item-type of (Picked item)) and give it to TempUnit
                          • Item - Remove (Picked item)
                    • Else - Actions
                • Else - Actions
        • Else - Actions
 
Level 6
Joined
Feb 12, 2008
Messages
207
ok 1st at all... The event "Unit - A unit Stops casting an ability" i think it will only be triggered if the unit is ordered to STOP while is casting the ability... i would recommend to use "Unit - A unit Finishes casting an ability"
and as the Mounted Hippogryph is a newly created unit... you would have to wait at least 0.01 seconds... what is the time that takes to create the new unit and remove the other two old units... at the time you are calling the "temp_unit" variable... that unis doesnt exists yet...

i think you could make 2 triggers... when the unit STARTS casting the ability... just save the item type of every slot in the archer and the position of the archer using variables... and when the unit FINISHES casting it... wait like 0.25 seconds, and then create those item types in the hippogryph (wich you can call taking it from | random unit from unit group - matching (unit type of matching unit = mounted hippogryph))

i think you could figure out how to give the experience too :)

anyway... if i got some time for tomorrow i could make the trigger and test it for you...

hope i helped you ^^
 
Last edited:
Level 2
Joined
Feb 18, 2008
Messages
21
EDIT: Hey thanks for the help KaiserG, didn't see your post before I posted...my browser must've screwed up the caching or something. Anyway, when I first started on the triggers, I tested for all events ie, starts/finishes channeling/casting. The one that got triggered with Mount/Dismount was Stops Casting, I don't know why because to me Finishes Casting would have been more logical. It actually fires off 4 events in the following order:

A unit starts casting an ability (unit seeks partner)
A unit starts channeling an ability
A unit starts the effect of the ability
A unit stops casting (actual mount/dismount)

The first 3 events are pretty much fired simultaneously, so I have no idea what does what.

The stops casting ability is I think fired after the merge, so the new unit(s) are already created at that point, however (casting unit) is still viable as well. The bulk of the trigger worked, it just wasn't registering the items for some reason. I added in the tempUnit variable to test that it was actually selecting the right unit, as it turned out it was unnecessary anyway.

Anyway thanks for your help :)

******

Hmm, after poking around a bit more, I found a solution...it still could have problems (ie. two hippogryphs/archers with different items merge at similar times, screwing up the item array) but the problem is minimal since in most games a.) items will be given to straight heroes and b.) what are the odds that more than one hippogryph with items will merge at the same time.

Anyway, my solution was to add another trigger as below:

  • StartAbility
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • HippoCheck Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Casting unit)) Equal to Archer (new)
          • (Unit-type of (Casting unit)) Equal to Hippogryph (new)
          • (Unit-type of (Casting unit)) Equal to Hippogryph Rider (new)
      • Or - Any (Conditions) are true
        • Conditions
          • (Ability being cast) Equal to Dismount (new)
          • (Ability being cast) Equal to Pick up Archer (new)
          • (Ability being cast) Equal to Mount Hippogryph (new)
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Dismount (new)
        • Then - Actions
          • -------- TempUnit should always be HippogryphRider --------
          • Set TempUnit = (Casting unit)
        • Else - Actions
          • -------- TempUnit should always be Archer --------
          • If ((Ability being cast) Equal to Mount Hippogryph (new)) then do (Set TempUnit = (Casting unit)) else do (Set TempUnit = (Target unit of ability being cast))
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set HeroItems[((Integer A) - 1)] = (Item-type of (Item carried by TempUnit in slot (Integer A)))
          • Item - Remove (Item carried by TempUnit in slot (Integer A))
      • Set HippoCheck = False
  • EndDismount
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • (Unit-type of (Casting unit)) Equal to Hippogryph Rider (new)
    • Actions
      • Set Player = (Owner of (Casting unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player controller) Equal to User
          • (Ability being cast) Equal to Dismount (new)
        • Then - Actions
          • Set Hippogryph = (Region centered at (Position of (Casting unit)) with size (256.00, 256.00))
          • Unit Group - Add all units of (Units in Hippogryph owned by Player) to TempGroup
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Unit-type of (Picked unit)) Equal to Archer (new)) or ((Unit-type of (Picked unit)) Equal to Hippogryph (new))
                  • (Hero experience of (Picked unit)) Equal to 0
                • Then - Actions
                  • Hero - Set (Picked unit) experience to (Hero experience of (Casting unit)), Hide level-up graphics
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Unit-type of (Picked unit)) Equal to Archer (new)
                    • Then - Actions
                      • For each (Integer A) from 0 to 5, do (Hero - Create HeroItems[(Integer A)] and give it to (Picked unit))
                    • Else - Actions
                • Else - Actions
        • Else - Actions
      • Set HippoCheck = True
  • EndMount
    • Events
      • Unit - A unit Stops casting an ability
    • Conditions
      • ((Unit-type of (Casting unit)) Equal to Archer (new)) or ((Unit-type of (Casting unit)) Equal to Hippogryph (new))
    • Actions
      • Set Player = (Owner of (Casting unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player controller) Equal to User
          • ((Ability being cast) Equal to Mount Hippogryph (new)) or ((Ability being cast) Equal to Pick up Archer (new))
        • Then - Actions
          • Set Hippogryph = (Region centered at (Position of (Casting unit)) with size (256.00, 256.00))
          • Unit Group - Add all units of (Units in Hippogryph owned by Player) to TempGroup
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Hippogryph Rider (new)
                  • (Hero experience of (Picked unit)) Equal to 0
                • Then - Actions
                  • Hero - Set (Picked unit) experience to (((Hero experience of (Casting unit)) + (Hero experience of (Target unit of ability being cast))) / 2), Hide level-up graphics
                  • For each (Integer A) from 0 to 5, do (Hero - Create HeroItems[(Integer A)] and give it to (Picked unit))
                • Else - Actions
        • Else - Actions
      • Set HippoCheck = True
 
Level 6
Joined
Feb 12, 2008
Messages
207
ya, you used a trigger for the starting and another for the finishing as i thought :)
and did that worked?

Hmm, after poking around a bit more, I found a solution...it still could have problems (ie. two hippogryphs/archers with different items merge at similar times, screwing up the item array) but the problem is minimal since in most games a.) items will be given to straight heroes and b.) what are the odds that more than one hippogryph with items will merge at the same time.
You can be sure of the point b)..
1) Triggers calculate a minimum of 0.01 seconds.. so, you should have to mount 2 hippogryphs in the same fraction of second to be at "the same time"
2) Even if you do it at the exact same time... triggers run sepparated... in less than a fraction of second, the trigger is actioned (at least you use a wait x seconds action, and in that time you change the variables) so if more than one unit starts an ability, they will have their own trigger for each.. thats why you cant screw so easily the triggers :)
 
Status
Not open for further replies.
Top