• 🏆 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] Could this be coded more efficiently/Does it leak?

Status
Not open for further replies.
Level 6
Joined
Jan 8, 2009
Messages
140
This is a recipe trigger for stackable items. I'm not sure if it leaks or anything, it's for a single player map if that means anything.

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Ability being cast) Equal to Smelt Bronze
      • ((Triggering unit) has an item of type Copper Bar) Equal to True
      • ((Triggering unit) has an item of type Tin Bar) Equal to True
    • Then - Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • For each (Integer B) from 1 to 6, 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 Copper Bar
                  • (Item-type of (Item carried by (Triggering unit) in slot (Integer B))) Equal to Tin Bar
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) Equal to 1
                      • (Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) Equal to 1
                    • Then - Actions
                      • Item - Remove (Item carried by (Triggering unit) in slot (Integer A))
                      • Item - Remove (Item carried by (Triggering unit) in slot (Integer B))
                      • Item - Create Bronze Bar at (Position of (Triggering unit))
                      • Item - Set charges remaining in (Last created item) to 2
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) Equal to 1
                        • Then - Actions
                          • Item - Remove (Item carried by (Triggering unit) in slot (Integer B))
                          • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) - 1)
                          • Item - Create Bronze Bar at (Position of (Triggering unit))
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) Equal to 1
                            • Then - Actions
                              • Item - Remove (Item carried by (Triggering unit) in slot (Integer A))
                              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer B)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) - 1)
                              • Item - Create Bronze Bar at (Position of (Triggering unit))
                              • Item - Set charges remaining in (Last created item) to 2
                            • Else - Actions
                              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer A)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer A))) - 1)
                              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot (Integer B)) to ((Charges remaining in (Item carried by (Triggering unit) in slot (Integer B))) - 1)
                              • Item - Create Bronze Bar at (Position of (Triggering unit))
                              • Item - Set charges remaining in (Last created item) to 2
                • Else - Actions
    • Else - Actions
      • Floating Text - Create floating text that reads Incorrect materials. above (Triggering unit) with Z offset 0.00, using font size 10.00, color (100.00%, 10.00%, 10.00%), and 0.00% transparency
      • Set tmpFloat = (Last created floating text)
      • Floating Text - Set the velocity of tmpFloat to 120.00 towards 270.00 degrees
      • Floating Text - Change tmpFloat: Disable permanence
      • Floating Text - Change the lifespan of tmpFloat to 2.00 seconds
      • Floating Text - Change the fading age of tmpFloat to 0.00 seconds
 
Level 2
Joined
Aug 11, 2010
Messages
27
Level 6
Joined
Jan 8, 2009
Messages
140
never use integer A / B. they are less efficient than using ur own variable. also anything u use twice or more store into a variable and use the variable. ex: triggering unit. and item carried by triggering unit.

This doesn't have an impact on speed does it? I only ask because it's done now and if I don't have to replace that it doesn't really matter then.


Yes this trigger leak, at least when you create your item, you use a location without removing it from memory, look here for more details (Location part) : http://www.hiveworkshop.com/forums/general-mapping-tutorials-278/complete-list-things-leak-126761/

Also, to make this more efficient, look the position of the first Copper bar, than The position of Tin Bar, and after do your stuff with it (here remplace them with a bronze ingot).

Alright would I remove those leaks by setting tmpPoint then removing it after spawning?

I don't understand how you mean look at the position of the first then the second then spawn the new item.
 
Level 2
Joined
Aug 11, 2010
Messages
27
Ok, I made 2 version for that, I hope it will be enough for you. I don't use charge, but it may be easy enough to add it yourself.
 

Attachments

  • forgingtest.w3x
    18.5 KB · Views: 42
Last edited:
Level 6
Joined
Jan 8, 2009
Messages
140
Is this right?

EDIT: just noticed you posted, looking at your map now.

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Ability being cast) Equal to Smelt Bronze
      • ((Triggering unit) has an item of type Copper Bar) Equal to True
      • ((Triggering unit) has an item of type Tin Bar) Equal to True
    • Then - Actions
      • For each (Integer loopA) from 1 to 6, do (Actions)
        • Loop - Actions
          • For each (Integer loopB) from 1 to 6, 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 loopA)) Equal to Copper Bar
                  • (Item-type of (Item carried by (Triggering unit) in slot loopB)) Equal to Tin Bar
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Charges remaining in (Item carried by (Triggering unit) in slot loopA)) Equal to 1
                      • (Charges remaining in (Item carried by (Triggering unit) in slot loopB)) Equal to 1
                    • Then - Actions
                      • Item - Remove (Item carried by (Triggering unit) in slot loopA)
                      • Item - Remove (Item carried by (Triggering unit) in slot loopB)
                      • Set tmpPoint = (Position of (Triggering unit))
                      • Item - Create Bronze Bar at tmpPoint
                      • Custom script: call RemoveLocation (udg_tmpPoint)
                      • Item - Set charges remaining in (Last created item) to 2
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Charges remaining in (Item carried by (Triggering unit) in slot loopB)) Equal to 1
                        • Then - Actions
                          • Item - Remove (Item carried by (Triggering unit) in slot loopB)
                          • Item - Set charges remaining in (Item carried by (Triggering unit) in slot loopA) to ((Charges remaining in (Item carried by (Triggering unit) in slot loopA)) - 1)
                          • Set tmpPoint = (Position of (Triggering unit))
                          • Item - Create Bronze Bar at tmpPoint
                          • Custom script: call RemoveLocation (udg_tmpPoint)
                          • Item - Set charges remaining in (Last created item) to 2
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Charges remaining in (Item carried by (Triggering unit) in slot loopA)) Equal to 1
                            • Then - Actions
                              • Item - Remove (Item carried by (Triggering unit) in slot loopA)
                              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot loopB) to ((Charges remaining in (Item carried by (Triggering unit) in slot loopB)) - 1)
                              • Set tmpPoint = (Position of (Triggering unit))
                              • Item - Create Bronze Bar at tmpPoint
                              • Custom script: call RemoveLocation (udg_tmpPoint)
                              • Item - Set charges remaining in (Last created item) to 2
                            • Else - Actions
                              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot loopA) to ((Charges remaining in (Item carried by (Triggering unit) in slot loopA)) - 1)
                              • Item - Set charges remaining in (Item carried by (Triggering unit) in slot loopB) to ((Charges remaining in (Item carried by (Triggering unit) in slot loopB)) - 1)
                              • Set tmpPoint = (Position of (Triggering unit))
                              • Item - Create Bronze Bar at tmpPoint
                              • Custom script: call RemoveLocation (udg_tmpPoint)
                              • Item - Set charges remaining in (Last created item) to 2
                • Else - Actions
    • Else - Actions
      • Floating Text - Create floating text that reads Incorrect materials. above (Triggering unit) with Z offset 0.00, using font size 10.00, color (100.00%, 10.00%, 10.00%), and 0.00% transparency
      • Set tmpFloat = (Last created floating text)
      • Floating Text - Set the velocity of tmpFloat to 120.00 towards 270.00 degrees
      • Floating Text - Change tmpFloat: Disable permanence
      • Floating Text - Change the lifespan of tmpFloat to 2.00 seconds
      • Floating Text - Change the fading age of tmpFloat to 0.00 seconds
 
Level 2
Joined
Aug 11, 2010
Messages
27
It's not right, and it could be more efficient. I just saw that you create a floating text even if the ability casted isn't the right one ? I don't think it's that you want.

Also if you need a version who use some charge of the item, tell me
 
Level 6
Joined
Jan 8, 2009
Messages
140
It's not right, and it could be more efficient. I just saw that you create a floating text even if the ability casted isn't the right one ? I don't think it's that you want.

Also if you need a version who use some charge of the item, tell me

EDIT

  • Forge
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Forge
    • Actions
      • Set item = (Item carried by (Triggering unit) of type Moon Key)
      • Set item_2 = (Item carried by (Triggering unit) of type Cheese)
      • Set Point = (Position of (Triggering unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • item Not equal to No item
          • item_2 Not equal to No item
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Charges remaining in item) Equal to 1
              • (Charges remaining in item_2) Equal to 1
            • Then - Actions
              • Item - Remove item
              • Item - Remove item_2
              • Item - Create Sun Key at Point
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Charges remaining in item) Equal to 1
                • Then - Actions
                  • Item - Remove item
                  • Item - Set charges remaining in item_2 to ((Charges remaining in item_2) - 1)
                  • Item - Create Sun Key at Point
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Charges remaining in item_2) Equal to 1
                    • Then - Actions
                      • Item - Remove item_2
                      • Item - Set charges remaining in item to ((Charges remaining in item) - 1)
                      • Item - Create Sun Key at Point
                    • Else - Actions
                      • Item - Set charges remaining in item to ((Charges remaining in item) - 1)
                      • Item - Set charges remaining in item_2 to ((Charges remaining in item_2) - 1)
                      • Item - Create Sun Key at Point
        • Else - Actions
          • Floating Text - Create floating text that reads Nothing to forge! at Point with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
          • Floating Text - Change the fading age of (Last created floating text) to 4.00 seconds
      • Custom script: call RemoveLocation(udg_Point)
Is this the correct way to go about it?
 
Level 2
Joined
Aug 11, 2010
Messages
27
Correct way, yes, but you can just remove one charge and check if they have 0 charge remove them (more compact, less thing to check)
 
Level 2
Joined
Aug 11, 2010
Messages
27
Could you please show me how to do that?

Not so hard, but I did some different version to let you see the different things we can do, some may contain some issue and some may be less efficient, so I let you choose, and try them all ("Init 2" trigger is just for testing)
 

Attachments

  • forgingtest.w3x
    22.7 KB · Views: 71
Status
Not open for further replies.
Top