• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[General] Can't spin a unit

Status
Not open for further replies.

sentrywiz

S

sentrywiz

Hi. I'm trying to spin a unit from 0 - 45 degrees in a loop. I have all the stuff, and the trigger works for a unit that is already created. But for a new unit that is being created via trigger, it doesn't work and I can't see why.

Triggers:

  • Spawn Item
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hammer Spawn <gen> contains hammer_created) Not equal to True
          • hammer_created Equal to No unit
        • Then - Actions
          • Set item_loc = (Center of Hammer Spawn <gen>)
          • Unit - Create 1 Sledge for Neutral Passive at item_loc facing 0.00 degrees
          • Set hammer_created = (Last created unit)
          • Custom script: call RemoveLocation ( udg_item_loc )
        • Else - Actions
Creates the unit, sets the hammer_created = (Last created unit) which I want to use to spin the unit.

  • Spin Items
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
      • hammer_created Not equal to No unit
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • turn_ctr Equal to 0.00
        • Then - Actions
          • Set spin_wep = True
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • turn_ctr Equal to 45.00
            • Then - Actions
              • Set spin_wep = False
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • spin_wep Equal to True
        • Then - Actions
          • Set turn_ctr = (turn_ctr + 1.00)
        • Else - Actions
          • Set turn_ctr = (turn_ctr - 1.00)
      • Unit - Make hammer_created face turn_ctr over 0.10 seconds
It checks if hammer_created is a unit rather than No unit and spins it. This is just a cosmetic effect but it doesn't work. When I put a normal unit pre-placed on the map, it spins it correctly.

Thank you for reading!
 
Level 13
Joined
Oct 10, 2009
Messages
439
Hrmm, not sure how advanced you are in triggering but here is a "Spin Trigger" I made for a light saber throw ability quite some time ago.

Think of hashtables as records or enums or structs.

Note: I've deleted all un-relevant triggers
  • ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable


Change this trigger (Below) To whatever your initialisation is:
  • V Emp hit
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) YOUR ABILITY OR WHATEVER HERE
    • Actions
      • Set Point[0] = (Position of (Triggering unit))
      • Unit - Create 1 Saber (Effect 1) for (Owner of (Triggering unit)) at Point[0] facing Default building facing (270.0) degrees
      • Unit - Set the custom value of (Last created unit) to 0
      • Unit Group - Add (Last created unit) to UG_SaberThrow
      • Hashtable - Save (Facing of (Triggering unit)) as (Key Angle) of (Key (Last created unit)) in (Last created hashtable)
      • Trigger - Turn on V Saber throw loop <gen>
      • Custom script: call RemoveLocation(udg_Point[0])

  • V Saber throw loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in UG_SaberThrow and do (Actions)
        • Loop - Actions
          • Set Point[0] = (Position of (Picked unit))
          • Set Point[2] = (Position of DarthVader)
          • Set TAngle = (Load (Key Angle) of (Key (Picked unit)) from (Last created hashtable))
          • Unit - Set the custom value of (Picked unit) to ((Custom value of (Picked unit)) + 1)
          • Unit - Make (Picked unit) face ((Facing of (Picked unit)) + 15.00) over 0.00 seconds
          • Set TempReal2 = (25.00 - ((Real(((Custom value of (Picked unit)) x (Custom value of (Picked unit))))) / 400.00))
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Custom value of (Picked unit)) Less than or equal to (<=) 100
              • Then - Actions
                • Set Point[1] = (Point[0] offset by TempReal2 towards TAngle degrees)
                • Custom script: call SetUnitY(GetEnumUnit(), GetLocationY(udg_Point[1]))
                • Custom script: call SetUnitX(GetEnumUnit(), GetLocationX(udg_Point[1]))
              • Else - Actions
                • Set Point[1] = (Point[0] offset by TempReal2 towards TAngle degrees)
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • TempReal2 Less than (<) -29.00
                    • Then - Actions
                      • Set Point[1] = (Point[0] offset by 29.00 towards (Angle from Point[0] to Point[2]) degrees)
                    • Else - Actions
                      • Set Point[1] = (Point[0] offset by TempReal2 towards (Angle from Point[2] to Point[0]) degrees)
                • Custom script: call SetUnitY(GetEnumUnit(), GetLocationY(udg_Point[1]))
                • Custom script: call SetUnitX(GetEnumUnit(), GetLocationX(udg_Point[1]))
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Distance between Point[2] and Point[1]) Less than or equal to (<=) 30.00
                    • Then - Actions
                      • SABER HAS RETURNED TO CASTER ADD WHATEVER HERE
                    • Else - Actions
                      • SABER HAS NOT RETURNED TO CASTER, DEALING DAMAGE IN AN AREA AROUND IT
          • Set Group = (Units within 150.00 of Point[1] matching ((((Matching unit) belongs to an enemy of (Owner of (Picked unit))) Equal to (==) True) and ((((Matching unit) is dead) Equal to (==) False) and ((Level of Invulnerable (Neutral) for (Matching unit)) Equal to (==) 0))
          • Unit Group - Pick every unit in Group and do (Actions)
            • Loop - Actions
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is in UG_SabreCheck) Equal to (==) False
                • Then - Actions
                  • Unit Group - Add (Picked unit) to UG_SabreCheck
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • ((Picked unit) is A Hero) Equal to (==) True
                      • Then - Actions
                        • Unit - Cause Unit to damage...
                      • Else - Actions
                        • Unit - Cause Unit to damage...
                • Else - Actions
          • Custom script: call DestroyGroup(udg_Group)
          • Unit Group - Pick every unit in UG_SabreCheck and do (Actions)
            • Loop - Actions
              • Set Point[3] = (Position of (Picked unit))
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Distance between Point[1] and Point[3]) Greater than (>) 170.00
                  • Then - Actions
                    • Unit Group - Remove (Picked unit) from UG_SabreCheck
                  • Else - Actions
              • Custom script: call RemoveLocation(udg_Point[3])
          • Custom script: call RemoveLocation(udg_Point[0])
          • Custom script: call RemoveLocation(udg_Point[1])
          • Custom script: call RemoveLocation(udg_Point[2])




Annnnnnnnnnnnnd I just read your post, guess this whole splurge of triggers here are quite meaningless. Mind if you tell us what model you are using for the effect? Also, have you tried debugging "IE, printing out the directional facing of the hammer each loop to see if it does spin but the model is bugging"
 

sentrywiz

S

sentrywiz

Annnnnnnnnnnnnd I just read your post, guess this whole splurge of triggers here are quite meaningless.

Unfortunately I have to agree with you. Posting the triggers served no purpose
But it shows you made something similar and it worked.

The hammer is a custom made model of "Maul of Strength" but I have used Storm Bolt hammer or Gryphon Attack hammer. Checked all to see if the model is bugged.

But no, model works great. Its something with the trigger, but I can't find anything else besides that the variable keeping the pointer to the unit last created doesn't work for facing or something I am not seeing there.

And yes, I've checked the loop, the model and even turned a static unit that I placed from the editor. Everything checks out and the unit is turning correctly. But its not working for the unit created in triggers
 

sentrywiz

S

sentrywiz

That wasn't it, I just tried with a normal non-changed default unit. It works. So now it only means that I have put something in the unit stats to make it so it can't turn. But what...

EDIT:

Its the movespeed. I set it to 0 on the dummy unit. I can't see how facing has anything to do with movespeed. But since I found the problem, its all good.
 
Status
Not open for further replies.
Top